tokio-modbus icon indicating copy to clipboard operation
tokio-modbus copied to clipboard

How to convert tokio_modbus::Request to bytes?

Open cppcoffee opened this issue 2 years ago • 5 comments

The tokio_modbus::Request has TryFrom<Bytes> function, how to convert from Request to Bytes? just like impl into<Bytes> for tokio_modbus::Request.

cppcoffee avatar Jun 19 '23 09:06 cppcoffee

Please describe your use case.

uklotzde avatar Jun 19 '23 09:06 uklotzde

In my case, there is an endpoint that needs to add a data header to the modbus data and send it to it, which needs to be encapsulated using the modbus request data.

cppcoffee avatar Jun 19 '23 10:06 cppcoffee

We currently don't expose the low-level encoding/decoding of Modbus protocol messages at the API.

Implementing the public From/TryFrom traits that leak into the public API instead of using private functions was probably inappropriate and leads to those false expectations.

uklotzde avatar Jun 19 '23 10:06 uklotzde

Oh, I known. Is there any other way to get modbus data? Or tokio_modbus::Request a logical reference for assembling modbus data?

cppcoffee avatar Jun 19 '23 11:06 cppcoffee

This would require to extract the lower level code, preferably as a standalone crate: #22

uklotzde avatar Jun 19 '23 11:06 uklotzde