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

connect_slave reuse connections for different slaves ?

Open glennpierce opened this issue 3 years ago • 1 comments

I am using

tokio_modbus::client::sync::tcp::connect_slave

Is it possible to connect to one ip / port once and then read from different slaves with having to reconnect to each ?

Is this allow in modbus ? I am aware it would break the api so not suggesting it to be changed just curious if I could cache the connection maybe.

Thanks

glennpierce avatar May 13 '21 10:05 glennpierce

yes it is possible. try the set_slave() function. after let mut ctx = rtu::connect_slave(port, slave).await?; // it's rtu connection you can do: ctx.set_slave(Slave(device.id)); // to switch to another slave.

anatoliyzhang avatar Jan 04 '23 07:01 anatoliyzhang