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
This is a tracking issue for progress on adding Modbus Exception code available to use in the client and server side.
Goal
The goal is to provide:
A simple API to use for the user in the client side.
When calling a modbus function, the user should easily access the wanted data or the exception.
A simple API to use for the user in the server side.
When implementing a server, the user should be able to simply return exception codes, and the server should send the appropriate Response type.
Use cases
I'll try to present the wanted usage of this library from my pov. I'm currently using this library as a client and a server, and the use cases showed here is what I feel is a good way of using a modbus library in Rust.
Please, feel free to add your use case if you think this proposition is not very good for it. Or, if you agree with the proposition.
Client
The client must be able to call a modbus function and easily see what failed.
#[tokio::main]asyncfnmain() -> Result<(),Box<dyn std::error::Error>>{use tokio_modbus::prelude::*;let socket_addr = "127.0.0.1:5502".parse().unwrap();letmut ctx = tcp::connect(socket_addr).await?;loop{// Read input registers and return if a fatal communication error occuredlet data = ctx.read_input_registers(0x1000,7).await?;match data {Ok(data) => println!("My data: {:?}", data),// Handle your data hereErr(exception) => println!("Modbus exception: {}", exception),// Handle the exception here}}Ok(())}
Server
The server is responsible to return a valid response or an exception according to the user needs.
The server should be very simple to implement, because if we follow the Modbus spec, if an error occurs, the server must send a specific Exception. Thus removing the need to have std::io::Error on the server implementation side.
Thus, implementing the server will only require returning the correct Response for a Request. Returning the appropriate Exception when an error arise in the implementation (following the modbus specification). If any error should occur during the processing of the modbus command, the Exception::ServerDeviceFailure must be sent, and the user implementing the server should log the error in order to be able to understand what happened.
Here, the server will take care of building the appropriate ExceptionResponse, because it already has the Request, it can then build the Response with the FunctionCode and the returned Exception.
Mandatory
We need a few things before being able to send and receive Exception code.
This proposition includes a lot of breaking changes to try to simplify the client/server implementation. Since we are not in 1.0, I hope it's not too much of a change.
Tell me if you think we should do it another way. Or if you have other plans.
Please, feel free to give your feedback in order to improve the current proposition, I'll be updating this issue if more questions arise.
The text was updated successfully, but these errors were encountered:
This is a tracking issue for progress on adding Modbus
Exception
code available to use in theclient
andserver
side.Goal
The goal is to provide:
client
side.server
side.Use cases
I'll try to present the wanted usage of this library from my pov. I'm currently using this library as a
client
and aserver
, and the use cases showed here is what I feel is a good way of using a modbus library in Rust.Please, feel free to add your use case if you think this proposition is not very good for it. Or, if you agree with the proposition.
Client
The client must be able to call a modbus function and easily see what failed.
Server
The server is responsible to return a valid response or an exception according to the user needs.
The server should be very simple to implement, because if we follow the Modbus spec, if an error occurs, the server must send a specific
Exception
. Thus removing the need to havestd::io::Error
on the server implementation side.Thus, implementing the server will only require returning the correct
Response
for aRequest
. Returning the appropriateException
when an error arise in the implementation (following the modbus specification). If any error should occur during the processing of the modbus command, theException::ServerDeviceFailure
must be sent, and the user implementing the server should log the error in order to be able to understand what happened.Here, the server will take care of building the appropriate
ExceptionResponse
, because it already has theRequest
, it can then build theResponse
with theFunctionCode
and the returnedException
.Mandatory
We need a few things before being able to send and receive
Exception
code.Exception
type in the public API. Publicly exportExceptionResponse
andException
types #218Client
,Reader
andWriter
trait in order to return anException
.Service
trait in order to return anException
if an Error occurs.process
function to correctly build aResponse
or anExceptionResponse
.Response
or anException
.Response
or anException
.Optional
FunctionCode
type in order to simplify the library. ReplaceFunctionCode
type alias with enum #236Questions
Exception
implement the traitError
in order to be able to handle errors more easily ?let data = ctx.read_input_registers(0x1000, 7).await??;
Previous propositions and discussion
Breaking Changes
This proposition includes a lot of breaking changes to try to simplify the client/server implementation. Since we are not in
1.0
, I hope it's not too much of a change.Tell me if you think we should do it another way. Or if you have other plans.
Please, feel free to give your feedback in order to improve the current proposition, I'll be updating this issue if more questions arise.
The text was updated successfully, but these errors were encountered: