File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -49,11 +49,13 @@ def find_serial_devices(serial_matcher: str = "") -> List[str]:
49
49
:param serial_matcher:
50
50
only device IDs starting with this string are returned
51
51
"""
52
- objWMIService = win32com .client .Dispatch ("WbemScripting.SWbemLocator" )
53
- objSWbemServices = objWMIService .ConnectServer ("." , "root\\ cimv2" )
54
- query = "SELECT * FROM CIM_LogicalDevice where Name LIKE '%USB2CAN%'"
55
- devices = objSWbemServices .ExecQuery (query )
56
- serial_numbers = [device .DeviceID .split ("\\ " )[- 1 ] for device in devices ]
52
+ serial_numbers = []
53
+ wmi = win32com .client .GetObject ("winmgmts:" )
54
+ for usb_controller in wmi .InstancesOf ("Win32_USBControllerDevice" ):
55
+ usb_device = wmi .Get (usb_controller .Dependent )
56
+ if "USB2CAN" in usb_device .Name :
57
+ serial_numbers .append (usb_device .DeviceID .split ("\\ " )[- 1 ])
58
+
57
59
if serial_matcher :
58
60
return [sn for sn in serial_numbers if serial_matcher in sn ]
59
61
return serial_numbers
You can’t perform that action at this time.
0 commit comments