Listing usb devices using pyusb doesn't work

a 夏天 提交于 2021-02-11 09:44:02

问题


I am trying to list USB devices on my windows 7 pc. I installed this ahead: https://sourceforge.net/projects/libusb-win32/files/libusb-win32-releases/1.2.6.0/libusb-win32-devel-filter-1.2.6.0.exe

The code below does not print anything. Is there something else to be done to get the device info?

import usb.core
import usb.util
dev = usb.core.find(find_all=True)
for d in dev:
    print(usb.util.get_string(d,128,d.iManufacturer))

Edit: Solved

This comes close to what I need Retrieve list of USB items using Python

import win32com.client
wmi = win32com.client.GetObject ("winmgmts:")
for usb in wmi.InstancesOf ("Win32_USBHub"):
    print('Device ID:', usb.DeviceID)

回答1:


Looks like you're using a Python libusb wrapper. This will only enumerate USB devices which have actually been associated with the libusb driver. Every device is associated with a driver, and most will have class drivers (eg HID, UVC, MSC, etc) provided by the OS, so you need to use a different API to access them. You can enumerate all devices in a generic fashion by using the native SetupAPI and WinUSB on Windows, if that's what you really want. But this wrapper will only enumerate devices that specifically use the libusb driver. Since your code doesn't show any, you probably just don't have a device that uses libusb.

You can use the Zadig tool to remap drivers to different devices. But beware of doing this as you can easily break things if you happen to choose an unsupported configuration. It's normally used when you have a custom or 3rd party device.



来源:https://stackoverflow.com/questions/57634218/listing-usb-devices-using-pyusb-doesnt-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!