diff --git a/src/main.rs b/src/main.rs index 97b3fb9e5177c58f6710a2a72546d7e62ce94c32..07835cdfef127b41d6e5ff5fd139045c5e36c53f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use serial::prelude::*; fn main() { - let device = String::from("/dev/cu.usbmodem1411"); + let device = String::from("/dev/cu.usbmodem41"); let mut port = serial::open(&device).unwrap(); interact(&mut port).unwrap(); @@ -29,19 +29,37 @@ fn interact<T: SerialPort>(port: &mut T) -> io::Result<()> { //let mut buf: Vec<u8> = (0..255).collect(); - let mut buf: [u8; 255] = [0; 255]; + let mut buf: [u8; 8] = [0; 8]; let mut count: usize = 0; + loop { + match port.read_exact(&mut buf){ + Ok(_) => { + print!("A: {}, ", ((buf[0] as u32) << 24) + ((buf[1] as u32) << 16) + ((buf[2] as u32) << 8) + (buf[3] as u32)); + println!("B: {}", ((buf[4] as u32) << 24) + ((buf[5] as u32) << 16) + ((buf[6] as u32) << 8) + (buf[7] as u32)); + }, + Err(e) => { + println!("Could not read all bytes: {:?}", e); + break; + }, + } + } + for c in port.bytes() { match c { Ok(c) => { buf[count] = c; count+=1; - if c as char == '\n' { - for i in 0..count { - print!("{}", buf[i] as char); - } + if count == 8 { + + print!("A: {}, ", ((buf[0] as u32) << 24) + ((buf[1] as u32) << 16) + ((buf[2] as u32) << 8) + (buf[3] as u32)); + println!("B: {}", ((buf[4] as u32) << 24) + ((buf[5] as u32) << 16) + ((buf[6] as u32) << 8) + (buf[7] as u32)); + + //for i in 0..count { + // print!("{} ", buf[i]); + //} count = 0; + //println!(); } }, Err(e) => println!("{:?}", e),