RTU: Raise exception for unexpected slave or function code in response#117
Open
acolomb wants to merge 2 commits intoAdvancedClimateSystems:masterfrom
Open
RTU: Raise exception for unexpected slave or function code in response#117acolomb wants to merge 2 commits intoAdvancedClimateSystems:masterfrom
acolomb wants to merge 2 commits intoAdvancedClimateSystems:masterfrom
Conversation
For RTU links, the specification (section 2.4.1) says the following: "When a reply is received, the Master checks the reply before starting the data processing. The checking may result in an error, for example a reply from an unexpected slave, or an error in the received frame." Technically, such frame errors include a mismatch in the response CRC or slave address. The CRC is handled by uModbus, but the slave address is not checked. If the function code does not match the request, uModbus will also happily parse it and return data which is valid, but unrelated to the application's request. The latter two should be regarded as a failure in send_message() as well, which this change does by throwing a specific exception. The standard goes on to specify that the "Response time-out" should be kept running if a response comes from the wrong slave. However, no such mechanism exists in uModbus yet (relying on the serial port RX timeout). This simple approach does not fix that inconsistency with the spec, but still allows better error handling in the application.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For RTU links, the specification (section 2.4.1) says the following:
"When a reply is received, the Master checks the reply before starting
the data processing. The checking may result in an error, for example
a reply from an unexpected slave, or an error in the received frame."
Technically, such frame errors include a mismatch in the response CRC
or slave address. The CRC is handled by uModbus, but the slave
address is not checked. If the function code does not match the
request, uModbus will also happily parse it and return data which is
valid, but unrelated to the application's request. The latter two
should be regarded as a failure in send_message() as well, which this
change does by throwing a specific exception.
The standard goes on to specify that the "Response time-out" should be
kept running if a response comes from the wrong slave. However, no
such mechanism exists in uModbus yet (relying on the serial port RX
timeout). This simple approach does not fix that inconsistency with
the spec, but still allows better error handling in the application.