def __init__(self, vendor=None, product=None, serial_number=None, device_filters=None, timeout=None, **kwargs):
    super(USBRaw, self).__init__()
    self.timeout = timeout
    device_filters = (device_filters or {})
    devices = list(self.find_devices(vendor, product, serial_number, None, **device_filters))
    if (not devices):
        raise ValueError('No device found.')
    elif (len(devices) > 1):
        desc = '\n'.join((str(dev) for dev in devices))
        raise ValueError('{} devices found:\n{}\nPlease narrow the search criteria'.format(len(devices), desc))
    self.usb_dev = devices[0]
    try:
        if self.usb_dev.is_kernel_driver_active(0):
            self.usb_dev.detach_kernel_driver(0)
    except (usb.core.USBError, NotImplementedError) as e:
        pass
    try:
        self.usb_dev.set_configuration()
    except usb.core.USBError as e:
        raise Exception(('failed to set configuration\n %s' % e))
    try:
        self.usb_dev.set_interface_altsetting()
    except usb.core.USBError as e:
        pass
    self.usb_intf = self._find_interface(self.usb_dev, self.INTERFACE)
    (self.usb_recv_ep, self.usb_send_ep) = self._find_endpoints(self.usb_intf, self.ENDPOINTS)
def __init__(self, vendor=None, product=None, serial_number=None, device_filters=None, timeout=None, **kwargs):
    super(USBRaw, self).__init__()
    self.timeout = timeout
    device_filters = (device_filters or {})
    devices = list(self.find_devices(vendor, product, serial_number, None, **device_filters))
    if (not devices):
        raise ValueError('No device found.')
    elif (len(devices) > 1):
        desc = '\n'.join((str(dev) for dev in devices))
        raise ValueError('{} devices found:\n{}\nPlease narrow the search criteria'.format(len(devices), desc))
    self.usb_dev = devices[0]
    try:
        if self.usb_dev.is_kernel_driver_active(0):
            self.usb_dev.detach_kernel_driver(0)
    except (usb.core.USBError, NotImplementedError) as e:
        pass
    try:
        self.usb_dev.set_configuration()
    except usb.core.USBError as e:
        raise Exception(('failed to set configuration\n %s' % e))
    try:
        self.usb_dev.set_interface_altsetting()
    except usb.core.USBError as e:
        pass
    self.usb_intf = self._find_interface(self.usb_dev, self.INTERFACE)
    (self.usb_recv_ep, self.usb_send_ep) = self._find_endpoints(self.usb_intf, self.ENDPOINTS)