From 024e6e07eb62dd7814386a64a4a2f44465cc2773 Mon Sep 17 00:00:00 2001 From: soiamsoNG <83182235@qq.com> Date: Thu, 28 Mar 2024 12:35:48 +0000 Subject: [PATCH] Try find port type in parent device --- src/posix/enumerate.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/posix/enumerate.rs b/src/posix/enumerate.rs index 455a484c..76f17148 100644 --- a/src/posix/enumerate.rs +++ b/src/posix/enumerate.rs @@ -174,6 +174,24 @@ fn port_type(d: &libudev::Device) -> Result { Ok(SerialPortType::PciPort) } } + None => { + let p = d.parent().unwrap(); + let parent_driver = p.driver().unwrap().to_str().unwrap(); + let parent_subsystem = p.subsystem().unwrap().to_str().unwrap(); + + if parent_driver == "cdc_acm" && parent_subsystem == "usb" { + let product_code = p.property_value("PRODUCT").and_then(OsStr::to_str).unwrap(); + Ok(SerialPortType::UsbPort(UsbPortInfo { + vid: u16::from_str_radix(&product_code[0..4], 16).unwrap(), + pid: u16::from_str_radix(&product_code[5..9], 16).unwrap(), + serial_number: None, + manufacturer: None, + product: None, + })) + } else { + Ok(SerialPortType::Unknown) + } + } _ => Ok(SerialPortType::Unknown), } }