plc重连机制

zw
rszn 4 months ago
parent 803cc739ba
commit 45e8818eee

@ -27,8 +27,9 @@ public class FireControlClient: ModbusTcpMaster
WordSeq= EndingConst.WordSeq.CD;
}
private void BatchRead(ModbusTcpMaster master)
private bool BatchRead(ModbusTcpMaster master)
{
bool connectResult = false;
//1电表
//2消防
//3温湿度
@ -39,6 +40,7 @@ public class FireControlClient: ModbusTcpMaster
var readPowerValue = master.Read("x=3;39424", 2).Content;
if (readPowerValue != null)
{
connectResult = true;
Array.Reverse(readPowerValue);
//ModbusDecoder.Decode<PowerValue>(readPowerValue, FireControlMgr.PowerValue, EndingConst.ByteSeq.BA, EndingConst.WordSeq.DC);
FireControlMgr.PowerValue.FPowerValue.Value=BitConverter.ToSingle(readPowerValue, 0);
@ -51,6 +53,7 @@ public class FireControlClient: ModbusTcpMaster
var readTem = master.Read("s=3;x=3;0", 2).Content;
if (readTem!=null)
{
connectResult = true;
ModbusDecoder.Decode<TemperatureHumidity>(readTem, FireControlMgr.TemperatureHumidity, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
}
@ -67,6 +70,7 @@ public class FireControlClient: ModbusTcpMaster
var bytesAdd2 = master.Read("s=2;x=4;3048", 1048).Content;//0x04 可以
if (bytesAdd1 != null && bytesAdd2 != null)
{
connectResult = true;
bytes06.AddRange(bytesAdd1);
bytes06.AddRange(bytesAdd2);
}
@ -79,6 +83,7 @@ public class FireControlClient: ModbusTcpMaster
if (bytes02 != null)
{
Log.Info("fire read bytes02 success");
connectResult = true;
FireControlMgr.Subzone2.GiveAnAlarm.Value = bytes02[0];
FireControlMgr.Subzone2.NumberOfFailures.Value = bytes02[1];
FireControlMgr.Subzone2.SoundSuppression.Value = bytes02[2];
@ -100,11 +105,13 @@ public class FireControlClient: ModbusTcpMaster
if (bytes03 != null)
{
connectResult = true;
ModbusDecoder.Decode<Subzone3>(bytes03, FireControlMgr.Subzone3, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
}
if (bytes04 != null)
{
connectResult = true;
ModbusDecoder.Decode<Subzone4>(bytes04, FireControlMgr.Subzone4, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
List<string> faultList = new List<string>()
{
@ -144,16 +151,19 @@ public class FireControlClient: ModbusTcpMaster
if (bytes05 != null)
{
connectResult = true;
ModbusDecoder.Decode<Subzone5>(bytes05, FireControlMgr.Subzone5, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
}
if (bytes06 != null)
{
connectResult = true;
ModbusDecoder.Decode<Subzone6>(bytes06.ToArray(), FireControlMgr.Subzone6, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
}
if (bytes07 != null)
{
connectResult = true;
ModbusDecoder.Decode<Subzone7>(bytes07, FireControlMgr.Subzone7, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
}
@ -167,6 +177,7 @@ public class FireControlClient: ModbusTcpMaster
ModbusDecoder.Decode<Subzone9>(bytes09, FireControlMgr.Subzone9, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC);
}*/
return connectResult;
}
private void SaveAlarmInfo(List<string> lstAlarm)

@ -53,16 +53,18 @@ public class PlcClient : ModbusTcpMaster
WordSeq = EndingConst.WordSeq.CD;
}
private void BatchRead(ModbusTcpMaster master)
private bool BatchRead(ModbusTcpMaster master)
{
bool connectResult = false;
try
{
Log.Info("Plc read satrt");
Log.Info("Plc read start");
if (master != null)
{
var bytes01 = master.BatchReadHolderRegister(1, 115);
if (bytes01 != null)
{
connectResult = true;
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<HostToPlc>(bytes01, PlcMgr.HostToPlcData, EndingConst.ByteSeq.AB,
@ -72,6 +74,7 @@ public class PlcClient : ModbusTcpMaster
var bytes02 = master.BatchReadHolderRegister(201, 222);
if (bytes02 != null)
{
connectResult = true;
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcToHost>(bytes02, PlcMgr.PlcToHostData, EndingConst.ByteSeq.AB,
EndingConst.WordSeq.DC);
@ -89,6 +92,7 @@ public class PlcClient : ModbusTcpMaster
var bytes03 = master.BatchReadHolderRegister(701, 32);
if (bytes03 != null)
{
connectResult = true;
PlcMgr.LastPlcFaultData = PlcMgr.PlcFaultData;
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcFault>(bytes03, PlcMgr.PlcFaultData, EndingConst.ByteSeq.AB,
@ -124,6 +128,7 @@ public class PlcClient : ModbusTcpMaster
var bytes01 = PlcMgr.PlcClient.BatchReadHolderRegister(1, 115);
if (bytes01 != null)
{
connectResult = true;
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<HostToPlc>(bytes01, PlcMgr.HostToPlcData, EndingConst.ByteSeq.AB,
@ -133,6 +138,7 @@ public class PlcClient : ModbusTcpMaster
var bytes02 = PlcMgr.PlcClient.BatchReadHolderRegister(201, 222);
if (bytes02 != null)
{
connectResult = true;
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcToHost>(bytes02, PlcMgr.PlcToHostData, EndingConst.ByteSeq.AB,
EndingConst.WordSeq.DC);
@ -150,6 +156,7 @@ public class PlcClient : ModbusTcpMaster
var bytes03 = PlcMgr.PlcClient.BatchReadHolderRegister(701, 32);
if (bytes03 != null)
{
connectResult = true;
PlcMgr.LastPlcFaultData = PlcMgr.PlcFaultData;
PlcMgr.DataValidityTime = DateTime.Now;
ModbusDecoder.Decode<PlcFault>(bytes03, PlcMgr.PlcFaultData, EndingConst.ByteSeq.AB,
@ -185,6 +192,8 @@ public class PlcClient : ModbusTcpMaster
Log.Info($"Plc read error:{e}");
throw;
}
return connectResult;
}
private void SaveAlarmInfo(List<string> lstAlarm)

Loading…
Cancel
Save