Read from hardcoded serial port
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
commit
a1dcd606d9
7 changed files with 303 additions and 0 deletions
34
src/main.rs
Normal file
34
src/main.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
use std::{
|
||||
io::{self, Write},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
let port_name = "/dev/serial0";
|
||||
let baud_rate = 9600;
|
||||
|
||||
let port = serialport::new(port_name, baud_rate)
|
||||
.timeout(Duration::from_millis(100))
|
||||
.open();
|
||||
|
||||
match port {
|
||||
Ok(mut port) => {
|
||||
let mut serial_buf: Vec<u8> = vec![0; 1000];
|
||||
println!("Receiving data on {} at {} baud:", &port_name, &baud_rate);
|
||||
loop {
|
||||
match port.read(serial_buf.as_mut_slice()) {
|
||||
Ok(t) => io::stdout().write_all(&serial_buf[..t]).unwrap(),
|
||||
Err(ref e) if e.kind() == io::ErrorKind::TimedOut => (),
|
||||
Err(e) => {
|
||||
eprintln!("Failed to read \"{}\". Error: {}", port_name, e);
|
||||
::std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Failed to open \"{}\". Error: {}", port_name, e);
|
||||
::std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue