Endianess for ModbusTcpServerSee original GitHub issue
I have seen that the ModbusTcpServer checks if we have Little or Big-Endian. My system (Linux ARM32) is Little-Endian. When I check the data (with ModbusPoll) - it is not reversed.
Span<short> inputreg = server.GetInputRegisterBuffer<short>(); inputreg = 1;
In ModbusPoll I got “256” (0x0100), I expected “1” (0x0001).
It was possible that I manually reverse my data before with
ModbusUtils.SwitchEndianness(), but I was wondering if there is a cleaner solution for it.
With the client I was able to receive the data in the correct endianess:
It would be great if someone could help me, or tell me if it makes sense to reverse every single value before.
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Yes the content is returned without changes. The check in the extension method will be lightweight, so you should not notice any performance impact.
Start offset: If you set the 8 byte double value to buffer, it would be located at byte positions 8-15 which is equal to Modbus registers 4-7 (with 2 bytes per Modbus register). But if you want to have it located at Modbus registers 1-5, you need a way to specify a start offset (in bytes).
Since everything is clear for me now, I will prepare a draft and hopefully finish it on Monday.
Sounds good, I think this is a good solution. Thanks a lot!