python 3.5 - Pyusb på Windows 7 - Ikke-implementeret Fejl: is\_kernal\_driver\_active

Indlæg af Hanne Mølgaard Plasc

Problem



Jeg bruger escposprinter python bibliotek til at udskrive mine data i termisk printer. Det afhænger af pyrus. biblioteket fungerer fint i linux. Mens i Windows 7 får jeg det, det har nogle problemer. Her er output, jeg får.


File "main.py", line 1, in <module>
    from app import app
  File "D:freeth-in-erp-60ab8eb96fadapp\_\_init\_\_.py", line 94, in <module>
    from .api\_routes import *
  File "D:freeth-in-erp-60ab8eb96fadappapi\_routes.py", line 44, in <module>
    from .printer import pos
  File "D:freeth-in-erp-60ab8eb96fadappprinterpos.py", line 14, in <module>
    Epson = printer.Usb(idVendor=0x0416,idProduct=0x5011)
  File "D:freeth-in-erp-60ab8eb96fadvenvlibsite-packagesescposprinterprint
er.py", line 37, in \_\_init\_\_
    self.open()
  File "D:freeth-in-erp-60ab8eb96fadvenvlibsite-packagesescposprinterprint
er.py", line 46, in open
    if self.device.is\_kernel\_driver\_active(0):
  File "D:freeth-in-erp-60ab8eb96fadvenvlibsite-packagesusbcore.py", line
1064, in is\_kernel\_driver\_active
    interface)
  File "D:freeth-in-erp-60ab8eb96fadvenvlibsite-packagesusbackend\_\_init\_
\_.py", line 365, in is\_kernel\_driver\_active
    \_not\_implemented(self.is\_kernel\_driver\_active)
  File "D:freeth-in-erp-60ab8eb96fadvenvlibsite-packagesusbackend\_\_init\_
\_.py", line 81, in \_not\_implemented
    raise NotImplementedError(func.\_\_name\_\_)
NotImplementedError: is\_kernel\_driver\_active


Jeg henter libusb-1.20 fra libusb.info og kopier fil libusb-1.0.dll fra MinGW32 og indsæt i 'C: \ windows \ System32'. Jeg får følgende resultat.


   from app import app
  File "D:freeth-in-erp-60ab8eb96fadapp\_\_init\_\_.py", line 94, in <module>
    from .api\_routes import *
  File "D:freeth-in-erp-60ab8eb96fadappapi\_routes.py", line 44, in <module>
    from .printer import pos
  File "D:freeth-in-erp-60ab8eb96fadappprinterpos.py", line 14, in <module>
    Epson = printer.Usb(idVendor=0x0416,idProduct=0x5011)
  File "D:freeth-in-erp-60ab8eb96fadvenvlibsite-packagesescposprinterprint
er.py", line 37, in \_\_init\_\_
    self.open()
  File "D:freeth-in-erp-60ab8eb96fadvenvlibsite-packagesescposprinterprint
er.py", line 46, in open
    if self.device.is\_kernel\_driver\_active(0):
  File "D:freeth-in-erp-60ab8eb96fadvenvlibsite-packagesusbcore.py", line
1064, in is\_kernel\_driver\_active
    interface)
  File "D:freeth-in-erp-60ab8eb96fadvenvlibsite-packagesusbackendlibusb1
.py", line 898, in is\_kernel\_driver\_active
    intf)))
  File "D:freeth-in-erp-60ab8eb96fadvenvlibsite-packagesusbackendlibusb1
.py", line 593, in \_check
    raise NotImplementedError(\_strerror(ret))
NotImplementedError: Operation not supported or unimplemented on this platform


min kode er
`


from escposprinter import *
from tabulate import tabulate

Epson = printer.Usb(0x0416,0x5011)


fra bibliotekets escposprinter


  class Usb(Escpos):
    """ Define USB printer """

    def \_\_init\_\_(self, idVendor, idProduct, interface=0, in\_ep=0x82, out\_ep=0x01):
        """
        @param idVendor  : Vendor ID
        @param idProduct : Product ID
        @param interface : USB device interface
        @param in\_ep     : Input end point
        @param out\_ep    : Output end point
        """
        self.idVendor  = idVendor
        self.idProduct = idProduct
        self.interface = interface
        self.in\_ep     = in\_ep
        self.out\_ep    = out\_ep
        self.open()


    def open(self):
        """ Search device on USB tree and set is as escpos device """
        self.device = usb.core.find(idVendor=self.idVendor, idProduct=self.idProduct)
        if self.device is None:
            print ("Cable isn't plugged in")

        if self.device.is\_kernel\_driver\_active(0):
            try:
                self.device.detach\_kernel\_driver(0)
            except usb.core.USBError as e:
                print ("Could not detatch kernel driver: \%s" \% str(e))


hjælp mig med dit forslag
`

Bedste reference


Problemet er klart og simpelt at kontrollere, om en kernel driver er aktiv, hvilket ikke er muligt på Windows. Det ser ud til, at dette bibliotek simpelthen ikke er skrevet til brug på Windows.


Du kan bruge den på Windows, hvis du sletter de sidste 5 linjer fra kildekoden, der begynder med if self.device.is\_kernel\_driver\_active(0):, eller kontroller, om koden kører på Windows på forhånd og ikke ring dem.


Husk på Windows, du skal installere din egen driver. Jeg anbefaler at bruge Zadig til at oprette og/eller installere driveren.