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

rtu non-functional when used #1

Closed
kallisti5 opened this issue Feb 21, 2018 · 2 comments
Closed

rtu non-functional when used #1

kallisti5 opened this issue Feb 21, 2018 · 2 comments

Comments

@kallisti5
Copy link

main.rs

extern crate futures;
extern crate tokio_core;
extern crate tokio_modbus;
extern crate tokio_serial;
extern crate tokio_service;
use tokio_modbus::*;

pub fn main() {
    use tokio_core::reactor::Core;
    use futures::future::Future;
    use tokio_serial::{BaudRate, Serial, SerialPortSettings};

    let mut core = Core::new().unwrap();
    let handle = core.handle();
    let tty_path = "/dev/ttyUSB0";
    let server_addr = 0x01;

    let mut settings = SerialPortSettings::default();
    settings.baud_rate = BaudRate::Baud19200;
    let mut port = Serial::from_path(tty_path, &settings, &handle)
        .expect(&format!("Unable to open serial device '{}'", tty_path));
    port.set_exclusive(false)
        .expect("Unable to set serial port exlusive");

    let task = Client::connect_rtu(port, server_addr, &handle).and_then(|client| {
        println!("Reading a sensor value");
        client
            .read_holding_registers(0x082B, 2)
            .and_then(move |res| {
                println!("Sensor value is: {:?}", res);
                Ok(())
            })
    });

    core.run(task).unwrap();
}

Cargo.toml

[dependencies]
futures = "*"
tokio = "*"
tokio-core = "*"
tokio-serial = "*"
tokio-service = "*"
tokio-modbus = { version = "*", default-features = false, features = ["rtu"] }

Results

error[E0599]: no function or associated item named `connect_rtu` found for type `tokio_modbus::Client` in the current scope
  --> src/main.rs:25:16
   |
25 |     let task = Client::connect_rtu(port, server_addr, &handle).and_then(|client| {
   |                ^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error
@flosse
Copy link
Member

flosse commented Feb 21, 2018

It looks like you are using tokio_modbus v0.1.0 that has a different API.
The current master branch should lead to v0.2.0 but first these issues should be closed:

So in your case you can either use the v0.1.0 API (example) or point the tokio-modbus dependency to the git repo:

[dependencies.tokio-modbus]
version = "*"
git = "https://github.com/slowtec/tokio-modbus"
default-features = false
features = ["rtu"]

@flosse
Copy link
Member

flosse commented Mar 30, 2018

I just published v0.2.0 so you can use it as usual :)

@flosse flosse closed this as completed Mar 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants