From 8bd2d3fbaa9fd277f2f392ded6b0da5069ecf8cb Mon Sep 17 00:00:00 2001 From: zhanghuang515 Date: Tue, 2 Jan 2024 14:38:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3modbus=E6=B5=AE=E7=82=B9?= =?UTF-8?q?=E5=9E=8B=E6=95=B0=E5=80=BC=E5=86=99=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Plugins/Drivers/PLC.ModBusMaster/DeviceModBusMaster.cs | 4 +++- Plugins/Plugin/DeviceThread.cs | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Plugins/Drivers/PLC.ModBusMaster/DeviceModBusMaster.cs b/Plugins/Drivers/PLC.ModBusMaster/DeviceModBusMaster.cs index 0ec7fa6..6e4e210 100644 --- a/Plugins/Drivers/PLC.ModBusMaster/DeviceModBusMaster.cs +++ b/Plugins/Drivers/PLC.ModBusMaster/DeviceModBusMaster.cs @@ -631,7 +631,9 @@ namespace PLC.ModBusMaster break; case DataTypeEnum.Float: var f = float.Parse(ioArg.Value.ToString()); - ModBusDataConvert.SetReal(shortArray, 0, f); + var fValue = BitConverter.SingleToUInt32Bits(f); + shortArray[1] = (ushort)(fValue & 0xffff); + shortArray[0] = (ushort)(fValue >> 16 & 0xffff); toWriteArray = ChangeBuffersOrder(shortArray, ioArg.EndianType); await _master.WriteMultipleRegistersAsync(slaveAddress, address, toWriteArray); break; diff --git a/Plugins/Plugin/DeviceThread.cs b/Plugins/Plugin/DeviceThread.cs index 5047fd5..74364ba 100644 --- a/Plugins/Plugin/DeviceThread.cs +++ b/Plugins/Plugin/DeviceThread.cs @@ -289,7 +289,8 @@ namespace Plugin { Address = deviceVariable.DeviceAddress, Value = para.Value, - ValueType = deviceVariable.DataType + ValueType = deviceVariable.DataType, + EndianType = deviceVariable.EndianType }; var writeResponse = Driver .WriteAsync(e.RequestId, deviceVariable.Method, ioArgModel).Result;