1 |
62efcbc4
|
silhavyj
|
import usb.core
|
2 |
|
|
import usb.util
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
def read_connected_devices():
|
6 |
|
|
detected_devices = []
|
7 |
|
|
|
8 |
|
|
busses = usb.busses()
|
9 |
|
|
|
10 |
|
|
for bus in busses:
|
11 |
|
|
devices = bus.devices
|
12 |
|
|
for dev in devices:
|
13 |
0f94f9b0
|
Pultak
|
serial_number = None
|
14 |
|
|
device_info = usb.core.find(idProduct=dev.idProduct)
|
15 |
5c67f214
|
Pultak
|
try:
|
16 |
0f94f9b0
|
Pultak
|
serial_number = usb.util.get_string(device_info, device_info.iSerialNumber)
|
17 |
|
|
except:
|
18 |
|
|
# Failed to retrieve information from device
|
19 |
|
|
pass
|
20 |
|
|
|
21 |
|
|
if serial_number is not None:
|
22 |
5c67f214
|
Pultak
|
detected_devices.append({
|
23 |
|
|
"vendor_id": dev.idVendor,
|
24 |
|
|
"product_id": dev.idProduct,
|
25 |
0f94f9b0
|
Pultak
|
"serial_number": serial_number
|
26 |
5c67f214
|
Pultak
|
})
|
27 |
62efcbc4
|
silhavyj
|
|
28 |
|
|
return detected_devices
|