From d20646b2a941addfc1ca0cacc6d6cdabcfad41d0 Mon Sep 17 00:00:00 2001 From: Omer Akram Date: Wed, 22 May 2019 17:01:13 +0500 Subject: [PATCH] Make windows enablement code more intelligent --- src/escpos/printer.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/escpos/printer.py b/src/escpos/printer.py index 1763c5c..ed38d4f 100644 --- a/src/escpos/printer.py +++ b/src/escpos/printer.py @@ -17,7 +17,6 @@ import usb.core import usb.util import serial import socket -import sys from .escpos import Escpos from .exceptions import USBNotFoundError @@ -69,9 +68,11 @@ class Usb(Escpos): self.idVendor = self.device.idVendor self.idProduct = self.device.idProduct - # detach_kernel_driver() doesn't really work on Windows, - # causing the library to not work on that platform. - if sys.platform != 'win32': + # pyusb has three backends: libusb0, libusb1 and openusb but + # only libusb1 backend implements the methods is_kernel_driver_active() + # and detach_kernel_driver(). This change helps enable this + # library to work on Windows. + if sef.device.backend.__module__.endswith("libusb1"): check_driver = None try: