Skip to content

Commit 024e6e0

Browse files
committed
Try find port type in parent device
1 parent 361664b commit 024e6e0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/posix/enumerate.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,24 @@ fn port_type(d: &libudev::Device) -> Result<SerialPortType> {
174174
Ok(SerialPortType::PciPort)
175175
}
176176
}
177+
None => {
178+
let p = d.parent().unwrap();
179+
let parent_driver = p.driver().unwrap().to_str().unwrap();
180+
let parent_subsystem = p.subsystem().unwrap().to_str().unwrap();
181+
182+
if parent_driver == "cdc_acm" && parent_subsystem == "usb" {
183+
let product_code = p.property_value("PRODUCT").and_then(OsStr::to_str).unwrap();
184+
Ok(SerialPortType::UsbPort(UsbPortInfo {
185+
vid: u16::from_str_radix(&product_code[0..4], 16).unwrap(),
186+
pid: u16::from_str_radix(&product_code[5..9], 16).unwrap(),
187+
serial_number: None,
188+
manufacturer: None,
189+
product: None,
190+
}))
191+
} else {
192+
Ok(SerialPortType::Unknown)
193+
}
194+
}
177195
_ => Ok(SerialPortType::Unknown),
178196
}
179197
}

0 commit comments

Comments
 (0)