Add a data type UINT16_BS : byte swapped in unsigned 16-bit integers
The PLC we used stores a word as an unsigned 16-bit integer. But bytes with this 16-bit register are swapped. This data type is not supported by Modbus. Therefore, I modified the source code to support 16-bit unsigned intergers with swapped bytes within a word. I add a new data type called UINT16_BS.
What type of computer are you running the Modbus driver on (for example Intel x64 with Linux, etc.)?
I want to make sure the problem is not with the endianness of the Modbus client. The Modbus specification is very clear that 16-bit values should be transmitted in network byte order, i.e. big-endian. The Modbus driver converts to the endianness of the host.
We use Linux x86-64. In Modbus, data types such as INT32_LE_BS and UINT32_LE_BS support byte swapping. However, for 16-bit unsigned integers, only UINT16 is available by default. To address this, I have added UINT16_BS, which enables byte swapping support for 16-bit unsigned integers.
I think for completeness we should also add INT16_BS.