Skip to content

Limit Write Multiple Coils to 1968 coils and answer ILLEGAL_VALUE - #3106

Merged
janiversen merged 2 commits into
pymodbus-dev:devfrom
anirudh12032008:fix-write-coils-max-count
Nov 28, 2026
Merged

janiversen merged 2 commits into
pymodbus-dev:devfrom
anirudh12032008:fix-write-coils-max-count

Conversation

@anirudh12032008

Copy link
Copy Markdown
Contributor

Fixes #3105.

Write Multiple Coils quantity is limited to 0x07B0 (1968) by the Modbus spec, so the PDU stays within 253 bytes. MAX_COUNT was 2000, which let a 256-byte PDU be encoded and accepted.

Decoding no longer raises on an out-of-range count; datastore_update answers ILLEGAL_VALUE instead of the request being dropped, matching the read requests (#3066) and Write Multiple Registers.

Tests: max count encodes within 253 bytes, 1969 is rejected, counts 0/1969/2000 get ILLEGAL_VALUE.

@janiversen janiversen left a comment

Copy link
Copy Markdown
Collaborator

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 b0d4132 into pymodbus-dev:dev Nov 28, 2026
16 checks passed
@janiversen

janiversen commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Just for info, normally we do not make separate test classes, but have one class for each type of tests, like e.g. one class for all coil tests.

But it does not disturb, nor make maintenance more complex, therefore it is merged as your choice.

@janiversen

Copy link
Copy Markdown
Collaborator

#3068 is updated with both the limit (was already done) and the test case.

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.

Write Multiple Coils accepts 2000 coils, spec limit is 1968

2 participants