3

我没有正确理解 USB 协议,因此在添加 USB 时对获取有关 USB 的数据的代码感到困惑。我不知道我哪里出错了。我的系统是 Windows 8 64 位。

有一个重大错误,我也需要帮助。

import usb.core
import usb.util
# Find our device
dev = usb.core.find(find_all=True)
busses = usb.busses()
# Was it found?
if dev is None:
    raise ValueError('Device not found')

for bus in busses:
    devices = bus.devices
    for dev in devices:
        try:
            _name = usb.util.get_string(dev.dev, 19, 1)
        except:
             continue
        dev.set_configuration()
        cfg = dev.get_active_configuration()
        interface_number = cfg[(0,0)].bInterfaceNumber
        alternate_settting = usb.control.get_interface(interface_number)
        print "Device name:",_name
        print "Device:", dev.filename
        print "  idVendor:",hex(dev.idVendor)
        print "  idProduct:",hex(dev.idProduct)
        for config in dev.configurations:
            print "  Configuration:", config.value
            print "    Total length:", config.totalLength 
            print "    selfPowered:", config.selfPowered
            print "    remoteWakeup:", config.remoteWakeup
            print "    maxPower:", config.maxPower
        print

这是我得到的错误:

import usb.backend.libusb10 as libusb10
ImportError: No module named backend.libusb10

4

1 回答 1

0

除了最新版本的pyusb还需要安装最新版本的libusb

在 Windows 上,只需从 libusb 文件包中提取:(libusb-1.0.dll从文件夹 MinGW32/64 - 取决于 python 版本)并将其复制到C:\Windows\System32\文件夹中。

于 2017-12-19T09:27:33.367 回答