本文介绍了Windows 7上的Pyusb-未实现错误:is_kernal_driver_active的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用escposprinter python库在热敏打印机中打印数据.这取决于pyusb.该库在linux上运行良好.在Windows 7中,我得到了一些问题.这是我得到的输出.

I am using escposprinter python library for printing my data in thermal printer. It depends on pyusb. the library is working fine in linux . While in windows 7 ,i get the it have some issues. Here are output i get.

File "main.py", line 1, in <module>
    from app import app
  File "D:\freeth-in-erp-60ab8eb96fad\app\__init__.py", line 94, in <module>
    from .api_routes import *
  File "D:\freeth-in-erp-60ab8eb96fad\app\api_routes.py", line 44, in <module>
    from .printer import pos
  File "D:\freeth-in-erp-60ab8eb96fad\app\printer\pos.py", line 14, in <module>
    Epson = printer.Usb(idVendor=0x0416,idProduct=0x5011)
  File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\escposprinter\print
er.py", line 37, in __init__
    self.open()
  File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\escposprinter\print
er.py", line 46, in open
    if self.device.is_kernel_driver_active(0):
  File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\usb\core.py", line
1064, in is_kernel_driver_active
    interface)
  File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\usb\backend\__init_
_.py", line 365, in is_kernel_driver_active
    _not_implemented(self.is_kernel_driver_active)
  File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\usb\backend\__init_
_.py", line 81, in _not_implemented
    raise NotImplementedError(func.__name__)
NotImplementedError: is_kernel_driver_active

我从libusb.info下载libusb-1.20,并从MinGW32复制文件libusb-1.0.dll,然后粘贴到"C:\ windows \ System32"中.我得到以下结果.

i download the libusb-1.20 from libusb.info and copy file libusb-1.0.dll from MinGW32 and paste in "C:\windows\System32". I get the following result.

   from app import app
  File "D:\freeth-in-erp-60ab8eb96fad\app\__init__.py", line 94, in <module>
    from .api_routes import *
  File "D:\freeth-in-erp-60ab8eb96fad\app\api_routes.py", line 44, in <module>
    from .printer import pos
  File "D:\freeth-in-erp-60ab8eb96fad\app\printer\pos.py", line 14, in <module>
    Epson = printer.Usb(idVendor=0x0416,idProduct=0x5011)
  File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\escposprinter\print
er.py", line 37, in __init__
    self.open()
  File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\escposprinter\print
er.py", line 46, in open
    if self.device.is_kernel_driver_active(0):
  File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\usb\core.py", line
1064, in is_kernel_driver_active
    interface)
  File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\usb\backend\libusb1
.py", line 898, in is_kernel_driver_active
    intf)))
  File "D:\freeth-in-erp-60ab8eb96fad\venv\lib\site-packages\usb\backend\libusb1
.py", line 593, in _check
    raise NotImplementedError(_strerror(ret))
NotImplementedError: Operation not supported or unimplemented on this platform

我的代码是`

from escposprinter import *
from tabulate import tabulate

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

来自库escposprinter

from library 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))

帮我提出您的建议`

推荐答案

问题很简单,那就是检查内核驱动程序是否处于活动状态,这在Windows上是不可能的.看来该库根本不是为在Windows上使用而编写的.

The problem is plain and simple that the check whether a kernel driver is active which is not possible on Windows. It seems this library is simply not written for use on Windows.

如果您从源代码中删除以if self.device.is_kernel_driver_active(0):开头的最后5行,或者预先检查代码是否在Windows上运行并且不调用它们,则可以在Windows上使用它.

You can use it on Windows if you delete the last 5 lines from the source code starting with if self.device.is_kernel_driver_active(0): or check if the code runs on Windows beforehand and don't call them.

请记住,在Windows上,您需要安装自己的驱动程序.我建议使用Zadig创建和/或安装驱动程序.

Remember on Windows you need to install your own driver. I recommend using Zadig for creating and/or installing the driver.

这篇关于Windows 7上的Pyusb-未实现错误:is_kernal_driver_active的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 15:43