Skip to content

Changing the endianness of the Modbus client? #1248

Answered by janiversen
nikstp asked this question in Help
Discussion options

You must be logged in to vote

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:

@classmethod
    def build_value_from_registers(cls, registers, is_int):
        """Build registers from int32 or float32"""
        value_bytes = int.to_bytes(registers[0], 2, "big") + int.to_bytes(
            registers[1], 2, "big"
        )
        if is_in…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nikstp
Comment options

Answer selected by nikstp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants