slowtec / tokio-modbus

A tokio-based modbus library
Apache License 2.0
378 stars 117 forks source link

How to get hexadecimal modbus rtu message data #257

Open byte-voyager opened 3 months ago

byte-voyager commented 3 months ago

https://github.com/slowtec/tokio-modbus/blob/main/examples/rtu-server.rs

impl tokio_modbus::server::Service for Service {
    type Request = SlaveRequest<'static>;
    type Future = future::Ready<Result<Response, Exception>>;

    fn call(&self, req: Self::Request) -> Self::Future {
        match req.request {
            Request::ReadInputRegisters(_addr, cnt) => {
                let mut registers = vec![0; cnt.into()];
                registers[2] = 0x77;
                future::ready(Ok(Response::ReadInputRegisters(registers)))
            }
            Request::ReadHoldingRegisters(_, _) => {
                future::ready(Err(Exception::IllegalDataAddress))
            }
            _ => unimplemented!(),
        }
    }
}

It doesn't seem to get the full byte message in this example

uklotzde commented 3 months ago

Is this a question or is this a bug report? Please provide a working, reproducible example.

byte-voyager commented 2 months ago

Is this a question or is this a bug report? Please provide a working, reproducible example.

Hi, want to use for logging full messages to the database