FluentModbus icon indicating copy to clipboard operation
FluentModbus copied to clipboard

Corruption of array passed to WriteMultipleRegistersAsync

Open tony-hailes opened this issue 2 years ago • 3 comments

With the option Connect(port, ModbusEndianness.BigEndian) the byte order of each item in an integer array passed to WriteMultipleRegistersAsync is changed.

tony-hailes avatar Aug 27 '21 15:08 tony-hailes

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?

Apollo3zehn avatar Aug 27 '21 17:08 Apollo3zehn

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.

tony-hailes avatar Sep 03 '21 09:09 tony-hailes

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.

Apollo3zehn avatar Sep 03 '21 11:09 Apollo3zehn