Apollo3zehn / FluentModbus

Lightweight and fast client and server implementation of the Modbus protocol (TCP/RTU).
MIT License
189 stars 71 forks source link

Corruption of array passed to WriteMultipleRegistersAsync #52

Open tony-hailes opened 2 years ago

tony-hailes commented 2 years ago

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

Apollo3zehn commented 2 years ago

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?

tony-hailes commented 2 years ago

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.

Apollo3zehn commented 2 years ago

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.