Skip to content

Fix reg_count calc#2924

Merged
janiversen merged 1 commit intopymodbus-dev:devfrom
rubenmendes-eaton:sim-reg_count-fix
Apr 20, 2026
Merged

Fix reg_count calc#2924
janiversen merged 1 commit intopymodbus-dev:devfrom
rubenmendes-eaton:sim-reg_count-fix

Conversation

@rubenmendes-eaton
Copy link
Copy Markdown
Contributor

The current formula computes the number of 16-bit registers needed based only on the bit count, ignoring where within the first register the read starts. It breaks when bit_offset + count > 16, i.e., the requested bits actually span a register boundary.

Also, when address is a multiple of 16, the formula over-allocates by 1 register.

The first part of the following "if" also does not seem correct.

Copy link
Copy Markdown
Collaborator

@janiversen janiversen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@janiversen janiversen merged commit dba82f8 into pymodbus-dev:dev Apr 20, 2026
18 checks passed
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