Skip to content

Instantly share code, notes, and snippets.

@zzeroo
Created May 25, 2020 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zzeroo/1b8e25eda202ce37b915b32a5c287fdd to your computer and use it in GitHub Desktop.
Save zzeroo/1b8e25eda202ce37b915b32a5c287fdd to your computer and use it in GitHub Desktop.
Where to put the type info?
use std::thread;
use tokio::runtime::Runtime;
use tokio_modbus::prelude::*;
use tokio_serial::Serial;
fn main() {
thread::spawn(|| {
let mut rt = Runtime::new().expect("Couldn't create Runtime");
rt.block_on(async {
let port = Serial::from_path("/dev/ttyUSB0", &Default::default()).unwrap();
let mut ctx = rtu::connect_slave(port, 247.into()).await?;
let data = ctx.read_input_registers(0, 10).await?;
println!("{:?}", data);
Ok(())
})
})
.join()
.unwrap();
}
@zzeroo
Copy link
Author

zzeroo commented May 25, 2020

This returns an error like this:

error[E0282]: type annotations needed
  --> src/main.rs:11:27
   |
9  |         rt.block_on(async {
   |            -------- help: consider specifying the type argument in the method call: `block_on::<F>`
10 |             let port = Serial::from_path("/dev/ttyUSB0", &Default::default()).unwrap();
11 |             let mut ctx = rtu::connect_slave(port, 247.into()).await?;
   |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment