【问题标题】:Pyusb Windows error:USBError: [Errno None] libusb0-dll:err [claim_interface] could not claim interface 1, win error: The requested resource is in usePyusb Windows 错误:USBError: [Errno None] libusb0-dll:err [claim_interface] could not claim interface 1, win error: The requested resource is in use
【发布时间】:2019-07-11 03:09:56
【问题描述】:

我正在尝试在 python 中使用 pyusb 从 USB 读取数据。我能够获取设备的所有配置,但是当我尝试读取数据时。我收到以下错误:

USBError: [Errno None] libusb0-dll:err [claim_interface] could not claim interface 1, win error: The requested resource is in use.

PF 代码也是我写的:

import usb.core
test = usb.core.find(idVendor=0x0ghe, idProduct=0x0241)
print test

test.set_configuration()

for i in range(0, 20):
    while True:
        try:
            test = test.read(0x81, 8, timeout=50)
            break
        except usb.core.USBError, e:            
            if str(e).find("timeout") >= 0:
                pass
            else:
                raise IOError("USB Error: %s"%str(e))

    print test

以下是我的问题:

  1. 当我们在 USB 连接的设备中进行任何操作时,如何每秒从主机中的 USB 读取数据?
  2. 为什么从端点读取数据时会出现此错误?
  3. 使用 pyusb 从 USB 读取输入的有效方法是什么?

【问题讨论】:

  • 行为是否取决于设备?在您的系统上使用 pyusb 是否有任何访问权限?
  • 不,它不依赖于特定设备。是的,它适用于获取具有配置和接口的设备信息。仅用于读取数据我遇到问题。

标签: python python-2.7 pyusb


【解决方案1】:

我在将 pyusb 与我创建的自定义 USB 设备和 libusb-win32(v1.2.6.0) 驱动程序一起使用时遇到了这个问题。我能够从根本上导致尝试创建对已打开设备的多个引用的问题。就我而言,每次尝试写入其中一个端点时,我都在搜索设备,但我已经在之前的函数调用中引用了该设备。只保留一个对设备的引用为我解决了这个问题。

【讨论】:

  • 几行关于 Maintaining only one reference to the device 的代码显示如何执行和不执行此操作可能会有所帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-18
  • 2021-04-28
  • 2016-07-10
  • 1970-01-01
  • 2021-03-24
  • 2016-04-30
  • 2010-12-05
相关资源
最近更新 更多