From 5eaae41b80fb2523eef05a4757dff25975a86a88 Mon Sep 17 00:00:00 2001 From: smartwyy <645583145@qq.com> Date: Wed, 29 May 2024 20:57:07 +0800 Subject: [PATCH] =?UTF-8?q?plc=E6=9B=B4=E6=96=B0=E5=9C=A8=E4=BD=8D?= =?UTF-8?q?=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Plc/Client/PlcClient.cs | 59 ++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/Service/Plc/Client/PlcClient.cs b/Service/Plc/Client/PlcClient.cs index 7d5d8b3..2b18b06 100644 --- a/Service/Plc/Client/PlcClient.cs +++ b/Service/Plc/Client/PlcClient.cs @@ -1,4 +1,5 @@ -using HybirdFrameworkCore.Autofac.Attribute; +using Entity.DbModel.Station; +using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Const; using HybirdFrameworkDriver.ModbusTcpMaster; using Repository.Station; @@ -33,42 +34,54 @@ public class PlcClient : ModbusTcpMaster { PlcMgr.DataValidityTime = DateTime.Now; - ModbusDecoder.Decode(bytes01, PlcMgr.HostToPlcData, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC); + ModbusDecoder.Decode(bytes01, PlcMgr.HostToPlcData, EndingConst.ByteSeq.AB, + EndingConst.WordSeq.DC); } var bytes02 = master.BatchReadHolderRegister(201, 222); if (bytes02 != null) { PlcMgr.DataValidityTime = DateTime.Now; - ModbusDecoder.Decode(bytes02, PlcMgr.PlcToHostData, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC); - - _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec01.Value, it => it.No == "1"); + ModbusDecoder.Decode(bytes02, PlcMgr.PlcToHostData, EndingConst.ByteSeq.AB, + EndingConst.WordSeq.DC); - - _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec02.Value, it => it.No == "2"); + UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec01.Value, "1"); + UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec02.Value, "2"); + UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec03.Value, "3"); + UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec04.Value, "4"); + UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec05.Value, "5"); + UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec06.Value, "6"); + UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec07.Value, "7"); + UpdateBinInfo(PlcMgr.PlcToHostData.MaterialDetec08.Value, "8"); - - _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, EndingConst.ByteSeq.AB, EndingConst.WordSeq.DC); + ModbusDecoder.Decode(bytes03, PlcMgr.PlcFaultData, EndingConst.ByteSeq.AB, + EndingConst.WordSeq.DC); } } + + private void UpdateBinInfo(int exists, string binNo) + { + if (exists == 0) + _binInfoRepository.Update( + it => + new BinInfo(){ + Exists = 0, + BatteryNo = "-1", + Soc = (decimal)-1, + Soe = (decimal)-1, + Soh = (decimal)-1, + }, + it => it.No == binNo); + else + + _binInfoRepository.Update(it => it.Exists == 1, + it => it.No == binNo); + + } } \ No newline at end of file