From 59a7492a3161e2d9162f3e2378687d01e445ec42 Mon Sep 17 00:00:00 2001 From: CZ Date: Wed, 29 May 2024 17:10:09 +0800 Subject: [PATCH] =?UTF-8?q?PLC=E6=A3=80=E6=B5=8B=E6=B2=A1=E7=94=B5?= =?UTF-8?q?=E6=B1=A0=E6=97=B6=E6=9B=B4=E6=96=B0SOC=E4=B8=BA-1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Plc/Client/PlcClient.cs | 52 ++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/Service/Plc/Client/PlcClient.cs b/Service/Plc/Client/PlcClient.cs index aaf912d..00c0783 100644 --- a/Service/Plc/Client/PlcClient.cs +++ b/Service/Plc/Client/PlcClient.cs @@ -32,8 +32,8 @@ public class PlcClient : ModbusTcpMaster if (bytes01 != null) { PlcMgr.DataValidityTime = DateTime.Now; - - ModbusDecoder.Decode(bytes01, PlcMgr.HostToPlcData); + + ModbusDecoder.Decode(bytes01, PlcMgr.HostToPlcData); } var bytes02 = master.BatchReadHolderRegister(201, 222); @@ -41,14 +41,46 @@ public class PlcClient : ModbusTcpMaster { 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"); + if (PlcMgr.PlcToHostData.MaterialDetec01.Value == 1) + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec01.Value && it.BatteryNo == "-1" && it.Soc == (decimal)(-1) && it.Soe == (decimal)(-1) && it.Soh == (decimal)(-1), it => it.No == "1"); + else + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec01.Value, it => it.No == "1"); + + if (PlcMgr.PlcToHostData.MaterialDetec02.Value == 1) + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec02.Value && it.BatteryNo == "-1" && it.Soc == (decimal)(-1) && it.Soe == (decimal)(-1) && it.Soh == (decimal)(-1), it => it.No == "2"); + else + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec02.Value, it => it.No == "2"); + + if (PlcMgr.PlcToHostData.MaterialDetec03.Value == 1) + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec03.Value && it.BatteryNo == "-1" && it.Soc == (decimal)(-1) && it.Soe == (decimal)(-1) && it.Soh == (decimal)(-1), it => it.No == "3"); + else + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec03.Value, it => it.No == "3"); + + if (PlcMgr.PlcToHostData.MaterialDetec04.Value == 1) + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec04.Value && it.BatteryNo == "-1" && it.Soc == (decimal)(-1) && it.Soe == (decimal)(-1) && it.Soh == (decimal)(-1), it => it.No == "4"); + else + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec04.Value, it => it.No == "4"); + + if (PlcMgr.PlcToHostData.MaterialDetec05.Value == 1) + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec05.Value && it.BatteryNo == "-1" && it.Soc == (decimal)(-1) && it.Soe == (decimal)(-1) && it.Soh == (decimal)(-1), it => it.No == "5"); + else + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec05.Value, it => it.No == "5"); + + if (PlcMgr.PlcToHostData.MaterialDetec06.Value == 1) + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec06.Value && it.BatteryNo == "-1" && it.Soc == (decimal)(-1) && it.Soe == (decimal)(-1) && it.Soh == (decimal)(-1), it => it.No == "6"); + else + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec06.Value, it => it.No == "6"); + + if (PlcMgr.PlcToHostData.MaterialDetec07.Value == 1) + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec07.Value && it.BatteryNo == "-1" && it.Soc == (decimal)(-1) && it.Soe == (decimal)(-1) && it.Soh == (decimal)(-1), it => it.No == "7"); + else + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec07.Value, it => it.No == "7"); + + if (PlcMgr.PlcToHostData.MaterialDetec08.Value == 1) + + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec08.Value && it.BatteryNo == "-1" && it.Soc == (decimal)(-1) && it.Soe == (decimal)(-1) && it.Soh == (decimal)(-1), it => it.No == "8"); + else + _binInfoRepository.Update(it => it.Exists == PlcMgr.PlcToHostData.MaterialDetec08.Value, it => it.No == "8"); } var bytes03 = master.BatchReadHolderRegister(701, 10);