戳人痛处

导航

[记]RUST获取串口描述信息

1.

toml

serialport = "4.2.0"

---

fn main() {
    let ports = serialport::available_ports().expect("没有串口哦 by博客园:戳人痛处");
    
    println!("{:?}",ports);
    for p in ports {
        println!("{}", p.port_name);
        match p.port_type{
            serialport::SerialPortType::UsbPort(x)=>{println!("{}",x.product.unwrap())},
            _ =>{println!("没有描述信息哦 by博客园:戳人痛处")},
        }
    }
}

输出:

[SerialPortInfo { port_name: "COM41", port_type: UsbPort(UsbPortInfo { vid: 4292, pid: 60016, serial_number: None, manufacturer: Some("Silicon Labs"), product: Some("Silicon Labs Dual CP210x USB to UART Bridge: Enhanced COM Port (COM41)") }) }, SerialPortInfo { port_name: "COM38", port_type: UsbPort(UsbPortInfo { vid: 4292, pid: 60016, serial_number: None, manufacturer: Some("Silicon Labs"), product: Some("Silicon Labs Dual CP210x USB to UART Bridge: Standard COM Port (COM38)") }) }] by博客园:戳人痛处
COM41
Silicon Labs Dual CP210x USB to UART Bridge: Enhanced COM Port (COM41)
COM38
Silicon Labs Dual CP210x USB to UART Bridge: Standard COM Port (COM38)
View Code

 

posted on 2022-08-22 16:01  戳人痛处  阅读(357)  评论(0编辑  收藏  举报