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
Cannot run RTU client sync example #107
Comments
|
Maybe the example is outdated?
in the first line before main, so it will start the tokio runtime. Is it OK then? |
Thank you for this tip! I already tried this, but this still results in the same error message as shown in the description. My example looks like $ git diff examples/rtu-client-sync.rs
diff --git a/examples/rtu-client-sync.rs b/examples/rtu-client-sync.rs
index 5872f26..cf11c96 100644
--- a/examples/rtu-client-sync.rs
+++ b/examples/rtu-client-sync.rs
@@ -1,4 +1,5 @@
-pub fn main() -> Result<(), Box<dyn std::error::Error>> {
+#[tokio::main(flavor = "current_thread")]
+pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
use tokio_modbus::prelude::*;
let tty_path = "/dev/ttyUSB0"; and I was running it like shown in the description. I would have expected this to work as well. |
What is the "official" way for providing a runtime for this example? If it has to be done explicitly like in #107 (comment), I will create a PR for updating it. |
Did someone manage to run an example of reading modbus in synchronous mode? It doesn't work for me either, same error as described in the first post. The asynchronous read example works, but I need a synchronous one. |
I did manage as suggested in #107 (comment) |
This example doesn't work for me:
|
Have you brought into scope the correct Runtime object? Can you post your code? |
Here is my code:
|
I think you are missing tokio I have this in Cargo.toml: tokio-modbus = { version = "0.5.2", default-features = false, features = [
"rtu",
"sync",
] }
tokio-serial = "5.4.2"
tokio = { version = "1.17.0", features = ["rt-multi-thread"] } |
Yes you are right. I'm missing tokio |
#116 resolves this and the "vanilla" example works now out of the box. |
rtu-client-sync.rs
panics withcontext.rs:29
it looks like borrowing fromCONTEXT
fails and I bet there is some initialization missing. But this is my first contact with Tokio and I have no idea about the what, how, and why.The text was updated successfully, but these errors were encountered: