Skip to content

Instantly share code, notes, and snippets.

@zzeroo
Created May 25, 2020 14:21
Show Gist options
  • Save zzeroo/b89a0c7e4d3de4d834faf8cd7ebaa345 to your computer and use it in GitHub Desktop.
Save zzeroo/b89a0c7e4d3de4d834faf8cd7ebaa345 to your computer and use it in GitHub Desktop.

Revisions

  1. zzeroo created this gist May 25, 2020.
    19 changes: 19 additions & 0 deletions runtime_return_value.rs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    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!(".");
    Ok(())
    })
    })
    .join()
    .unwrap();
    }