mirror of
				https://github.com/python-escpos/python-escpos
				synced 2025-10-23 09:30:00 +00:00 
			
		
		
		
	Enable Windows Support
This commit is contained in:
		@@ -17,6 +17,7 @@ import usb.core
 | 
			
		||||
import usb.util
 | 
			
		||||
import serial
 | 
			
		||||
import socket
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
from .escpos import Escpos
 | 
			
		||||
from .exceptions import USBNotFoundError
 | 
			
		||||
@@ -68,19 +69,22 @@ class Usb(Escpos):
 | 
			
		||||
        self.idVendor = self.device.idVendor
 | 
			
		||||
        self.idProduct = self.device.idProduct
 | 
			
		||||
 | 
			
		||||
        check_driver = None
 | 
			
		||||
        # detach_kernel_driver() doesn't really work on Windows,
 | 
			
		||||
        # causing the library to not work on that platform.
 | 
			
		||||
        if sys.platform != 'win32':
 | 
			
		||||
            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:
 | 
			
		||||
                if check_driver is not None:
 | 
			
		||||
                    print("Could not detatch kernel driver: {0}".format(str(e)))
 | 
			
		||||
                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:
 | 
			
		||||
                    if check_driver is not None:
 | 
			
		||||
                        print("Could not detatch kernel driver: {0}".format(str(e)))
 | 
			
		||||
 | 
			
		||||
        try:
 | 
			
		||||
            self.device.set_configuration()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user