using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkDriver.ModbusTcpMaster; using Repository.Station; using Service.Plc.Msg; namespace Service.Plc.Client; /// /// /// [Scope] public class PlcClient : ModbusTcpMaster { private BinInfoRepository _binInfoRepository; public PlcClient(BinInfoRepository binInfoRepository) { ReadAction = BatchRead; Ip = "172.0.20.66"; Port = 502; Duration = 2000; AutoReConnect = true; _binInfoRepository = binInfoRepository; } private void BatchRead(ModbusTcpMaster master) { var bytes01 = master.BatchReadHolderRegister(1, 115); if (bytes01 != null) { PlcMgr.DataValidityTime = DateTime.Now; ModbusDecoder.Decode(bytes01, PlcMgr.HostToPlcData); } var bytes02 = master.BatchReadHolderRegister(201, 222); if (bytes02 != null) { PlcMgr.DataValidityTime = DateTime.Now; ModbusDecoder.Decode(bytes02, PlcMgr.PlcToHostData); _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec01.Value, it => it.No == "1"); _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec02.Value, it => it.No == "2"); _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec03.Value, it => it.No == "3"); _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec04.Value, it => it.No == "4"); _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec05.Value, it => it.No == "5"); _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec06.Value, it => it.No == "6"); _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec07.Value, it => it.No == "7"); _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec08.Value, it => it.No == "8"); } var bytes03 = master.BatchReadHolderRegister(701, 10); if (bytes03 != null) { PlcMgr.DataValidityTime = DateTime.Now; ModbusDecoder.Decode(bytes03, PlcMgr.PlcFaultData); } } }