Changing the endianness of the Modbus client? #1248
-
Hi, I've been having some issues with converting little endian to big endian floats I get from the Modbus client. I know there are programmatic workarounds, but looking through the documentation, it seems there are functions or ways to set the client or do that "natively", that is using Pymodbus's internal functions or objects. Am I correct and if I am, could you point me to an example which does that or where should I look? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There are no way to tell the client to deliver in little endian for floats, since floats are minimum 2 registers. When you read a register with pymodbus the 2 bytes are automatically set to the endianness of the CPU, what you need to do is to combine reg[0] + reg[1] or reg[1] + reg[0] depending on your CPU. in https://github.com/riptideio/pymodbus/blob/dev/pymodbus/datastore/simulator.py we have internal function to do the changes:
|
Beta Was this translation helpful? Give feedback.
There are no way to tell the client to deliver in little endian for floats, since floats are minimum 2 registers.
When you read a register with pymodbus the 2 bytes are automatically set to the endianness of the CPU, what you need to do is to combine reg[0] + reg[1] or reg[1] + reg[0] depending on your CPU.
in https://github.com/riptideio/pymodbus/blob/dev/pymodbus/datastore/simulator.py we have internal function to do the changes: