File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -261,6 +261,26 @@ impl PortDevice {
261261 }
262262 }
263263
264+ /// Retrieves the problem status of this device. For example, `CM_PROB_DISABLED` indicates
265+ /// the device has been disabled in Device Manager.
266+ fn problem ( & mut self ) -> Option < ULONG > {
267+ let mut status = 0 ;
268+ let mut problem_number = 0 ;
269+ let res = unsafe {
270+ CM_Get_DevNode_Status (
271+ & mut status,
272+ & mut problem_number,
273+ self . devinfo_data . DevInst ,
274+ 0 ,
275+ )
276+ } ;
277+ if res == CR_SUCCESS {
278+ Some ( problem_number)
279+ } else {
280+ None
281+ }
282+ }
283+
264284 // Retrieves the port name (i.e. COM6) associated with this device.
265285 pub fn name ( & mut self ) -> String {
266286 let hkey = unsafe {
@@ -348,6 +368,11 @@ pub fn available_ports() -> Result<Vec<SerialPortInfo>> {
348368 for guid in get_ports_guids ( ) ? {
349369 let port_devices = PortDevices :: new ( & guid) ;
350370 for mut port_device in port_devices {
371+ // Ignore nonfunctional devices
372+ if port_device. problem ( ) != Some ( 0 ) {
373+ continue ;
374+ }
375+
351376 let port_name = port_device. name ( ) ;
352377
353378 debug_assert ! (
You can’t perform that action at this time.
0 commit comments