|
|
|
|
@ -34,23 +34,25 @@ namespace Sln.Iot.Business
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var res11 = _plc.ReadBytes(_plc.DeltaInstance1, "D200", 8);
|
|
|
|
|
var res12 = _plc.ReadBytes(_plc.DeltaInstance1, "D610", 6);
|
|
|
|
|
var res13 = _plc.ReadBytes(_plc.DeltaInstance1, "D120", 4);
|
|
|
|
|
var res14 = _plc.ReadFloat(_plc.DeltaInstance1, "D58");
|
|
|
|
|
// 读取PLC数据
|
|
|
|
|
var res = _plc.ReadBytes(_plc.DeltaInstance1, "D188", 21);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UnitsProcess1Entity entity = new UnitsProcess1Entity()
|
|
|
|
|
{
|
|
|
|
|
GlueAmountSetValue1 = BitConverter.ToSingle(res12.Content, 4),
|
|
|
|
|
GluePushSpeedSetValue1 = BitConverter.ToSingle(res12.Content, 0),
|
|
|
|
|
BarrelA1TempActValue1 = BitConverter.ToInt16(res11.Content, 0),
|
|
|
|
|
BarrelA2TempActValue1 = BitConverter.ToInt16(res11.Content, 4),
|
|
|
|
|
BarrelB1TempActValue1 = BitConverter.ToInt16(res11.Content, 12),
|
|
|
|
|
BarrelB2TempActValue1 = BitConverter.ToInt16(res11.Content, 16),
|
|
|
|
|
PumpAPressureActValue1 = BitConverter.ToSingle(res13.Content, 0),
|
|
|
|
|
PumpBPressureActValue1 = BitConverter.ToSingle(res13.Content, 4),
|
|
|
|
|
VacuumDegreeActValue1 = res14.Content,
|
|
|
|
|
PressureHoldTimeSetValue1 = BitConverter.ToInt16(res12.Content, 12),
|
|
|
|
|
// Float(单精度浮点数)占4字节,先截取4字节再反转
|
|
|
|
|
PumpAPressureActValue1 = BitConverter.ToSingle(SingleReverseBytesForValue(res.Content, (188 - 188) * 2, 4), 0),
|
|
|
|
|
PumpBPressureActValue1 = BitConverter.ToSingle(SingleReverseBytesForValue(res.Content, (190 - 188) * 2, 4), 0),
|
|
|
|
|
GluePushSpeedSetValue1 = BitConverter.ToSingle(SingleReverseBytesForValue(res.Content, (192 - 188) * 2, 4), 0),
|
|
|
|
|
GlueAmountSetValue1 = BitConverter.ToSingle(SingleReverseBytesForValue(res.Content, (194 - 188) * 2, 4), 0),
|
|
|
|
|
VacuumDegreeActValue1 = BitConverter.ToSingle(SingleReverseBytesForValue(res.Content, (196 - 188) * 2, 4), 0),
|
|
|
|
|
|
|
|
|
|
// Int16(短整型)占2字节,先截取2字节再反转
|
|
|
|
|
PressureHoldTimeSetValue1 = BitConverter.ToInt16(Int16ReverseBytesForValue(res.Content, (198 - 188) * 2, 2), 0),
|
|
|
|
|
BarrelA1TempActValue1 = BitConverter.ToInt16(Int16ReverseBytesForValue(res.Content, (200 - 188) * 2, 2), 0),
|
|
|
|
|
BarrelA2TempActValue1 = BitConverter.ToInt16(Int16ReverseBytesForValue(res.Content, (202 - 188) * 2, 2), 0),
|
|
|
|
|
BarrelB1TempActValue1 = BitConverter.ToInt16(Int16ReverseBytesForValue(res.Content, (206 - 188) * 2, 2), 0),
|
|
|
|
|
BarrelB2TempActValue1 = BitConverter.ToInt16(Int16ReverseBytesForValue(res.Content, (208 - 188) * 2, 2), 0),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return entity;
|
|
|
|
|
@ -70,23 +72,23 @@ namespace Sln.Iot.Business
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var res21 = _plc.ReadBytes(_plc.DeltaInstance2, "D200", 8);
|
|
|
|
|
var res22 = _plc.ReadBytes(_plc.DeltaInstance2, "D610", 6);
|
|
|
|
|
var res23 = _plc.ReadBytes(_plc.DeltaInstance2, "D120", 4);
|
|
|
|
|
var res24 = _plc.ReadFloat(_plc.DeltaInstance2, "D58");
|
|
|
|
|
|
|
|
|
|
var res = _plc.ReadBytes(_plc.DeltaInstance2, "D188", 21);
|
|
|
|
|
var result = res.Content.Reverse().ToArray();
|
|
|
|
|
UnitsProcess1Entity entity = new UnitsProcess1Entity()
|
|
|
|
|
{
|
|
|
|
|
GlueAmountSetValue2 = BitConverter.ToSingle(res22.Content, 4),
|
|
|
|
|
GluePushSpeedSetValue2 = BitConverter.ToSingle(res22.Content, 0),
|
|
|
|
|
BarrelA1TempActValue2 = BitConverter.ToInt16(res21.Content, 0),
|
|
|
|
|
BarrelA2TempActValue2 = BitConverter.ToInt16(res21.Content, 4),
|
|
|
|
|
BarrelB1TempActValue2 = BitConverter.ToInt16(res21.Content, 12),
|
|
|
|
|
BarrelB2TempActValue2 = BitConverter.ToInt16(res21.Content, 16),
|
|
|
|
|
PumpAPressureActValue2 = BitConverter.ToSingle(res23.Content, 0),
|
|
|
|
|
PumpBPressureActValue2 = BitConverter.ToSingle(res23.Content, 4),
|
|
|
|
|
VacuumDegreeActValue2 = res24.Content,
|
|
|
|
|
PressureHoldTimeSetValue2 = BitConverter.ToInt16(res22.Content, 12),
|
|
|
|
|
// Float(单精度浮点数)占4字节,先截取4字节再反转
|
|
|
|
|
PumpAPressureActValue2 = BitConverter.ToSingle(SingleReverseBytesForValue(res.Content, (188 - 188) * 2, 4), 0),
|
|
|
|
|
PumpBPressureActValue2 = BitConverter.ToSingle(SingleReverseBytesForValue(res.Content, (190 - 188) * 2, 4), 0),
|
|
|
|
|
GluePushSpeedSetValue2 = BitConverter.ToSingle(SingleReverseBytesForValue(res.Content, (192 - 188) * 2, 4), 0),
|
|
|
|
|
GlueAmountSetValue2 = BitConverter.ToSingle(SingleReverseBytesForValue(res.Content, (194 - 188) * 2, 4), 0),
|
|
|
|
|
VacuumDegreeActValue2 = BitConverter.ToSingle(SingleReverseBytesForValue(res.Content, (196 - 188) * 2, 4), 0),
|
|
|
|
|
|
|
|
|
|
// Int16(短整型)占2字节,先截取2字节再反转
|
|
|
|
|
PressureHoldTimeSetValue2 = BitConverter.ToInt16(Int16ReverseBytesForValue(res.Content, (198 - 188) * 2, 2), 0),
|
|
|
|
|
BarrelA1TempActValue2 = BitConverter.ToInt16(Int16ReverseBytesForValue(res.Content, (200 - 188) * 2, 2), 0),
|
|
|
|
|
BarrelA2TempActValue2 = BitConverter.ToInt16(Int16ReverseBytesForValue(res.Content, (202 - 188) * 2, 2), 0),
|
|
|
|
|
BarrelB1TempActValue2 = BitConverter.ToInt16(Int16ReverseBytesForValue(res.Content, (206 - 188) * 2, 2), 0),
|
|
|
|
|
BarrelB2TempActValue2 = BitConverter.ToInt16(Int16ReverseBytesForValue(res.Content, (208 - 188) * 2, 2), 0),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return entity;
|
|
|
|
|
@ -98,6 +100,42 @@ namespace Sln.Iot.Business
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 定义字节序转换的辅助方法(核心)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="source"></param>
|
|
|
|
|
/// <param name="startIndex"></param>
|
|
|
|
|
/// <param name="length"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
byte[] Int16ReverseBytesForValue(byte[] source, int startIndex, int length)
|
|
|
|
|
{
|
|
|
|
|
// 截取对应位置的字节片段(避免修改原数组)
|
|
|
|
|
byte[] temp = new byte[length];
|
|
|
|
|
Array.Copy(source, startIndex, temp, 0, length);
|
|
|
|
|
// 反转字节序(大端转小端)
|
|
|
|
|
Array.Reverse(temp);
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 定义字节序转换的辅助方法(核心)
|
|
|
|
|
byte[] SingleReverseBytesForValue(byte[] source, int startIndex, int length)
|
|
|
|
|
{
|
|
|
|
|
// 截取对应位置的字节片段(避免修改原数组)
|
|
|
|
|
byte[] temp = new byte[length];
|
|
|
|
|
Array.Copy(source, startIndex, temp, 0, length);
|
|
|
|
|
|
|
|
|
|
var t = temp[0];
|
|
|
|
|
temp[0] = temp[2];
|
|
|
|
|
temp[2] = t;
|
|
|
|
|
t = temp[1];
|
|
|
|
|
temp[1] = temp[3];
|
|
|
|
|
temp[3] = t;
|
|
|
|
|
|
|
|
|
|
// 反转字节序(大端转小端)
|
|
|
|
|
Array.Reverse(temp);
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 预热炉数据获取
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -131,15 +169,14 @@ namespace Sln.Iot.Business
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var res = _plc.ReadBytes(_plc.DeltaInstance0, "D201", 4);
|
|
|
|
|
|
|
|
|
|
var result = res.Content.Reverse().ToArray();
|
|
|
|
|
UnitsProcess3Entity unitsProcess3Entity = new UnitsProcess3Entity()
|
|
|
|
|
{
|
|
|
|
|
PreCureOven1TempActValue = BitConverter.ToInt16(res.Content, 0),
|
|
|
|
|
PreCureOven2TempActValue = BitConverter.ToInt16(res.Content, 2),
|
|
|
|
|
PreCureOven3TempActValue = BitConverter.ToInt16(res.Content, 4),
|
|
|
|
|
PreCureOven4TempActValue = BitConverter.ToInt16(res.Content, 6),
|
|
|
|
|
PreCureOven4TempActValue = BitConverter.ToInt16(result, 0),
|
|
|
|
|
PreCureOven3TempActValue = BitConverter.ToInt16(result, 2),
|
|
|
|
|
PreCureOven2TempActValue = BitConverter.ToInt16(result, 4),
|
|
|
|
|
PreCureOven1TempActValue = BitConverter.ToInt16(result, 6),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return unitsProcess3Entity;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
@ -158,13 +195,13 @@ namespace Sln.Iot.Business
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var res = _plc.ReadBytes(_plc.DeltaInstance0, "D205", 4);
|
|
|
|
|
|
|
|
|
|
var result = res.Content.Reverse().ToArray();
|
|
|
|
|
UnitsProcess3Entity unitsProcess3Entity = new UnitsProcess3Entity()
|
|
|
|
|
{
|
|
|
|
|
CureOven1TempActValue = BitConverter.ToInt16(res.Content, 0),
|
|
|
|
|
CureOven2TempActValue = BitConverter.ToInt16(res.Content, 2),
|
|
|
|
|
CureOven3TempActValue = BitConverter.ToInt16(res.Content, 4),
|
|
|
|
|
CureOven4TempActValue = BitConverter.ToInt16(res.Content, 6),
|
|
|
|
|
CureOven4TempActValue = BitConverter.ToInt16(result, 0),
|
|
|
|
|
CureOven3TempActValue = BitConverter.ToInt16(result, 2),
|
|
|
|
|
CureOven2TempActValue = BitConverter.ToInt16(result, 4),
|
|
|
|
|
CureOven1TempActValue = BitConverter.ToInt16(result, 6),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return unitsProcess3Entity;
|
|
|
|
|
|