'Search device on USB tree and set is as escpos device'

def open(self):

    self.device = usb.core.find(idVendor=self.idVendor, idProduct=self.idProduct)
    if (self.device is None):
        raise NoDeviceError()
    try:
        if self.device.is_kernel_driver_active(self.interface):
            self.device.detach_kernel_driver(self.interface)
        self.device.set_configuration()
        usb.util.claim_interface(self.device, self.interface)
        cfg = self.device.get_active_configuration()
        intf = cfg[(0, 0)]
        if (self.in_ep is None):
            try:
                is_IN = (lambda e: (usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_IN))
                is_OUT = (lambda e: (usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_OUT))
                endpoint_in = usb.util.find_descriptor(intf, custom_match=is_IN)
                endpoint_out = usb.util.find_descriptor(intf, custom_match=is_OUT)
                self.in_ep = endpoint_in.bEndpointAddress
                self.out_ep = endpoint_out.bEndpointAddress
            except usb.core.USBError:
                self.in_ep = 130
                self.out_ep = 1
    except usb.core.USBError as e:
        raise HandleDeviceError(e)
