Git Product home page Git Product logo

Comments (6)

uklotzde avatar uklotzde commented on August 17, 2024

You need to enable the required features manually: rust-lang/cargo#4663

cargo run --example tcp-client-sync --features tcp-sync

from tokio-modbus.

gxcora avatar gxcora commented on August 17, 2024

I did that, and it returns error: none of the selected packages contains these features: tcp-sync
To confirm, I have [dependencies] tokio-modbus = "*" in the toml file

from tokio-modbus.

uklotzde avatar uklotzde commented on August 17, 2024

I tested it on the main branch and it works.

from tokio-modbus.

uklotzde avatar uklotzde commented on August 17, 2024

I don't know anything about your private project. But it looks like you forgot to add the feature to the dependency.

from tokio-modbus.

gxcora avatar gxcora commented on August 17, 2024

Thanks Uwe. That was my bad. I got it to build ok. I changed the example like this

fn main() {
    use tokio_modbus::prelude::*;

    let socket_addr = "10.2.16.171:502".parse().unwrap();
    let mut ctx = sync::tcp::connect(socket_addr).unwrap();
    let buff = ctx.read_input_registers(3, 1).unwrap();
    println!("Response is '{buff:?}'");
}

And it returns

    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `../tokio-modbus/target/debug/examples/tcp-client-sync`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Custom { kind: Other, error: ExceptionResponse { function: 4, exception: IllegalDataAddress } }', examples/tcp-client-sync.rs:11:47
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Yet mbpoll is able to see the data:

mbpoll -m tcp -a 1 -t 4 -r 3 -c 1 -1 10.2.16.171
......

Protocol configuration: Modbus TCP
Slave configuration...: address = [1]
                        start reference = 3, count = 1
Communication.........: 10.2.16.171, port 502, t/o 1.00 s, poll rate 1000 ms
Data type.............: 16-bit register, output (holding) register table

-- Polling slave 1...
[3]: 	2

Any ideas?

from tokio-modbus.

uklotzde avatar uklotzde commented on August 17, 2024

Check the tokio-modbus docs about 0/1-based addressing.

from tokio-modbus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.