From cd5969e843822e63473ac36a2e5570f634a17b85 Mon Sep 17 00:00:00 2001 From: Hark Date: Fri, 4 Sep 2015 22:48:58 +0100 Subject: [PATCH] Prevent crash when using libusb0 printers --- escpos/printer.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/escpos/printer.py b/escpos/printer.py index 738d7ca..3a3bc84 100644 --- a/escpos/printer.py +++ b/escpos/printer.py @@ -40,11 +40,19 @@ class Usb(Escpos): if self.device is None: print "Cable isn't plugged in" - if self.device.is_kernel_driver_active(0): + check_driver = None + + try: + check_driver = self.device.is_kernel_driver_active(0) + except NotImplementedError: + pass + + if check_driver is None or check_driver: try: self.device.detach_kernel_driver(0) except usb.core.USBError as e: - print "Could not detatch kernel driver: %s" % str(e) + if check_driver is not None: + print "Could not detatch kernel driver: %s" % str(e) try: self.device.set_configuration()