using HslCommunication; using HslCommunication.ModBus; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Const; using HybirdFrameworkDriver.ModbusTcpMaster; using Service.Ups.Msg; namespace Service.Ups; [Scope] public class UpsClient: ModbusTcpMaster { public UpsClient() { ReadAction = BatchRead; Ip = "192.168.3.100"; Port = 23; Duration = 1000; AutoReConnect = true; ByteSeq = EndingConst.ByteSeq.BA; WordSeq= EndingConst.WordSeq.CD; } private void BatchRead(ModbusTcpMaster master) { bool resul = Connected; ModbusTcpNet _client = new ModbusTcpNet(master.Ip, master.Port, 0x01); OperateResult operateResult01 = _client.Read("x=3;" + 1, (ushort)81); OperateResult operateResult02 = _client.Read("x=3;" + 1, (ushort)81); //0x03 var bytes02 = master.Read("x=3;1", 80).Content; if (bytes02 != null) { UpsMgr.DataValidityTime = DateTime.Now; ModbusDecoder.Decode(bytes02, UpsMgr.UpsRemoteComm, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC); } //0x04 var bytes01 = master.BatchReadInputRegister(81, 160); if (bytes01 != null) { UpsMgr.DataValidityTime = DateTime.Now; ModbusDecoder.Decode(bytes01, UpsMgr.UpsTelemetering, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC); } } }