我要做的就是使用libusb win32列出usb设备,我遇到了很多麻烦。我正在使用c ++和minGW。这是我的简单程序,它将编译但不会列出任何内容。如果有人能告诉我从哪里开始,我们将不胜感激。
cout << "\nFinding Devices..." << endl;
struct usb_bus *busses;
usb_init();
usb_find_busses();
usb_find_devices();
busses = usb_get_busses();
usb_set_debug(3);
struct usb_bus *bus;
int c, i, a;
for (bus = busses; bus; bus->next){
struct usb_device *dev;
for (dev = bus->devices; dev; dev = dev->next){
if (dev->descriptor.bDeviceClass == 7){
usb_dev_handle usb_open(struct usb_device *dev);
int usb_set_configuration(usb_dev_handle *dev, int configuration);
}}}
答案 0 :(得分:0)
我猜想可能发生的事情是你的设备有0级 - 这意味着该类是在接口级定义的,而不是在设备级定义的。例如,这是lsusb
为我的Microsoft键盘报告的内容:
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x045e Microsoft Corp.
idProduct 0x07f8
bcdDevice 3.00
iManufacturer 1
iProduct 2
iSerial 0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 59
bNumInterfaces 2
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xa0
(Bus Powered)
Remote Wakeup
MaxPower 100mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 1 Boot Interface Subclass
bInterfaceProtocol 1 Keyboard
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.11
bCountryCode 0 Not supported
...
了解该设备如何将bDeviceClass
设置为0 (Defined at Interface level)
并且每个界面都设置了自己的bInterfaceClass
?
找出问题的最简单方法是找到适用于Windows的libusb.exe并使用-v
标志运行它以转储每个设备的详细信息。