【问题标题】:PyUSB error "USBError: [Errno 2] Entity not found" using libusb0 driver (Windows 10)PyUSB 错误“USBError:[Errno 2] Entity not found”使用 libusb0 驱动程序(Windows 10)
【发布时间】:2017-09-27 22:42:06
【问题描述】:

我正在尝试与 USB 设备建立通信。我确实在 Python 中安装了 libusb1 和 libusb,并为我正在与之通信的设备安装了驱动程序。该设备在设备管理器中显示为 libusb-win32-devices。我已尝试遵循本教程https://github.com/walac/pyusb/blob/master/docs/tutorial.rst 我不确定我做错了什么。

  • Windows 10
  • Python:2.7.15
  • pyusb:版本 '1.0.2'

简单代码示例:

import usb
dev = usb.core.find(idVendor=0x0683, idProduct=0x4108)
if dev is None:
       print 'Unable to find the usb device'
dev.set_configuration()

我收到此错误:

---------------------------------------------------------------------------
USBError                                  Traceback (most recent call last)
Y:\All Projects\Lab Equipment\DataQ\python\DI-4108\DI_4108_SANDBOX.py in <module>()
      9
     10
---> 11 dev.set_configuration()
     12
     13 # get an endpoint instance

C:\Anaconda2\lib\site-packages\usb\core.pyc in set_configuration(self, configuration)
    867         without arguments is enough to get the device ready.
    868         """
--> 869         self._ctx.managed_set_configuration(self, configuration)
    870
    871     def get_active_configuration(self):

C:\Anaconda2\lib\site-packages\usb\core.pyc in wrapper(self, *args, **kwargs)
    100         try:
    101             self.lock.acquire()
--> 102             return f(self, *args, **kwargs)
    103         finally:
    104             self.lock.release()

C:\Anaconda2\lib\site-packages\usb\core.pyc in managed_set_configuration(self, device, config)
    146
    147         self.managed_open()
--> 148         self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
    149
    150         # cache the index instead of the object to avoid cyclic references

C:\Anaconda2\lib\site-packages\usb\backend\libusb1.pyc in set_configuration(self, dev_handle, config_value)
    792     @methodtrace(_logger)
    793     def set_configuration(self, dev_handle, config_value):
--> 794         _check(self.lib.libusb_set_configuration(dev_handle.handle, config_value))
    795
    796     @methodtrace(_logger)

C:\Anaconda2\lib\site-packages\usb\backend\libusb1.pyc in _check(ret)
    593             raise NotImplementedError(_strerror(ret))
    594         else:
--> 595             raise USBError(_strerror(ret), ret, _libusb_errno[ret])
    596
    597     return ret

USBError: [Errno 2] Entity not found

我确实获得了有关我的设备的信息:

> DEVICE ID 0683:4108 on Bus 002 Address 005 =================  bLength 
> :   0x12 (18 bytes)  bDescriptorType        :    0x1 Device  bcdUSB   
> :  0x200 USB 2.0  bDeviceClass           :   0xff Vendor-specific 
> bDeviceSubClass        :    0x0  bDeviceProtocol        :    0x0 
> bMaxPacketSize0        :   0x40 (64 bytes)  idVendor               :
> 0x0683  idProduct              : 0x4108  bcdDevice              : 
> 0x100 Device 1.0  iManufacturer          :    0x1 Error Accessing
> String  iProduct               :    0x2 Error Accessing String 
> iSerialNumber          :    0x3 Error Accessing String 
> bNumConfigurations     :    0x1   CONFIGURATION 1: 500 mA
> ==================================    bLength              :    0x9 (9 bytes)    bDescriptorType      :    0x2 Configuration    wTotalLength 
> :   0x20 (32 bytes)    bNumInterfaces       :    0x1   
> bConfigurationValue  :    0x1    iConfiguration       :    0x5 Error
> Accessing String    bmAttributes         :   0xc0 Self Powered   
> bMaxPower            :   0xfa (500 mA)
>     INTERFACE 0: Vendor Specific ===========================
>      bLength            :    0x9 (9 bytes)
>      bDescriptorType    :    0x4 Interface
>      bInterfaceNumber   :    0x0
>      bAlternateSetting  :    0x0
>      bNumEndpoints      :    0x2
>      bInterfaceClass    :   0xff Vendor Specific
>      bInterfaceSubClass :    0x0
>      bInterfaceProtocol :    0x0
>      iInterface         :    0x4 Error Accessing String
>       ENDPOINT 0x81: Bulk IN ===============================
>        bLength          :    0x7 (7 bytes)
>        bDescriptorType  :    0x5 Endpoint
>        bEndpointAddress :   0x81 IN
>        bmAttributes     :    0x2 Bulk
>        wMaxPacketSize   :   0x40 (64 bytes)
>        bInterval        :    0x0
>       ENDPOINT 0x1: Bulk OUT ===============================
>        bLength          :    0x7 (7 bytes)
>        bDescriptorType  :    0x5 Endpoint
>        bEndpointAddress :    0x1 OUT
>        bmAttributes     :    0x2 Bulk
>        wMaxPacketSize   :   0x40 (64 bytes)
>        bInterval        :    0x0

那么,最后一个问题是:如何在 Windows 中获得权限?在 Linux 中,您可以通过 udev 来完成。如何在 Windows 中解决此问题?

【问题讨论】:

  • 如果我尝试在其中写入(在 [82] 中:dev.write(1,'test'))。我得到 USBError: [Errno 13] Access denied (insufficient permissions)
  • 我发现了一个问题。供应商提供的软件甚至看不到我试图与之交谈的设备。因此,下一步将是弄清楚为什么会发生这种情况。如果我发现任何东西,我会继续发布。顺便说一句,该设备是 DATAQ Instruments 的 DI-4108。我试图添加一个标签,但我没有足够的声誉。

标签: python windows usb libusb


【解决方案1】:

解决方案 #1: 如果您的 USB 批量设备在设备管理器中显示为 libusb-win32。您需要更改使用 libusb0 (v1.0.6.0) 的 libusb-win32 驱动程序

到使用 libusbK 驱动程序的 libusbK USB 设备(在我的例子中是 v3.0.7.0)。这实际上将安装 libusbK 驱动程序并更改驱动程序。这可以通过Zadig free software 无缝完成

这样就可以解决错误码的问题了

USBError: [Errno 2] Entity not found

【讨论】:

    【解决方案2】:

    这个场景有 2 个问题 1.pyusb libusb库搜索问题,pyusb会尝试搜索windows PATH中的任何libusb1 dll,而不是首选zadig在system32路径下安装的libusb0,你可以通过设置PYUSB_DEBUG标志找到这个问题

     To enable PyUSB logging, you define the environment variable PYUSB_DEBUG with one of the following logging level values:
    
    critical - only log critical errors
    error - only log critical errors and errors
    warning - log warnings, errors, and critical errors
    info - log info, warnings, errors, and critical errors
    debug - log everything including debug messages
    

    但它有时会出现不输出任何内容的问题,您必须将输出重定向到本地文件以查找其尝试使用在任何相关 PATH 程序文件夹中找到的 libusb1 dll 的行为

    By default, logged messages are sent to sys.stderr. You can redirect log messages to a file by defining the PYUSB_LOG_FILENAME environment variable to a string that is a valid file path and all logged messages will be written to the file rather than being sent to sys.stderr.
    

    2.libusb1兼容问题,libusb或sourceforge上的libusb-win32中的libusb1 dll都没有提供某些特定python程序所需的函数导出,可能会这样出来

    1. 未找到实体 + 未在此平台上实现

    2. 权限被拒绝

    两者都是由于libusb1.0 API在Windows平台上的不完整实现

    只需从上面的日志中删除任何 libusb1 dll 并让 pyUSB 尝试使用 libusb0。

    【讨论】:

      猜你喜欢
      • 2019-07-11
      • 2019-07-04
      • 2015-12-25
      • 1970-01-01
      • 1970-01-01
      • 2019-01-29
      • 1970-01-01
      • 2017-02-10
      • 1970-01-01
      相关资源
      最近更新 更多