Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add posix example #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
authors = ["Ashcon Mohseninia <[email protected]>"]
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

Expand Down
35 changes: 35 additions & 0 deletions examples/port_list_posix.rs
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
File renamed without changes.