pub struct PortInfo { /* private fields */ }
Expand description
Information on a listed serial port
Implementations§
Source§impl PortInfo
impl PortInfo
Sourcepub fn get_port(&self) -> &str
pub fn get_port(&self) -> &str
Gets port name
Examples found in repository?
examples/port_list.rs (line 29)
11fn main() {
12
13 #[cfg(windows)]
14 {
15 let mut scanner = port_lister::COMPortLister{};
16 for port in scanner.list_devices().unwrap() {
17 println!("Found port:");
18 println!("\tPort: {}", port.get_port());
19 println!("\tDescription: {}", port.get_desc());
20 println!("\tManufacturer: {}", port.get_manufacturer());
21 }
22 }
23
24 #[cfg(unix)]
25 {
26 let mut scanner = port_lister::TTYPortScanner{};
27 for port in scanner.list_devices().unwrap() {
28 println!("Found port:");
29 println!("\tPort: {}", port.get_port());
30 println!("\tDescription: {}", port.get_desc());
31 println!("\tManufacturer: {}", port.get_manufacturer());
32 }
33 }
34
35 #[cfg(windows)]
36 let p = COMPort::new("COM7".into(), Some(
37 SerialPortSettings::default()
38 .baud(115200)
39 .read_timeout(Some(100))
40 .write_timeout(Some(100))
41 .set_flow_control(FlowControl::None)
42 ));
43 #[cfg(unix)]
44 let p = TTYPort::new("/dev/ttyUSB0".into(), Some(
45 SerialPortSettings::default()
46 .baud(115200)
47 .read_timeout(Some(100))
48 .write_timeout(Some(100))
49 .set_flow_control(FlowControl::None)
50 ));
51 match p {
52 Ok(mut port) => {
53 let clone_r = port.try_clone().unwrap();
54 let mut clone_w = port.try_clone().unwrap();
55 println!("Port open OK!");
56 let test_msg: &[u8] = "#07E11092\n".as_bytes();
57 let mut buf_reader = BufReader::new(clone_r);
58 let mut b = String::new();
59 loop {
60 if buf_reader.read_line(&mut b).is_ok() {
61 print!("IN : {}", b);
62 b.clear();
63 println!("OUT: {:02X?}", test_msg);
64 if let Err(e) = clone_w.write(test_msg) {
65 eprintln!("Write error {}", e)
66 }
67 } else {
68 std::thread::sleep(std::time::Duration::from_millis(50));
69 }
70 }
71 },
72 Err(e) => {
73 eprintln!("Cannot open com port {}", e)
74 }
75 }
76}
Sourcepub fn get_manufacturer(&self) -> &str
pub fn get_manufacturer(&self) -> &str
Gets port devices’ manufacturer
Examples found in repository?
examples/port_list.rs (line 31)
11fn main() {
12
13 #[cfg(windows)]
14 {
15 let mut scanner = port_lister::COMPortLister{};
16 for port in scanner.list_devices().unwrap() {
17 println!("Found port:");
18 println!("\tPort: {}", port.get_port());
19 println!("\tDescription: {}", port.get_desc());
20 println!("\tManufacturer: {}", port.get_manufacturer());
21 }
22 }
23
24 #[cfg(unix)]
25 {
26 let mut scanner = port_lister::TTYPortScanner{};
27 for port in scanner.list_devices().unwrap() {
28 println!("Found port:");
29 println!("\tPort: {}", port.get_port());
30 println!("\tDescription: {}", port.get_desc());
31 println!("\tManufacturer: {}", port.get_manufacturer());
32 }
33 }
34
35 #[cfg(windows)]
36 let p = COMPort::new("COM7".into(), Some(
37 SerialPortSettings::default()
38 .baud(115200)
39 .read_timeout(Some(100))
40 .write_timeout(Some(100))
41 .set_flow_control(FlowControl::None)
42 ));
43 #[cfg(unix)]
44 let p = TTYPort::new("/dev/ttyUSB0".into(), Some(
45 SerialPortSettings::default()
46 .baud(115200)
47 .read_timeout(Some(100))
48 .write_timeout(Some(100))
49 .set_flow_control(FlowControl::None)
50 ));
51 match p {
52 Ok(mut port) => {
53 let clone_r = port.try_clone().unwrap();
54 let mut clone_w = port.try_clone().unwrap();
55 println!("Port open OK!");
56 let test_msg: &[u8] = "#07E11092\n".as_bytes();
57 let mut buf_reader = BufReader::new(clone_r);
58 let mut b = String::new();
59 loop {
60 if buf_reader.read_line(&mut b).is_ok() {
61 print!("IN : {}", b);
62 b.clear();
63 println!("OUT: {:02X?}", test_msg);
64 if let Err(e) = clone_w.write(test_msg) {
65 eprintln!("Write error {}", e)
66 }
67 } else {
68 std::thread::sleep(std::time::Duration::from_millis(50));
69 }
70 }
71 },
72 Err(e) => {
73 eprintln!("Cannot open com port {}", e)
74 }
75 }
76}
Sourcepub fn get_desc(&self) -> &str
pub fn get_desc(&self) -> &str
Gets port devices’ description
Examples found in repository?
examples/port_list.rs (line 30)
11fn main() {
12
13 #[cfg(windows)]
14 {
15 let mut scanner = port_lister::COMPortLister{};
16 for port in scanner.list_devices().unwrap() {
17 println!("Found port:");
18 println!("\tPort: {}", port.get_port());
19 println!("\tDescription: {}", port.get_desc());
20 println!("\tManufacturer: {}", port.get_manufacturer());
21 }
22 }
23
24 #[cfg(unix)]
25 {
26 let mut scanner = port_lister::TTYPortScanner{};
27 for port in scanner.list_devices().unwrap() {
28 println!("Found port:");
29 println!("\tPort: {}", port.get_port());
30 println!("\tDescription: {}", port.get_desc());
31 println!("\tManufacturer: {}", port.get_manufacturer());
32 }
33 }
34
35 #[cfg(windows)]
36 let p = COMPort::new("COM7".into(), Some(
37 SerialPortSettings::default()
38 .baud(115200)
39 .read_timeout(Some(100))
40 .write_timeout(Some(100))
41 .set_flow_control(FlowControl::None)
42 ));
43 #[cfg(unix)]
44 let p = TTYPort::new("/dev/ttyUSB0".into(), Some(
45 SerialPortSettings::default()
46 .baud(115200)
47 .read_timeout(Some(100))
48 .write_timeout(Some(100))
49 .set_flow_control(FlowControl::None)
50 ));
51 match p {
52 Ok(mut port) => {
53 let clone_r = port.try_clone().unwrap();
54 let mut clone_w = port.try_clone().unwrap();
55 println!("Port open OK!");
56 let test_msg: &[u8] = "#07E11092\n".as_bytes();
57 let mut buf_reader = BufReader::new(clone_r);
58 let mut b = String::new();
59 loop {
60 if buf_reader.read_line(&mut b).is_ok() {
61 print!("IN : {}", b);
62 b.clear();
63 println!("OUT: {:02X?}", test_msg);
64 if let Err(e) = clone_w.write(test_msg) {
65 eprintln!("Write error {}", e)
66 }
67 } else {
68 std::thread::sleep(std::time::Duration::from_millis(50));
69 }
70 }
71 },
72 Err(e) => {
73 eprintln!("Cannot open com port {}", e)
74 }
75 }
76}
Trait Implementations§
Source§impl Ord for PortInfo
impl Ord for PortInfo
Source§impl PartialOrd for PortInfo
impl PartialOrd for PortInfo
impl Eq for PortInfo
impl StructuralPartialEq for PortInfo
Auto Trait Implementations§
impl Freeze for PortInfo
impl RefUnwindSafe for PortInfo
impl Send for PortInfo
impl Sync for PortInfo
impl Unpin for PortInfo
impl UnwindSafe for PortInfo
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more