You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

868 lines
40 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Admin.Core.Common.Helper;
using Admin.Core.IService;
using Admin.Core.IService.IService_New;
using Admin.Core.Model.Model_New;
using Admin.Core.Service;
using Aucma.Core.BoxFoam.Models;
using Aucma.Core.HwPLc;
using Aucma.Core.Tasks.Models;
using Microsoft.Extensions.DependencyInjection;
using NetTaste;
using NPOI.HPSF;
using NPOI.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.RightsManagement;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Documents;
using Array = System.Array;
namespace Aucma.Core.BoxFoam.Business
{
/// <summary>
/// 采集发泡线数据
/// </summary>
public class CollectionFoamLine
{
public delegate Task RefreshBoxFoamDataDelegate(List<FixtureStatus> list);
public static event RefreshBoxFoamDataDelegate RefreshBoxFoamDataDelegateEvent;
private static System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
public static List<SpaceDetailModel> spaceDetailModel = new List<SpaceDetailModel>();
public static List<FixtureStatus> listFixtureStatus = new List<FixtureStatus>();
private readonly IRecordBoxFoamFixtureComplateServices _fixtureComplateServices;
private readonly IOldBoxFoamTypeServices _oldBoxFoamTypeServices;
private readonly IBaseSpaceInfoServices _baseSpaceInfoServices;
Semaphore semaphore = new Semaphore(1, 1);
public CollectionFoamLine()
{
_fixtureComplateServices = App.ServiceProvider.GetService<IRecordBoxFoamFixtureComplateServices>();
_oldBoxFoamTypeServices = App.ServiceProvider.GetService<IOldBoxFoamTypeServices>();
_baseSpaceInfoServices = App.ServiceProvider.GetService<IBaseSpaceInfoServices>();
startCollect();
}
public void startCollect()
{
Task.Run(() =>
{
Thread.Sleep(3000);
while (true)
{
try
{
// 1-6夹具
var plc1 = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("foamLine1Plc"));
//7-12夹具
var plc2 = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("foamLine2Plc"));
// 泡前库箱型和数量
var plc3 = PlcHelper.siemensList.FirstOrDefault(d => d.EquipName.Equals("泡前库Plc"));
spaceDetailModel = ReadStoreTypeAndCount(plc3);
if (spaceDetailModel.Count > 0)
{
// 更新货道库存
updateStoreAmount(spaceDetailModel);
}
//夹具箱型
List<FixtureStatus> boxTypeList = ReadBoxType(plc1, plc2);
List<FixtureStatus> holderStatusList = ReadFixtureStatus(plc1, plc2);
List<FixtureStatus> holderOutPutList = ReadFixtureProduction(plc1, plc2);
List<FixtureStatus> planCuringTimeList = ReadPlanCuringTime(plc1, plc2);
var mergedCollection = from boxType in boxTypeList
join holderStatus in holderStatusList on new { boxType.ObjId } equals new { holderStatus.ObjId }
join holderOutPut in holderOutPutList on new { boxType.ObjId } equals new { holderOutPut.ObjId }
join planCuringTime in planCuringTimeList on new { boxType.ObjId } equals new { planCuringTime.ObjId }
select new FixtureStatus
{
ObjId = boxType.ObjId,
FixtureBoxType = boxType.FixtureBoxType,
Status = holderStatus.Status,
Yield = holderOutPut.Yield,
PlanCuringTime = planCuringTime.PlanCuringTime
};
listFixtureStatus = mergedCollection.ToList();
if (listFixtureStatus != null)
{
RefreshBoxFoamDataDelegateEvent?.Invoke(listFixtureStatus);
List<RecordBoxFoamFixtureComplate> fixtureComplates = new List<RecordBoxFoamFixtureComplate>();
listFixtureStatus.ForEach(x =>
{
fixtureComplates.Add(new RecordBoxFoamFixtureComplate()
{
ProductionLine = "CX_02",
StationCode = "1005",
FixtureCode = x.ObjId,
FixtureBoxType = x.FixtureBoxType,
FixtureStatus = x.Status,
FixtureOutPut = x.Yield,
PlanCuringTime = x.PlanCuringTime,
RealCuringTime = x.RealCuringTime,
RecordTime = DateTime.Now,
});
});
var info = _fixtureComplateServices.SaveFixtureComplate(fixtureComplates, "CX_02", "1005");
}
}
catch (Exception ex)
{
Console.WriteLine($"箱体发泡线数据采集异常:{ex.Message}");
}
Thread.Sleep(2000);
}
});
}
/// <summary>
/// 读取泡前库箱型和数量
/// </summary>
static List<SpaceDetailModel> ReadStoreTypeAndCount(HwPLc.PlcModel obj)
{
List<SpaceDetailModel> spaceDetailModels = new List<SpaceDetailModel>();
if (obj != null && obj.plc.IsConnected)
{
byte[] info = obj.plc.Read("DB200.0", 100);
string str1 = asciiEncoding.GetString(info.Skip(6).Take(10).ToArray()).Replace("\0","").Trim('\n');
string str2 = asciiEncoding.GetString(info.Skip(18).Take(10).ToArray()).Replace("\0", "").Trim('\n');
string str3 = asciiEncoding.GetString(info.Skip(30).Take(10).ToArray()).Replace("\0", "").Trim('\n');
string str4 = asciiEncoding.GetString(info.Skip(42).Take(10).ToArray()).Replace("\0", "").Trim('\n');
string str5 = asciiEncoding.GetString(info.Skip(54).Take(10).ToArray()).Replace("\0", "").Trim('\n');
string str6 = asciiEncoding.GetString(info.Skip(66).Take(10).ToArray()).Replace("\0", "").Trim('\n');
Console.WriteLine($"读取泡前库箱型,1#:{str1};2#{str2};3#:{str3};4#:{str4};5#:{str5};6#:{str6}");
short temp1 = short.Parse(StringChange.bytesToHexStr(info.Skip(88).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
short temp2 = short.Parse(StringChange.bytesToHexStr(info.Skip(90).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
short temp3 = short.Parse(StringChange.bytesToHexStr(info.Skip(92).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
short temp4 = short.Parse(StringChange.bytesToHexStr(info.Skip(94).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
short temp5 = short.Parse(StringChange.bytesToHexStr(info.Skip(96).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
short temp6 = short.Parse(StringChange.bytesToHexStr(info.Skip(98).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
Console.WriteLine($"读取泡前库数量,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}");
spaceDetailModels.Add(new SpaceDetailModel()
{
ObjId = 1,
StoreType = str1.ToString(),
StoreAmount = temp1
});
spaceDetailModels.Add(new SpaceDetailModel()
{
ObjId = 2,
StoreType = str2.ToString(),
StoreAmount = temp2
});
spaceDetailModels.Add(new SpaceDetailModel()
{
ObjId = 3,
StoreType = str3.ToString(),
StoreAmount = temp3
});
spaceDetailModels.Add(new SpaceDetailModel()
{
ObjId = 4,
StoreType = str4.ToString(),
StoreAmount = temp4
});
spaceDetailModels.Add(new SpaceDetailModel()
{
ObjId = 5,
StoreType = str5.ToString(),
StoreAmount = temp5
});
spaceDetailModels.Add(new SpaceDetailModel()
{
ObjId = 6,
StoreType = str6.ToString(),
StoreAmount = temp6
});
}
return spaceDetailModels;
}
/// <summary>
/// 读取夹具箱型
/// </summary>
static List<FixtureStatus> ReadBoxType(HwPLc.PlcModel obj, HwPLc.PlcModel obj2)
{
List<FixtureStatus> fixtureStatuses = new List<FixtureStatus>();
#region 1-6夹具
if (obj != null && obj.plc.IsConnected)
{
byte[] result = obj.plc.Read("DB8.0", 12);
if (result != null)
{
short str1 = short.Parse(StringChange.bytesToHexStr(result.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 1,
FixtureBoxType = str1.ToString()
});
short str2 = short.Parse(StringChange.bytesToHexStr(result.Skip(2).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 2,
FixtureBoxType = str2.ToString()
});
short str3 = short.Parse(StringChange.bytesToHexStr(result.Skip(4).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 3,
FixtureBoxType = str3.ToString()
});
short str4 = short.Parse(StringChange.bytesToHexStr(result.Skip(6).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 4,
FixtureBoxType = str4.ToString()
});
short str5 = short.Parse(StringChange.bytesToHexStr(result.Skip(8).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 5,
FixtureBoxType = str5.ToString()
});
short str6= short.Parse(StringChange.bytesToHexStr(result.Skip(10).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 6,
FixtureBoxType = str6.ToString()
});
Console.WriteLine($"读取夹具箱型,1#:{str1};2#{str2};3#:{str3};4#:{str4};5#:{str5};6#:{str6}");
}
}
#endregion
#region 7-12夹具
if (obj2 != null && obj2.plc.IsConnected)
{
byte[] result = obj2.plc.Read("DB8.0",12 );
if (result != null)
{
short str1 = short.Parse(StringChange.bytesToHexStr(result.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 7,
FixtureBoxType = str1.ToString()
});
short str2 = short.Parse(StringChange.bytesToHexStr(result.Skip(2).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 8,
FixtureBoxType = str2.ToString()
});
short str3 = short.Parse(StringChange.bytesToHexStr(result.Skip(4).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
fixtureStatuses.Add(new FixtureStatus()
{
ObjId =9,
FixtureBoxType = str3.ToString()
});
short str4 = short.Parse(StringChange.bytesToHexStr(result.Skip(6).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 10,
FixtureBoxType = str4.ToString()
});
short str5 = short.Parse(StringChange.bytesToHexStr(result.Skip(8).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 11,
FixtureBoxType = str5.ToString()
});
short str6 = short.Parse(StringChange.bytesToHexStr(result.Skip(10).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 12,
FixtureBoxType = str6.ToString()
});
Console.WriteLine($"读取夹具箱型,1#:{str1};2#{str2};3#:{str3};4#:{str4};5#:{str5};6#:{str6}");
}
}
#endregion
return fixtureStatuses;
}
/// <summary>
/// 读取夹具状态1正常生产 3暂停生产
/// </summary>
static List<FixtureStatus> ReadFixtureStatus(HwPLc.PlcModel obj, HwPLc.PlcModel obj2)
{
List<FixtureStatus> fixtureStatuses = new List<FixtureStatus>();
#region 1-6夹具
if (obj != null && obj.plc.IsConnected)
{
byte[] info = obj.plc.Read("DB8.12", 13);
if (info != null)
{
int temp1 = judgeStatus(ByteArrayToBinary(info.Skip(0).Take(1).ToArray()));
int temp2 = judgeStatus(ByteArrayToBinary(info.Skip(2).Take(1).ToArray()));
int temp3 = judgeStatus(ByteArrayToBinary(info.Skip(4).Take(1).ToArray()));
int temp4 = judgeStatus(ByteArrayToBinary(info.Skip(6).Take(1).ToArray()));
int temp5 = judgeStatus(ByteArrayToBinary(info.Skip(8).Take(1).ToArray()));
int temp6 = judgeStatus(ByteArrayToBinary(info.Skip(10).Take(1).ToArray()));
Console.WriteLine($"读取夹具状态,1#:{temp1};2#:{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}");
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 1,
Status = temp1,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 2,
Status = temp2,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 3,
Status = temp3,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 4,
Status = temp4,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 5,
Status = temp5,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 6,
Status = temp6,
});
}
}
#endregion
#region 7-12夹具
if (obj2 != null && obj2.plc.IsConnected)
{
byte[] info2 = obj2.plc.Read("DB8.12", 13);
if (info2 != null)
{
int temp7 = judgeStatus(ByteArrayToBinary(info2.Skip(0).Take(1).ToArray()));
int temp8 = judgeStatus(ByteArrayToBinary(info2.Skip(2).Take(1).ToArray()));
int temp9 = judgeStatus(ByteArrayToBinary(info2.Skip(4).Take(1).ToArray()));
int temp10 = judgeStatus(ByteArrayToBinary(info2.Skip(6).Take(1).ToArray()));
int temp11 = judgeStatus(ByteArrayToBinary(info2.Skip(8).Take(1).ToArray()));
int temp12 = judgeStatus(ByteArrayToBinary(info2.Skip(10).Take(1).ToArray()));
Console.WriteLine($"读取夹具状态,7#:{temp7};8#:{temp8};9#:{temp9};10#:{temp10};11#:{temp11};12#:{temp12}");
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 7,
Status = temp7,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 8,
Status = temp8,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 9,
Status = temp9,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 10,
Status = temp10,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 11,
Status = temp11,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 12,
Status = temp12,
});
}
}
#endregion
return fixtureStatuses;
}
/// <summary>
/// 读取夹具产量
/// </summary>
static List<FixtureStatus> ReadFixtureProduction(HwPLc.PlcModel obj, HwPLc.PlcModel obj2)
{
List<FixtureStatus> fixtureStatuses = new List<FixtureStatus>();
#region 1-6夹具产量
if (obj != null && obj.plc.IsConnected)
{
byte[] info = obj.plc.Read("DB8.24", 48);
if (info != null)
{
int temp1 = int.Parse(StringChange.bytesToHexStr(info.Skip(0).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
int temp2 = int.Parse(StringChange.bytesToHexStr(info.Skip(4).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
int temp3 = int.Parse(StringChange.bytesToHexStr(info.Skip(8).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
int temp4 = int.Parse(StringChange.bytesToHexStr(info.Skip(12).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
int temp5 = int.Parse(StringChange.bytesToHexStr(info.Skip(16).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
int temp6 = int.Parse(StringChange.bytesToHexStr(info.Skip(20).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
Console.WriteLine($"读取夹具产量,1#:{temp1};2#:{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}");
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 1,
Yield = temp1,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 2,
Yield = temp2,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 3,
Yield = temp3,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 4,
Yield = temp4,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 5,
Yield = temp5,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 6,
Yield = temp6,
});
}
}
#endregion
#region 7-12夹具产量
if (obj2 != null && obj2.plc.IsConnected)
{
byte[] info = obj2.plc.Read("DB8.24", 48);
if (info != null)
{
int temp1 = int.Parse(StringChange.bytesToHexStr(info.Skip(0).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
int temp2 = int.Parse(StringChange.bytesToHexStr(info.Skip(4).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
int temp3 = int.Parse(StringChange.bytesToHexStr(info.Skip(8).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
int temp4 = int.Parse(StringChange.bytesToHexStr(info.Skip(12).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
int temp5 = int.Parse(StringChange.bytesToHexStr(info.Skip(16).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
int temp6 = int.Parse(StringChange.bytesToHexStr(info.Skip(20).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
Console.WriteLine($"读取夹具产量,1#:{temp1};2#:{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}");
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 7,
Yield = temp1,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 8,
Yield = temp2,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 9,
Yield = temp3,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 10,
Yield = temp4,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 11,
Yield = temp5,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 12,
Yield = temp6,
});
}
}
#endregion
return fixtureStatuses;
}
/// <summary>
/// 固化时间设定值
/// </summary>
static List<FixtureStatus> ReadPlanCuringTime(HwPLc.PlcModel obj, HwPLc.PlcModel obj2)
{
List<FixtureStatus> fixtureStatuses = new List<FixtureStatus>();
#region 1-6夹具
if (obj != null && obj.plc.IsConnected)
{
byte[] info = obj.plc.Read("DB8.48", 12);
if (info != null)
{
short temp1 = short.Parse(StringChange.bytesToHexStr(info.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
short temp2 = short.Parse(StringChange.bytesToHexStr(info.Skip(2).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
short temp3 = short.Parse(StringChange.bytesToHexStr(info.Skip(4).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
short temp4 = short.Parse(StringChange.bytesToHexStr(info.Skip(6).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
short temp5 = short.Parse(StringChange.bytesToHexStr(info.Skip(8).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
short temp6 = short.Parse(StringChange.bytesToHexStr(info.Skip(10).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
Console.WriteLine($"读取固化时间,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}");
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 1,
PlanCuringTime = temp1,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 2,
PlanCuringTime = temp2,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 3,
PlanCuringTime = temp3,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 4,
PlanCuringTime = temp4,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 5,
PlanCuringTime = temp5,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 6,
PlanCuringTime = temp6,
});
}
}
#endregion
#region 7-12夹具
if (obj2 != null && obj2.plc.IsConnected)
{
byte[] info = obj2.plc.Read("DB8.48", 12);
if (info != null)
{
short temp1 = short.Parse(StringChange.bytesToHexStr(info.Skip(0).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
short temp2 = short.Parse(StringChange.bytesToHexStr(info.Skip(2).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
short temp3 = short.Parse(StringChange.bytesToHexStr(info.Skip(4).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
short temp4 = short.Parse(StringChange.bytesToHexStr(info.Skip(6).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
short temp5 = short.Parse(StringChange.bytesToHexStr(info.Skip(8).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
short temp6 = short.Parse(StringChange.bytesToHexStr(info.Skip(10).Take(2).ToArray(), 2), System.Globalization.NumberStyles.HexNumber);
Console.WriteLine($"读取固化时间,1#:{temp1};2#{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}");
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 7,
PlanCuringTime = temp1,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 8,
PlanCuringTime = temp2,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 9,
PlanCuringTime = temp3,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 10,
PlanCuringTime = temp4,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 11,
PlanCuringTime = temp5,
});
fixtureStatuses.Add(new FixtureStatus()
{
ObjId = 12,
PlanCuringTime = temp6,
});
}
}
#endregion
return fixtureStatuses;
}
/// <summary>
/// 发泡线状态
/// </summary>
static void ReadLineStatus(HwPLc.PlcModel obj)
{
byte[] result = obj.plc.Read("DB8.630", 1);
byte[] info = result;
int temp1 = judgeStatus(ByteArrayToBinary(info.Skip(0).Take(1).ToArray()));
Console.WriteLine($"发泡线状态:{temp1}");
}
#region 字符工具转换方法
/// <summary>
/// byte数组转换为float
/// </summary>
static float byteToFloat(byte[] list)
{
float result = 0.00f;
Array.Reverse(list);
result = BitConverter.ToSingle(list, 0);
return result;
}
/// <summary>
/// byte[]转二进制
/// </summary>
/// <param name="bytes"></param>
static string ByteArrayToBinary(byte[] bytes)
{
StringBuilder binaryString = new StringBuilder();
foreach (byte b in bytes)
{
binaryString.Append(Convert.ToString(b, 2).PadLeft(8, '0'));
}
// Console.WriteLine(binaryString);
string reversedStr = new string(binaryString.ToString().Reverse().ToArray());
// Console.WriteLine(reversedStr);
return reversedStr;
}
/// <summary>
/// 根据二进制字符串确定夹具状态 1正常生产 3暂停生产
/// </summary>
static int judgeStatus(string str1)
{
int item1 = 0;
if (str1.Substring(0, 1) == "1")
{
item1 = 1; //
}
else if (str1.Substring(1, 1) == "1")
{
item1 = 3; //
}
return item1;
}
/// <summary>
/// 更新新线货道库存
/// </summary>
/// <param name="spaceDetailModel"></param>
public async void updateStoreAmount(List<SpaceDetailModel> spaceDetailModel)
{
if (spaceDetailModel == null) return;
var spaceList = _baseSpaceInfoServices.QueryAsync(x=>x.StoreCode=="PQK-001").Result;
foreach (var item in spaceDetailModel)
{
var space = spaceList.FirstOrDefault(x => x.SpaceCode.Substring(7,1).Equals(item.ObjId.ToString()));
if (space != null)
{
space.SpaceStock = item.StoreAmount;
}
}
_baseSpaceInfoServices.UpdateAsync(spaceList);
}
}
#endregion
#region 注释方法
///// <summary>
///// 固化时间显示值
///// </summary>
//static void ReadDisplayCuringTime(HwPLc.PlcModel obj, List<int> ActualTimeList)
//{
// if (obj == null) return;
// if (obj.plc.IsConnected)
// {
// byte[] result = obj.plc.Read("DB8.242", 48);
// byte[] info = result;
// int temp1 = int.Parse(StringChange.bytesToHexStr(info.Skip(0).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
// int temp2 = int.Parse(StringChange.bytesToHexStr(info.Skip(4).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
// int temp3 = int.Parse(StringChange.bytesToHexStr(info.Skip(8).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
// int temp4 = int.Parse(StringChange.bytesToHexStr(info.Skip(12).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
// int temp5 = int.Parse(StringChange.bytesToHexStr(info.Skip(16).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
// int temp6 = int.Parse(StringChange.bytesToHexStr(info.Skip(20).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
// int temp7 = int.Parse(StringChange.bytesToHexStr(info.Skip(24).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
// int temp8 = int.Parse(StringChange.bytesToHexStr(info.Skip(28).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
// int temp9 = int.Parse(StringChange.bytesToHexStr(info.Skip(32).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
// int temp10 = int.Parse(StringChange.bytesToHexStr(info.Skip(36).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
// int temp11 = int.Parse(StringChange.bytesToHexStr(info.Skip(40).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
// int temp12 = int.Parse(StringChange.bytesToHexStr(info.Skip(44).Take(4).ToArray(), 4), System.Globalization.NumberStyles.HexNumber);
// ActualTimeList.Add(temp1);
// ActualTimeList.Add(temp2);
// ActualTimeList.Add(temp3);
// ActualTimeList.Add(temp4);
// ActualTimeList.Add(temp5);
// ActualTimeList.Add(temp6);
// ActualTimeList.Add(temp7);
// ActualTimeList.Add(temp8);
// ActualTimeList.Add(temp9);
// ActualTimeList.Add(temp10);
// ActualTimeList.Add(temp11);
// ActualTimeList.Add(temp12);
// Console.WriteLine($"读取固化时间显示值,1#:{temp1};2#:{temp2};3#:{temp3};4#:{temp4};5#:{temp5};6#:{temp6}");
// Console.WriteLine($"读取固化时间显示值,7#:{temp7};8#:{temp8};9#:{temp9};10#:{temp10};11#:{temp11};12#:{temp12}");
// }
//}
///// <summary>
///// 模具内外温度
///// </summary>
//static void ReadMoldTemperature(HwPLc.PlcModel obj, List<float> MoldTemperatureList)
//{
// if (obj == null) return;
// if (obj.plc.IsConnected)
// {
// byte[] info = obj.plc.Read("DB8.294", 284);
// float temp1 = byteToFloat(info.Skip(0).Take(4).ToArray());
// float temp2 = byteToFloat(info.Skip(16).Take(4).ToArray());
// float temp3 = byteToFloat(info.Skip(24).Take(4).ToArray());
// float temp4 = byteToFloat(info.Skip(40).Take(4).ToArray());
// float temp5 = byteToFloat(info.Skip(48).Take(4).ToArray());
// float temp6 = byteToFloat(info.Skip(64).Take(4).ToArray());
// float temp7 = byteToFloat(info.Skip(72).Take(4).ToArray());
// float temp8 = byteToFloat(info.Skip(88).Take(4).ToArray());
// float temp9 = byteToFloat(info.Skip(96).Take(4).ToArray());
// float temp10 = byteToFloat(info.Skip(112).Take(4).ToArray());
// float temp11 = byteToFloat(info.Skip(120).Take(4).ToArray());
// float temp12 = byteToFloat(info.Skip(136).Take(4).ToArray());
// float temp13 = byteToFloat(info.Skip(144).Take(4).ToArray());
// float temp14 = byteToFloat(info.Skip(160).Take(4).ToArray());
// float temp15 = byteToFloat(info.Skip(168).Take(4).ToArray());
// float temp16 = byteToFloat(info.Skip(184).Take(4).ToArray());
// float temp17 = byteToFloat(info.Skip(192).Take(4).ToArray());
// float temp18 = byteToFloat(info.Skip(208).Take(4).ToArray());
// float temp19 = byteToFloat(info.Skip(216).Take(4).ToArray());
// float temp20 = byteToFloat(info.Skip(232).Take(4).ToArray());
// float temp21 = byteToFloat(info.Skip(240).Take(4).ToArray());
// float temp22 = byteToFloat(info.Skip(256).Take(4).ToArray());
// float temp23 = byteToFloat(info.Skip(264).Take(4).ToArray());
// float temp24 = byteToFloat(info.Skip(280).Take(4).ToArray());
// MoldTemperatureList.Add(temp1);
// MoldTemperatureList.Add(temp3);
// MoldTemperatureList.Add(temp5);
// MoldTemperatureList.Add(temp7);
// MoldTemperatureList.Add(temp9);
// MoldTemperatureList.Add(temp11);
// MoldTemperatureList.Add(temp13);
// MoldTemperatureList.Add(temp15);
// MoldTemperatureList.Add(temp17);
// MoldTemperatureList.Add(temp19);
// MoldTemperatureList.Add(temp21);
// MoldTemperatureList.Add(temp23);
// MoldTemperatureList.Add(temp2);
// MoldTemperatureList.Add(temp4);
// MoldTemperatureList.Add(temp6);
// MoldTemperatureList.Add(temp8);
// MoldTemperatureList.Add(temp10);
// MoldTemperatureList.Add(temp12);
// MoldTemperatureList.Add(temp14);
// MoldTemperatureList.Add(temp16);
// MoldTemperatureList.Add(temp18);
// MoldTemperatureList.Add(temp20);
// MoldTemperatureList.Add(temp22);
// MoldTemperatureList.Add(temp24);
// }
//}
///// <summary>
///// 生产节拍
///// </summary>
//static void ReadProductionCycle(HwPLc.PlcModel obj, List<float> ProductionCycleList)
//{
// if (obj == null) return;
// if (obj.plc.IsConnected)
// {
// byte[] info = obj.plc.Read("DB8.578", 52);
// float temp1 = byteToFloat(info.Skip(0).Take(4).ToArray());
// float temp2 = byteToFloat(info.Skip(4).Take(4).ToArray());
// float temp3 = byteToFloat(info.Skip(8).Take(4).ToArray());
// float temp4 = byteToFloat(info.Skip(12).Take(4).ToArray());
// float temp5 = byteToFloat(info.Skip(16).Take(4).ToArray());
// float temp6 = byteToFloat(info.Skip(20).Take(4).ToArray());
// float temp7 = byteToFloat(info.Skip(24).Take(4).ToArray());
// float temp8 = byteToFloat(info.Skip(28).Take(4).ToArray());
// float temp9 = byteToFloat(info.Skip(32).Take(4).ToArray());
// float temp10 = byteToFloat(info.Skip(36).Take(4).ToArray());
// float temp11 = byteToFloat(info.Skip(40).Take(4).ToArray());
// float temp12 = byteToFloat(info.Skip(44).Take(4).ToArray());
// // 平均节拍
// float temp13 = byteToFloat(info.Skip(48).Take(4).ToArray());
// ProductionCycleList.Add(temp1);
// ProductionCycleList.Add(temp2);
// ProductionCycleList.Add(temp3);
// ProductionCycleList.Add(temp4);
// ProductionCycleList.Add(temp5);
// ProductionCycleList.Add(temp6);
// ProductionCycleList.Add(temp7);
// ProductionCycleList.Add(temp8);
// ProductionCycleList.Add(temp9);
// ProductionCycleList.Add(temp10);
// ProductionCycleList.Add(temp11);
// ProductionCycleList.Add(temp12);
// }
//}
#endregion
}