From 9a14ec46c446d6fa91d218ac8dd1b9eb62251d5c 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: Tue, 4 Jul 2023 11:32:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=8E=E7=AB=99=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BPASmartClient.MorkCL/Server/OtherServer.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/BPASmartClient.MorkCL/Server/OtherServer.cs b/BPASmartClient.MorkCL/Server/OtherServer.cs index 1e67193a..b95e2a43 100644 --- a/BPASmartClient.MorkCL/Server/OtherServer.cs +++ b/BPASmartClient.MorkCL/Server/OtherServer.cs @@ -17,14 +17,18 @@ namespace BPASmartClient.MorkCL.Server MyModbus = new ModbusRtu(); MyModbus.WithModbusRtu(PortName).UseConnected(() => { + ModbusRtu myDevice = (ModbusRtu)MyModbus; TaskManage.GetInstance.StartLong(new Action(() => { - MyModbus.Read("LB100".ToModbusAdd(), 4).OnSuccess(s => + //设置站号 + myDevice.SlaveAddress = 1; + + myDevice.Read("LB100".ToModbusAdd(), 4).OnSuccess(s => { for (byte i = 0; i < s.Length; i++) BoxDetection[i] = s[i]; }); - MyModbus.Read("LW20".ToModbusAdd()).OnSuccess(s => { CurrentWeight = s; }); + myDevice.Read("LW20".ToModbusAdd()).OnSuccess(s => { CurrentWeight = s; }); Thread.Sleep(10); }), $"其它外部设备-{PortName}", true);