You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can user code using tokio-modbus as a Modbus client detect what specific exception code a server returned?
Two interrelated parts of this question:
How user code can distinguish between a recoverable error during a Modbus request, (e.g. IllegalDataAddress, and a connection failure, e.g. TCP connection closed by remote host, or a protocol framing error.)
How can user code identify which specific Modbus exception code was returned by the server. (E.g. IllegalDataAddress vs IllegalFunction)
In the case of Modbus exception responses, we don't want to close the Modbus connection. But if the network connection was lost, then user code needs to re-create a new tokio-modbus connection and start over.
I'm really in the need of finding out what Modbus error I got from a slave for my application.
I noticed it's not possible using tokio-modbus yet (at leat without doing silly err.to_string().contains("illegal data address"), and co), and found this issue.
After looking through the code. I found a fast, simple way to get access to the exception from a modbus server. You just have to make the ExceptionResponse and Exception types publicy accessible. Then someone using this crate can try to downcast the std::io::Error to the ExceptionResponse type to extract the error.
How can user code using tokio-modbus as a Modbus client detect what specific exception code a server returned?
Two interrelated parts of this question:
In the case of Modbus exception responses, we don't want to close the Modbus connection. But if the network connection was lost, then user code needs to re-create a new tokio-modbus connection and start over.
Related:
The text was updated successfully, but these errors were encountered: