(vendor_id=None, product_id=None)
return devices
Discovers USB serial device(s) connected to the machine matching the input
    arguments. If no arguments are given or both are None, returns all devices
    found.

    vendor_id -- the USB vendor id to match.
    product_id -- the USB product id to match.

    Returns a list of USBDeviceInfo objects matching the criteria given.
Discovers USB serial device(s) connected to the machine matching the input
    arguments. If no arguments are given or both are None, returns all devices
    found.
Discovers USB serial device ( s ) connected to the machine matching the input arguments . If no arguments are given or both are None returns all devices found .
def find_usb_serial_devices(vendor_id=None, product_id=None):
    """
    Discovers USB serial device(s) connected to the machine matching the input
    arguments. If no arguments are given or both are None, returns all devices
    found.

    vendor_id -- the USB vendor id to match.
    product_id -- the USB product id to match.

    Returns a list of USBDeviceInfo objects matching the criteria given.
    """
    devices = []
    raw_devices = list(serial.tools.list_ports.comports())
    log.debug("Found %d serial USB devices", len(raw_devices))
    for device in raw_devices:
        log.debug("Checking serial USB device: %s", device)
        dev = USBSerialDeviceInfo()
        dev.port_name = device[0]
        dev.device_name = device[1]
        found_device = extract_vid_pid(device[2])
        if found_device is not None:
            dev.vendor_id, dev.product_id = found_device
            if vendor_id is None and product_id is None:
                devices.append(dev)
            elif dev.vendor_id == vendor_id and product_id is None:
                devices.append(dev)
            elif dev.product_id == product_id and vendor_id is None:
                devices.append(dev)
            elif dev.product_id == product_id and dev.vendor_id == vendor_id:
                devices.append(dev)
            log.debug("USB device: %s", dev)
    return devices
def find_usb_serial_devices ( vendor_id = None , product_id = None ) : devices = [ ] raw_devices = list ( serial . tools . list_ports . comports ( ) ) log . debug ( "Found %d serial USB devices" , len ( raw_devices ) ) for device in raw_devices : log . debug ( "Checking serial USB device: %s" , device ) dev = USBSerialDeviceInfo ( ) dev . port_name = device [ 0 ] dev . device_name = device [ 1 ] found_device = extract_vid_pid ( device [ 2 ] ) if found_device is not None : dev . vendor_id , dev . product_id = found_device if vendor_id is None and product_id is None : devices . append ( dev ) elif dev . vendor_id == vendor_id and product_id is None : devices . append ( dev ) elif dev . product_id == product_id and vendor_id is None : devices . append ( dev ) elif dev . product_id == product_id and dev . vendor_id == vendor_id : devices . append ( dev ) log . debug ( "USB device: %s" , dev ) return devices