Skip to content

Answer ILLEGAL_VALUE for Read Device Identification code 0 - #3095

Merged
janiversen merged 2 commits into
pymodbus-dev:devfrom
DanShinde:device-id-read-code
Nov 24, 2026
Merged

janiversen merged 2 commits into
pymodbus-dev:devfrom
DanShinde:device-id-read-code

Conversation

@DanShinde

Copy link
Copy Markdown
Contributor

ReadDeviceInformationRequest.datastore_update() accepts read device id code 0x00, but only codes 01-04 are defined (and only those are in DeviceInformationFactory). A request with code 0 raises KeyError in the lookup, the server logs a traceback and answers DEVICE_FAILURE.

The range check now starts at 0x01, so code 0 gets ILLEGAL_VALUE like codes above 0x04, which is what the spec asks for an invalid read device id code.

Test added in test_read_device_information_request_error; it fails with KeyError: 0 without the change.

Read Device ID code 0x00 is not defined (valid codes are 01-04), but the
range check let it through, so the lookup raised KeyError and the
server logged a traceback and answered DEVICE_FAILURE.

Reject it with ILLEGAL_VALUE, like codes above 04.

@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

Copy link
Copy Markdown
Collaborator

Added to #3068.

@janiversen
janiversen merged commit 5181a87 into pymodbus-dev:dev Nov 24, 2026
16 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