-
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
example: tcp server additions for read and write, error handling #163
Conversation
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.
Thank you! Very helpful addition for getting started. And it also revealed some gaps.
Only some minor comments.
This updated example for the TCP server has clarified many questions I had. However, one question I still have is how to store an |
Insted o call the new() function of the Service, you can create the data objects in the main function and clone it to your threads. #[tokio::main]
} async fn server_context(socket_addr: SocketAddr, ir: Arc<Mutex<HashMap<u16, u16>>>, hr: Arc<Mutex<HashMap<u16, u16>>>) -> anyhow::Result<()> { fn another_thread_context( ir: Arc<Mutex<HashMap<u16, u16>>>) { Or implement a new() function of the Service that receive the data instead of create inside the new function. |
I think this library is great, just lacking some better examples and documentation. It will came with time. I made myself an example where holding registers are structures with several different data such floating point and strings which uses a from trair to convert the scructs to Vec. This structs generate data in different threads using something like I suggest previouslly. |
How to implement service to create the registers HashMap in the main function: impl Service { |
Attempting to expand the TCP server example by adding support for holding register read/write support, plus demonstrating error handling on both client and server side.
Need help to figure out how to send specific Modbus exception responses on the server side, and how to identify the exception code on the client side. For instance, in this example we test accessing a register address that is not supported by the server, so the server should respond with the Modbus exception code
IllegalDataAddress
.