You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think that serial port in windows wait some timeout or when buffer will be full. But i don't know how to fix it.
I'm control with oscilloscope that device response immediately (about 1 ms)
OS - Windows
Code:
fn main() -> Result<(), Box<dyn std::error::Error>> {
use tokio_modbus::prelude::*;
let tty_path = "COM6";
let slave = Slave(0x2);
let builder = tokio_serial::new(tty_path, 115200)
.data_bits(tokio_serial::DataBits::Eight)
.parity(tokio_serial::Parity::Even)
.stop_bits(tokio_serial::StopBits::One);
let mut ctx = sync::rtu::connect_slave(&builder, slave)?;
println!("Reading a sensor value");
let mut now;
loop {
now = time::Instant::now();
let res = ctx.read_holding_registers(0x1301, 1);
match res {
Err(er) => println!("Not OK {}", er),
Ok(val) => println!("Sensor value is: ok - {:?}, time is: {}", val, now.elapsed().as_micros()),
};
};
Ok(())
}
Output:
Reading a sensor value
Sensor value is: ok - Ok([15]), time is: 15353
Sensor value is: ok - Ok([15]), time is: 14505
Sensor value is: ok - Ok([15]), time is: 15005
Sensor value is: ok - Ok([15]), time is: 15438
Sensor value is: ok - Ok([15]), time is: 15151
Sensor value is: ok - Ok([15]), time is: 15628
Sensor value is: ok - Ok([15]), time is: 15421
Sensor value is: ok - Ok([15]), time is: 15666
Sensor value is: ok - Ok([15]), time is: 14693
Sensor value is: ok - Ok([15]), time is: 15739
The text was updated successfully, but these errors were encountered:
I think that serial port in windows wait some timeout or when buffer will be full. But i don't know how to fix it.
I'm control with oscilloscope that device response immediately (about 1 ms)
OS - Windows
Code:
Output:
Reading a sensor value
Sensor value is: ok - Ok([15]), time is: 15353
Sensor value is: ok - Ok([15]), time is: 14505
Sensor value is: ok - Ok([15]), time is: 15005
Sensor value is: ok - Ok([15]), time is: 15438
Sensor value is: ok - Ok([15]), time is: 15151
Sensor value is: ok - Ok([15]), time is: 15628
Sensor value is: ok - Ok([15]), time is: 15421
Sensor value is: ok - Ok([15]), time is: 15666
Sensor value is: ok - Ok([15]), time is: 14693
Sensor value is: ok - Ok([15]), time is: 15739
The text was updated successfully, but these errors were encountered: