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 · 1 comment
Open

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

ZaytsveDmitriy opened this issue Nov 5, 2024 · 1 comment
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
@thalesmaoanz
Copy link

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.

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

3 participants