-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathwindows.rs
More file actions
38 lines (35 loc) · 1.25 KB
/
Copy pathwindows.rs
File metadata and controls
38 lines (35 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use crate::RustSerialPortInfo;
use serialport::{available_ports, SerialPortType};
pub fn list_serial_ports() -> Result<Vec<RustSerialPortInfo>, String> {
let ports = available_ports().map_err(|e| e.to_string())?;
Ok(ports
.into_iter()
.map(|port| {
let (vid, pid, serial_number, manufacturer, product, interface_num) =
match port.port_type {
SerialPortType::UsbPort(info) => (
Some(info.vid),
Some(info.pid),
info.serial_number,
info.manufacturer,
info.product,
info.interface,
),
SerialPortType::PciPort
| SerialPortType::BluetoothPort
| SerialPortType::Unknown => (None, None, None, None, None, None),
};
RustSerialPortInfo {
device: port.port_name,
vid,
pid,
serial_number,
manufacturer,
product,
bcd_device: None,
interface_description: None,
interface_num,
}
})
.collect())
}