# Path: stoqdrivers/exceptions.py
# class USBDriverError(DriverError):
#     """A USB Error that was raised by StoqDrivers (and not pyusb)"""
# 
# Path: stoqdrivers/utils.py
# def str2bytes(text):
#     if isinstance(text, bytes):
#         return text
#     return bytes(ord(i) for i in text)


    import usb.core
    import usb.util
from stoqdrivers.exceptions import USBDriverError
from stoqdrivers.utils import str2bytes
            check_driver = self.device.is_kernel_driver_active(0)
        except NotImplementedError:
            check_driver = False

        if check_driver is None or check_driver:
            try:
                self.device.detach_kernel_driver(0)
            except usb.core.USBError as e:
                if check_driver is not None:
                    print(("Could not detatch kernel driver: {0}".format(str(e))))

        # This was required at some point, but stopped working. Is this really necessary? Are we
        # doing something wrong?
        #self.device.set_configuration()
        self.device.reset()

    def close(self):
        """Release the USB interface"""
        if self.device:
            usb.util.dispose_resources(self.device)
        self.device = None

    def write(self, data):
        """Write any data to the USB printer

        :param data: Any data to be written
        :type data: bytes
        """
        if not self.device:
            self.open()

# Path: stoqdrivers/exceptions.py
# class USBDriverError(DriverError):
#     """A USB Error that was raised by StoqDrivers (and not pyusb)"""
# 
# Path: stoqdrivers/utils.py
# def str2bytes(text):
#     if isinstance(text, bytes):
#         return text
#     return bytes(ord(i) for i in text)


# Path: stoqdrivers/usbbase.py
    import usb.core
    import usb.util
from stoqdrivers.exceptions import USBDriverError
from stoqdrivers.utils import str2bytes

            check_driver = self.device.is_kernel_driver_active(0)
        except NotImplementedError:
            check_driver = False

        if check_driver is None or check_driver:
            try:
                self.device.detach_kernel_driver(0)
            except usb.core.USBError as e:
                if check_driver is not None:
                    print(("Could not detatch kernel driver: {0}".format(str(e))))

        # This was required at some point, but stopped working. Is this really necessary? Are we
        # doing something wrong?
        #self.device.set_configuration()
        self.device.reset()

    def close(self):
        """Release the USB interface"""
        if self.device:
            usb.util.dispose_resources(self.device)
        self.device = None

    def write(self, data):
        """Write any data to the USB printer

        :param data: Any data to be written
        :type data: bytes
        """
        if not self.device:
            self.open()

        self.device.write(self.out_ep, str2bytes(data), self.timeout)