Skip to content

This PR improves Modbus RTU master extensibility and broadcast support.#209

Closed
shijianoo wants to merge 1 commit intoNModbus:masterfrom
shijianoo:master
Closed

This PR improves Modbus RTU master extensibility and broadcast support.#209
shijianoo wants to merge 1 commit intoNModbus:masterfrom
shijianoo:master

Conversation

@shijianoo
Copy link

Main Changes

  • ReadResponse<T> now accepts an IModbusMessage request parameter. This allows the response handler to access the original request's slave address and function code, enabling more flexible and accurate response parsing, especially for broadcast scenarios.
  • The methods ValidateResponse and ShouldRetryResponse are now marked as virtual. This allows subclasses to override them and implement custom logic (such as not enforcing slave ID match when the request is a broadcast).

Why

  • Broadcast requests (slaveId = 0) require special handling, since any slave (1-247) can reply and strict address checks should be relaxed.
  • Making validation and retry logic virtual makes it much easier for downstream users to customize behavior for different Modbus RTU devices or edge cases without modifying the base library.

Additional Notes

  • These changes are backwards compatible except for the new parameter in ReadResponse<T>.
  • Improves robustness and flexibility in noisy or complex Modbus RTU environments.

@shijianoo shijianoo closed this Jun 7, 2025
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

Comments