Skip to content

Conversation

@lvhuihui1988
Copy link

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.

@MarkRivers
Copy link
Member

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.

@lvhuihui1988
Copy link
Author

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.

@MarkRivers
Copy link
Member

I think for completeness we should also add INT16_BS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants