修正modbus浮点型数值写入

This commit is contained in:
zhanghuang515 2024-01-02 14:38:48 +08:00
parent 949e8ea805
commit 8bd2d3fbaa
2 changed files with 5 additions and 2 deletions

View File

@ -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;

View File

@ -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;