-
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
refacto: new Client
API
#248
Conversation
…o::Result<crate::Result<Response>>`
… to `io::Result<crate::Result<Response>>`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for implementing the nested Result proposal. Looks good so far. It nicely separates technical from semantic/logic errors.
Hi, Thanks for the feedback ! I need to also update the examples with the new client API to correctly // Now we try to read with an invalid register address.
// This should return a Modbus exception response with the code
// IllegalDataAddress.
println!("CLIENT: Reading nonexisting holding register address... (should return IllegalDataAddress)");
let response = ctx.read_holding_registers(0x100, 1).await;
println!("CLIENT: The result is '{response:?}'");
assert!(response.is_err());
// TODO: How can Modbus client identify Modbus exception responses? E.g. here we expect IllegalDataAddress
// Question here: https://github.com/slowtec/tokio-modbus/issues/169 Like this part with an I'll add the |
Updating the examples will hopefully also reveal if this approach is usable in practice. |
47aac49
to
1d64c48
Compare
1d64c48
to
3176718
Compare
I tried it with our I need to try with a more complex use case with multiple functions called asynchronously and in parallel. But things are looking great already ! |
I have just one small question regarding the use of Can you confirm that the paths with |
Paths marked as Sometimes you simply cannot proof statically that certain paths are never executed. In this case |
Agreed, For me, going down the self.client
.call(Request::ReadCoils(addr, cnt))
.await
.map(|modbus_rsp| {
modbus_rsp.map(|rsp| match rsp {
Response::ReadCoils(mut coils) => {
debug_assert!(coils.len() >= cnt.into());
coils.truncate(cnt.into());
coils
}
others => {
unreachable!(
"unexpected response code: {} (request code: {})",
others.function_code(),
FunctionCode::ReadCoils
)
}
})
}) Is a bug in the Are we ok with that ? If so, I think the PR is ready 👍🏻 |
Could you add a comment that points the reader where this is handled? Because at first sight it looks like the code would panic on invalid inputs. |
Add link to `tokio-modbus` issue to ease the reporting of the bug.
8576673
to
e811b18
Compare
Moved Added dev doc comments to explain why the Improved error message in Is it ok to have a link directly to the github issue page in the error message ? |
Sorry for the delay. I hope to review your PR again soon. Please be patient 🙈 |
Feedback from other users of this library would be greatly appreciated. Those are the ones that are most affected by this substantial API refactoring. |
Merge main and fix issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions for the wording in the changelog.
The new
Client
API enables the user to have 2 errors returned when calling a Modbus function.std::io::Error
: An error occured on the network side.tokio_modbus::Exception
: An error occured on the Modbus server.Tasks
Result
type alias.Client
trait.tcp-server.rs
tls-server.rs
rtu-server.rs
rtu-server-address.rs
rtu-over-tcp-server.rs