Python 3, Problem with byteorder/wordorder output from packing

325 views Asked by At

Using: Python 3, Endian, BinaryPayloadBuilder

Edit: This may be a known bug in pyModbus. I have heard mention of a similar problem with the byteorder-wordorder functions. For the time being, I have solved this with brute force coding and my payloads are working fine.

I have a problem with the BinaryPayloadBuilder output. I am trying to reproduce the correct byte order for a ModbusTCP transmission but the builder is giving me an unexpected result. I used Wireshark to sniff the proper order and tried to build the same message with python. The correct structure appears to be byteorder=Big.Endian, wordorder=Little.Endian according to the sniff but putting those setting into the builder doesn't change the output.

from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadBuilder

def run_binary_payload_ex():
    print()
    builder = BinaryPayloadBuilder(byteorder=Endian.Big, wordorder=Endian.Little)
    bStrng = "<ID 30><CLR>"
    builder.add_string(bStrng)
    payload = builder.to_registers()
    print(payload)
    print("\n")
    payload = builder.build()
    print(payload)

if __name__ == "__main__":
    run_binary_payload_ex()

Output:

[15433, 17440, 13104, 15932, 17228, 21054]


[b'<I', b'D ', b'30', b'><', b'CL', b'R>']

but I expected:

18748,  8260,  12339,  15422,  19523,  15954

[b'I<',  b' D',  b'03',  b'<>',  b'LC',  b'<R']

Bit order should be swapped for each pair. Can someone show me what I'm doing wrong?

0

There are 0 answers