Skip to content
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

More documentation for the server features #128

Open
raoulspronck opened this issue Oct 25, 2022 · 3 comments
Open

More documentation for the server features #128

raoulspronck opened this issue Oct 25, 2022 · 3 comments

Comments

@raoulspronck
Copy link

Hi there,

I want to build an TCP modbus server to be able to connect multiple robots and machines in our machine park. I came across this tokio-modbus library for rust. I followed the examples to build an TCP Server but I'm missing some documentation about all the functions and how to implement them.

got this from the documentation but is it really reading an register or do I need to implement this on my own?

impl Service for MbServer {
    type Request = Request;
    type Response = Response;
    type Error = std::io::Error;
    type Future = future::Ready<Result<Self::Response, Self::Error>>;
    fn call(&self, req: Self::Request) -> Self::Future {
        println!("{:?}", req);
        match req {
            Request::ReadInputRegisters(_addr, cnt) => {
                let mut registers = vec![0; cnt.into()];
                registers[2] = 77;
                future::ready(Ok(Response::ReadInputRegisters(registers)))
            }
            _ => unimplemented!(),
        }
    }
}

How do I write an input register ? Do I do it like this or?

Request::WriteSingleRegister(addr, cnt) => {
    let adress = addr.into();
    let register = cnt.into();
    future::ready(Ok(Response::WriteSingleRegister(adress, register)))
}

And how do you implement all the other functions like reading/writing coils, ....

I like how easy this library was to set up compared to others but I'm missing some documentation or some more extensive examples.

Maybe it is just me and I'm sorry if this all sounded dumb but can anyone help me?

Thanks in advance!

@cdbennett
Copy link
Contributor

Agreed, would be great to have some better documentation and examples.

I am looking at using this library as both a client and as a server. I'd be willing to help contribute to some examples.

Sounds like the server code is going to be extracted into a separate crate. See #146 for the tracking issue. (It's behind a tcp-server-unstable feature flag already, which is a sign that something is up.)

@uklotzde
Copy link
Member

Welcome @cdbennett.

Since we have no use case with actual requirements and are also short on resources (time and money) there is nothing "up". #146 only documents my and our opinion on how to proceed in the future.

If you are able to prove that the server traits are suitable for more than just implementing some toy examples and could provide feedback for improving both implementation and documentation that would be great.

@cdbennett
Copy link
Contributor

I started expanding the tcp-server example in #163 . I'm trying to figure out how to send and receive Modbus exception responses with specific code handling, e.g. invalid function code, invalid data address. Maybe the means to do this is not exposed publicly in the API yet. Or maybe I just haven't figured it out yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants