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
标签:Silicon,CP210x,USB,Port,Labs,获取,串口,port,RUST From: https://www.cnblogs.com/hardfood/p/16613131.html