Projekt

Obecné

Profil

Stáhnout (689 Bajtů) Statistiky
| Větev: | Tag: | Revize:
1 5c67f214 Pultak
import logging
2
3 62efcbc4 silhavyj
import usb.core
4
import usb.util
5
6
7
def read_connected_devices():
8
    detected_devices = []
9
10
    busses = usb.busses()
11
12
    for bus in busses:
13
        devices = bus.devices
14
        for dev in devices:
15 5c67f214 Pultak
            try:
16
                device_info = usb.core.find(idProduct=dev.idProduct)
17
                detected_devices.append({
18
                    "vendor_id": dev.idVendor,
19
                    "product_id": dev.idProduct,
20
                    "serial_number": usb.util.get_string(device_info, device_info.iSerialNumber)
21
                })
22
            except:
23
                logging.warning(f"Failed to retrieve information from device {dev}")
24 62efcbc4 silhavyj
25
    return detected_devices