From 99a6ee56656bb14bd0f98f954a08516c4d6aa90a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Sun, 25 Jun 2023 16:47:02 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=AE=AF=E7=BB=84=E4=BB=B6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Server/FryingPanServer.cs | 38 +++++++++---------- BPASmartClient.Tourism/Server/OtherServer.cs | 17 ++++----- .../Server/PressureCookerServer.cs | 5 +-- BPASmartClient.Tourism/Server/RobotServer.cs | 28 ++++++-------- 4 files changed, 40 insertions(+), 48 deletions(-) diff --git a/BPASmartClient.Tourism/Server/FryingPanServer.cs b/BPASmartClient.Tourism/Server/FryingPanServer.cs index 1c75626c..24b30b3e 100644 --- a/BPASmartClient.Tourism/Server/FryingPanServer.cs +++ b/BPASmartClient.Tourism/Server/FryingPanServer.cs @@ -15,38 +15,36 @@ namespace BPASmartClient.MorkCL.Server public void Init(string IP = "", int Port = 502, string PortName = "") { MyModbus = new ModbusTcp(); - MyModbus.Connected = () => + MyModbus.WithModbusTcp(IP, Port).UseConnected(() => { TaskManage.GetInstance.StartLong(new Action(() => { - var LB100 = MyModbus.Read("LB100".ToModbusAdd(), 13); - if (LB100.IsSuccess) + MyModbus.Read("LB100".ToModbusAdd(), 13).OnSuccess(s => { - InitComplete = LB100.Content[0]; - StatusMode = LB100.Content[1]; - EStop = LB100.Content[2]; + InitComplete = s[0]; + StatusMode = s[1]; + EStop = s[2]; - for (byte i = 0; i < 4; i++) StirFryingLocFB[i] = LB100.Content[i + 3]; + for (byte i = 0; i < 4; i++) StirFryingLocFB[i] = s[i + 3]; - DiningOutLocFB = LB100.Content[7]; - FeedingLocFB = LB100.Content[8]; - WashingPotLocFB = LB100.Content[9]; + DiningOutLocFB = s[7]; + FeedingLocFB = s[8]; + WashingPotLocFB = s[9]; - for (byte i = 0; i < 3; i++) ChannelDisCom[i] = LB100.Content[i + 10]; - } + for (byte i = 0; i < 3; i++) ChannelDisCom[i] = s[i + 10]; + }); - var LW20 = MyModbus.Read("LW20".ToModbusAdd(), 3); - if (LW20.IsSuccess) + + MyModbus.Read("LW20".ToModbusAdd(), 3).OnSuccess(s => { - CurrentTemperature = LW20.Content[0] * 10.0F; - CurrentSpeed = LW20.Content[1]; - HeatingGear = LW20.Content[2]; - } + CurrentTemperature = s[0] * 10.0F; + CurrentSpeed = s[1]; + HeatingGear = s[2]; + }); Thread.Sleep(10); }), $"炒锅服务-{IP}", true); - }; - MyModbus.Connect(new ConfigurationOptions() { IpAddress = IP, Port = Port }); + }); } } } diff --git a/BPASmartClient.Tourism/Server/OtherServer.cs b/BPASmartClient.Tourism/Server/OtherServer.cs index 12b41d12..1e67193a 100644 --- a/BPASmartClient.Tourism/Server/OtherServer.cs +++ b/BPASmartClient.Tourism/Server/OtherServer.cs @@ -15,21 +15,20 @@ namespace BPASmartClient.MorkCL.Server public void Init(string IP = "", int Port = 502, string PortName = "") { MyModbus = new ModbusRtu(); - MyModbus.Connected = () => + MyModbus.WithModbusRtu(PortName).UseConnected(() => { TaskManage.GetInstance.StartLong(new Action(() => { - var box = MyModbus.Read("LB100".ToModbusAdd(), 4); - if (box.IsSuccess) + MyModbus.Read("LB100".ToModbusAdd(), 4).OnSuccess(s => { - for (byte i = 0; i < box.Content.Length; i++) BoxDetection[i] = box.Content[i]; - } - var weight = MyModbus.Read("LW20".ToModbusAdd()); - if (weight.IsSuccess) CurrentWeight = weight.Content; + for (byte i = 0; i < s.Length; i++) BoxDetection[i] = s[i]; + }); + + MyModbus.Read("LW20".ToModbusAdd()).OnSuccess(s => { CurrentWeight = s; }); + Thread.Sleep(10); }), $"其它外部设备-{PortName}", true); - }; - MyModbus.Connect(new ConfigurationOptions() { PortName = PortName }); + }); } } } diff --git a/BPASmartClient.Tourism/Server/PressureCookerServer.cs b/BPASmartClient.Tourism/Server/PressureCookerServer.cs index c2fe25f5..df101e7a 100644 --- a/BPASmartClient.Tourism/Server/PressureCookerServer.cs +++ b/BPASmartClient.Tourism/Server/PressureCookerServer.cs @@ -14,15 +14,14 @@ namespace BPASmartClient.MorkCL.Server public void Init(string IP = "", int Port = 502, string PortName = "") { MyModbus = new ModbusTcp(); - MyModbus.Connected = () => + MyModbus.WithModbusTcp(IP, Port).UseConnected(() => { TaskManage.GetInstance.StartLong(new Action(() => { Thread.Sleep(10); }), $"压力锅服务-{IP}", true); - }; - MyModbus.Connect(new ConfigurationOptions() { IpAddress = IP, Port = Port }); + }); } } } diff --git a/BPASmartClient.Tourism/Server/RobotServer.cs b/BPASmartClient.Tourism/Server/RobotServer.cs index 9f9dede2..799bfc27 100644 --- a/BPASmartClient.Tourism/Server/RobotServer.cs +++ b/BPASmartClient.Tourism/Server/RobotServer.cs @@ -15,34 +15,30 @@ namespace BPASmartClient.MorkCL.Server public void Init(string IP = "", int Port = 502, string PortName = "") { MyModbus = new ModbusTcp(); - MyModbus.Connected = () => + MyModbus.WithModbusTcp(IP, Port).UseConnected(() => { TaskManage.GetInstance.StartLong(new Action(() => { - var m600 = MyModbus.Read("M600".ToModbusAdd(), 9); - if (m600.IsSuccess) + MyModbus.Read("M600".ToModbusAdd(), 9).OnSuccess(s => { for (byte i = 0; i < 3; i++) { - MaterialPouringRequest[i] = m600.Content[i * 3]; - MaterialPouringComplete[i] = m600.Content[i * 3 + 1]; - DiningOutRequest[i] = m600.Content[i * 3 + 2]; + MaterialPouringRequest[i] = s[i * 3]; + MaterialPouringComplete[i] = s[i * 3 + 1]; + DiningOutRequest[i] = s[i * 3 + 2]; } - } + }); - var m630 = MyModbus.Read("M630".ToModbusAdd(), 12); - if (m630.IsSuccess) - { - for (byte i = 0; i < m630.Content.Length; i++) WarehousingComplete[i] = m630.Content[i]; - } + MyModbus.Read("M630".ToModbusAdd(), 12).OnSuccess(s => + { + for (byte i = 0; i < s.Length; i++) WarehousingComplete[i] = s[i]; + }); - var gi = MyModbus.Read("GI5".ToModbusAdd(), 1); - if (gi.IsSuccess) TaskFeedback = (RobotMainTask)gi.Content; + MyModbus.Read("GI5".ToModbusAdd(), 1).OnSuccess(s => { TaskFeedback = (RobotMainTask)s; }); Thread.Sleep(10); }), $"机器人服务-{IP}", true); - }; - MyModbus.Connect(new ConfigurationOptions() { IpAddress = IP, Port = Port }); + }); } private void RobotInit()