Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get cycle time les then ~ 15 ms in Modbus RTU #297

Open
ZaytsveDmitriy opened this issue Nov 5, 2024 · 0 comments
Open

Can't get cycle time les then ~ 15 ms in Modbus RTU #297

ZaytsveDmitriy opened this issue Nov 5, 2024 · 0 comments
Labels

Comments

@ZaytsveDmitriy
Copy link

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

@flosse flosse added the rtu label Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants