-
Notifications
You must be signed in to change notification settings - Fork 122
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
TCP Server: How to return Modbus exception codes? #165
Comments
Hello, I'm trying to use I took a look at the code and the issues/PR this morning. I think #226 is a good start and I'll elaborate on that further. But I think that the downcast is a short fix, and will only postpone the problem to more complex cases. And I also don't like to show more private types to the public API. The public API should stay simple with 1. Modify
|
I had another ideas that popped in my mind will trying to implement the server. I'm putting everything down to bring more possibilities. 3. New
|
Separating orthogonal classes of errors from different layers in the (network) stack is usually done by nesting results:
The outer |
I agree that nesting the error feels more natural. That will requires changes in different Clientpub trait Client: SlaveContext + Send + Debug {
async fn call(&mut self, request: Request<'_>) -> Result<Result<Response, ExceptionResponse>, Error>;
} Reader/Writerpub trait Reader: Client {
async fn read_coils(&mut self, _: Address, _: Quantity) -> Result<Result<Vec<Coil>, Exception>, Error>;
}
pub trait Writer: Client {
async fn write_single_coil(&mut self, _: Address, _: Coil) -> Result<Result<(), Exception>, Error>;
} I saw in the implementation (let's say Because if we have the async fn read_discrete_inputs<'a>(&'a mut self, addr: Address, cnt: Quantity) -> Result<Result<Vec<Coil>, Exception>, Error> {
let rsp = self.client.call(Request::ReadDiscreteInputs(addr, cnt)).await?;
match rsp {
Ok(Response::ReadDiscreteInputs(mut coils)) => {
debug_assert!(coils.len() >= cnt.into());
coils.truncate(cnt.into());
Ok(Ok(coils))
},
Err(ExceptionResponse(_, exception)) => Ok(Err(exception)),
Ok(_) => unreachable!(), // fatal error, modbus-server is not returning valid response
}
} I don't know if it's a better idea to abort if the response is invalid, or return an Error, but the Exception should come from the server side, not the client. But since we follow the spec, this use case "should" never arise. ServerThanks to your server trait, we don't need to change anything because Pending questionsHow to handle the FeedbackWhat do you think ? |
See also: #163
The text was updated successfully, but these errors were encountered: