本文主要是记录一下学习过程。
程序来源于:https://unix.stackexchange.com/questions/61484/find-the-information-of-usb-devices-in-c
编译之前需要安装libusb0.1:
可以使用 sudo apt-get install libusb*
来安装
使用 命令g++ -pthread -o usb USBinf.cpp -lusb
来进行编译
#include <stdio.h>
#include<usb.h>
main(){
struct usb_bus *bus;
struct usb_device *dev;
usb_init();
usb_find_busses();
usb_find_devices();
for (bus = usb_busses; bus; bus = bus->next)
for (dev = bus->devices; dev; dev = dev->next){
printf("Trying device %s/%s\n", bus->dirname, dev->filename);
printf("\tID_VENDOR = 0x%04x\n", dev->descriptor.idVendor);
printf("\tID_PRODUCT = 0x%04x\n", dev->descriptor.idProduct);
}
}