diff --git a/Cargo.toml b/Cargo.toml index 799b6b5..d35b14c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" authors = ["Ashcon Mohseninia "] description = "A cross-platform rust serial RS232 library" readme = "README.md" -repository = "https://github.com/rnd-ash/pyserial-rs" +repository = "https://github.com/rnd-ash/serial-rs" keywords = ["serial", "modem", "serialport", "rs232"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/examples/port_list_posix.rs b/examples/port_list_posix.rs new file mode 100755 index 0000000..ce15d60 --- /dev/null +++ b/examples/port_list_posix.rs @@ -0,0 +1,35 @@ +use std::io::{BufReader, BufRead}; + +use serial_rs::{posix::{port_lister, TTYPort}, PortScanner, SerialPortSettings}; + +fn main() { + let mut scanner = port_lister::TTYPortScanner{}; + for port in scanner.list_devices().unwrap() { + println!("Found port:"); + println!("\tPort: {}", port.get_port()); + println!("\tDescription: {}", port.get_desc()); + println!("\tManufacturer: {}", port.get_manufacturer()); + } + + match TTYPort::new("/dev/cu.Bluetooth-Incoming-Port".into(), Some( + SerialPortSettings::default() + .baud(115200) + .read_timeout(Some(100)) + )) { + Ok(mut port) => { + println!("Port open OK!"); + let mut buf_reader = BufReader::new(&mut port); + let mut b = String::new(); + loop { + if buf_reader.read_line(&mut b).is_ok() { + print!("{}", b); + b.clear(); + } + std::thread::sleep(std::time::Duration::from_millis(50)); + } + }, + Err(e) => { + eprintln!("Cannot open com port {}", e) + } + } +} diff --git a/examples/port_list.rs b/examples/port_list_windows.rs similarity index 100% rename from examples/port_list.rs rename to examples/port_list_windows.rs