use std::io::{Read, Write}; use std::time::Duration; fn main() { let mut port = serialport::new("/dev/cu.usbmodem00000021", 115200) .data_bits(serialport::DataBits::Eight) .flow_control(serialport::FlowControl::None) .parity(serialport::Parity::None) .stop_bits(serialport::StopBits::One) .timeout(Duration::from_millis(5000)) .open() .expect("Failed to open"); port.write_all(b"AT\r").unwrap(); port.flush().unwrap(); std::thread::sleep(Duration::from_millis(500)); let mut buf = vec![0u8; 1024]; match port.read(&mut buf) { Ok(n) => println!("AT response: {:?}", String::from_utf8_lossy(&buf[..n])), Err(e) => println!("Error: {}", e), } port.write_all(b"AT+FTH=?\r").unwrap(); port.flush().unwrap(); std::thread::sleep(Duration::from_millis(1000)); let mut buf = vec![0u8; 1024]; match port.read(&mut buf) { Ok(n) => println!("AT+FTH=? response: {:?}", String::from_utf8_lossy(&buf[..n])), Err(e) => println!("Error: {}", e), } port.write_all(b"AT+FTM=?\r").unwrap(); port.flush().unwrap(); std::thread::sleep(Duration::from_millis(1000)); let mut buf = vec![0u8; 1024]; match port.read(&mut buf) { Ok(n) => println!("AT+FTM=? response: {:?}", String::from_utf8_lossy(&buf[..n])), Err(e) => println!("Error: {}", e), } }