!8 修正modbus浮点型数值写入

Merge pull request !8 from 卡卡罗特/master
This commit is contained in:
Sam 2024-01-02 08:49:29 +00:00 committed by Gitee
commit ad2a17e803
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
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;