using HybirdFrameworkCore.Const; using HybirdFrameworkDriver.ModbusTcpMaster; using Service.UpsAfrica.Msg; namespace Service.UpsAfrica.Client; public class UpsAfricaClient: ModbusTcpMaster { public UpsAfricaClient() { ReadAction = BatchRead; Ip = "192.168.3.100"; Port = 23; Duration = 1000; AutoReConnect = true; ByteSeq = EndingConst.ByteSeq.BA; WordSeq= EndingConst.WordSeq.CD; } private bool BatchRead(ModbusTcpMaster master) { bool resul = Connected; var bytes01 = master.Read("x=3;48", 2).Content; if (bytes01 != null) { UpsAfricaMgr.DataValidityTime = DateTime.Now; ModbusDecoder.Decode(bytes01, UpsAfricaMgr.UpsIndex30, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC); resul = true; } var bytes02 = master.Read("x=3;64", 17).Content; if (bytes02 != null) { UpsAfricaMgr.DataValidityTime = DateTime.Now; ModbusDecoder.Decode(bytes02, UpsAfricaMgr.UpsIndex40, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC); resul = true; } var bytes03 = master.Read("x=3;80", 4).Content; if (bytes03 != null) { UpsAfricaMgr.DataValidityTime = DateTime.Now; ModbusDecoder.Decode(bytes03, UpsAfricaMgr.UpsIndex50, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC); resul = true; } var bytes04 = master.Read("x=3;96", 8).Content; if (bytes04 != null) { UpsAfricaMgr.DataValidityTime = DateTime.Now; ModbusDecoder.Decode(bytes04, UpsAfricaMgr.UpsIndex60, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC); resul = true; } var bytes05 = master.Read("x=3;160", 1).Content; if (bytes05 != null) { UpsAfricaMgr.DataValidityTime = DateTime.Now; ModbusDecoder.Decode(bytes05, UpsAfricaMgr.UpsIndexA0, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC); resul = true; } var bytes06 = master.Read("x=3;192", 1).Content; if (bytes06 != null) { UpsAfricaMgr.DataValidityTime = DateTime.Now; ModbusDecoder.Decode(bytes06, UpsAfricaMgr.UpsIndexC0, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC); resul = true; } return resul; } }