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:
Hi @ZaytsveDmitriy , I've faced a lot of similar problems in the past. After some time, I did a deep research over modbus buses. Since it is a broadcast message, some periods, like mute, reply and so on are standardized. Take a look! You will not be able to increase those values.
Other important point is baud rate. We have this feeling that increase the baud rate will increase the overall communication speed, but you will notice that this is not always true. In my experience, over 9600 the improve is barely noted.
Last, but not least, I've already faced a bunch of devices with greater mute time. In other to improve the communication, I needed to manually tweak the times.
In my opinion, if you need to make a DAQ, don't use modbus.
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: