GithubHelp home page GithubHelp logo

Comments (12)

ShayBox avatar ShayBox commented on June 16, 2024

This appears to be caused by this https://github.com/tokio-rs/tokio/blame/master/tokio/src/lib.rs#L536-L541

from tokio-modbus.

flosse avatar flosse commented on June 16, 2024

... so it's not related to tokio-modbus, right?

from tokio-modbus.

ShayBox avatar ShayBox commented on June 16, 2024

This is related to tokio-modbus, the error comes from it trying to access the runtime tokio module without the cfg_rt! (I don't know what that macro expands to, likely a cfg feature flag?)

from tokio-modbus.

flosse avatar flosse commented on June 16, 2024

hm... I tried to compile some examples and could not reproduce this error. Could you provide some more info to reproduce it?

from tokio-modbus.

ShayBox avatar ShayBox commented on June 16, 2024

Cargo.toml

[package]
name = "test"
version = "0.0.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio-modbus = { version = "0.8.0", default-features = false, features = ["rtu-sync"] }
tokio-serial = "5.4.4"

src/main.rs examples/rtu-client-sync.rs

// SPDX-FileCopyrightText: Copyright (c) 2017-2023 slowtec GmbH <[email protected]>
// SPDX-License-Identifier: MIT OR Apache-2.0

//! Synchronous RTU client example

fn main() -> Result<(), Box<dyn std::error::Error>> {
    use tokio_modbus::prelude::*;

    let tty_path = "/dev/ttyUSB0";
    let slave = Slave(0x17);

    let builder = tokio_serial::new(tty_path, 19200);

    let mut ctx = sync::rtu::connect_slave(&builder, slave)?;
    println!("Reading a sensor value");
    let rsp = ctx.read_holding_registers(0x082B, 2)?;
    println!("Sensor value is: {rsp:?}");

    Ok(())
}

from tokio-modbus.

ShayBox avatar ShayBox commented on June 16, 2024

It appears to be because of default-features = false, it's been a while since I touched my project and I just updated it, but this comment implies it's still an intended use-case, probably one of the optional dependencies from a different feature is explicitly required.

from tokio-modbus.

flosse avatar flosse commented on June 16, 2024

I'm so sorry, I'm still not able to produce the error, even if I disable the default features 🤔
This is what works fine on my machine:

cargo check --no-default-features --features rtu-sync --example rtu-client-sync

from tokio-modbus.

ShayBox avatar ShayBox commented on June 16, 2024

Yes that command works if I clone tokio-modbus and run it within, this only happens in a new project with tokio-modbus as a dependency

from tokio-modbus.

ShayBox avatar ShayBox commented on June 16, 2024

Here's my test project if you like, it's just the above two files Test.zip
$ cargo build

from tokio-modbus.

flosse avatar flosse commented on June 16, 2024

I see...you're right!

from tokio-modbus.

flosse avatar flosse commented on June 16, 2024

Could you check if #192 solves the problem?

from tokio-modbus.

ShayBox avatar ShayBox commented on June 16, 2024

That does fix it 👍

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.