FluentModbus
FluentModbus copied to clipboard
Corruption of array passed to WriteMultipleRegistersAsync
With the option Connect(port, ModbusEndianness.BigEndian) the byte order of each item in an integer array passed to WriteMultipleRegistersAsync is changed.
If you are running the client on a little-endian system, this is the expected behavior. The four bytes of each integer are reversed then to match the byte order of the Modbus server. For example 0x01 0x02 0x03 0x04
are transmitted as 0x04 0x03 0x02 0x01
. Or is the byte order changed in another (unexpected) way in your case?
In my application I use the array repeatedly, just changing one or two items in it. It means that before using the call I must make a copy of the array.
Yes, that might happen because the array is rented from an ArrayPool. But your use case makes sense and there should be an option to pass your own array. I'll think about it.