tokio-modbus
tokio-modbus copied to clipboard
connect_slave reuse connections for different slaves ?
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
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.