Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTU: Raise exception for unexpected slave or function code in response #117

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

acolomb
Copy link
Contributor

@acolomb acolomb commented Mar 10, 2021

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.

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.
@coveralls
Copy link

coveralls commented Mar 10, 2021

Coverage Status

Coverage decreased (-0.09%) to 96.175% when pulling e28591e on acolomb:frame-exception into f1128a7 on AdvancedClimateSystems:master.

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.

None yet

2 participants