Skip to content

read_coils() report wrong bit order in 3.9.0 #2630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
chkr-private opened this issue Apr 8, 2025 · 2 comments · Fixed by #2631
Closed

read_coils() report wrong bit order in 3.9.0 #2630

chkr-private opened this issue Apr 8, 2025 · 2 comments · Fixed by #2631

Comments

@chkr-private
Copy link
Contributor

My modbus device is reporting the following coils starting at address 0x100: true, false, true, false, true, true, ... .

pymodbus 3.8.6 returned the bits in the correct order:

>>> client.read_coils(0x100, count=16).bits
[True, False, True, False, True, True, True, True, True, True, True, True, True, True, True, True]

pymodbus 3.9.0 returns the values byte-wise swapped:

>>> client.read_coils(0x100, count=16).bits
[True, True, True, True, True, True, True, True, True, False, True, False, True, True, True, True]

It seems, that pymodbus 3.9.0 misinterprets the on-wire protocol.

According to the Modbus Application Protocol 1.1b document, section 6.1, the data bytes should be interpreted one by one starting with the first byte and the bits should be interpreted starting at the LSB for each byte.

In my case, the device returns 2 data bytes: 0xf5, 0xff and so the bits should be interpreted as follows:

  • starting with the first byte (0xf5), interpreting the bits starting at LSB: true, false, true, false, true, true, true, true
  • then the 2nd byte (0xff), starting at LSB: true, true, ...

The modbus dissector in wireshark confirms it:

Image

It looks like that commit d47dc65 has broken the bit order in 3.9.0.

@janiversen
Copy link
Collaborator

hmm, could be a bug, I will take a look later

@janiversen
Copy link
Collaborator

janiversen commented Apr 9, 2025

bug confirmed, this will be released as v3.9.1

Actually it is a feature for v4.0 where bits will be reported from LSB to MSB across bytes.

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 a pull request may close this issue.

2 participants