?Ubuntu?,????libusb????USB???????????????,??????libusb???USB?????:
#include#include int main() { libusb_device **devs; libusb_context *ctx = NULL; ssize_t cnt; // ???libusb? if (libusb_init(&ctx) < 0) { printf("libusb init failed\n"); return 1; } // ???????????USB???? cnt = libusb_get_device_list(ctx, &devs); if (cnt < 0) { printf("Failed to get device list\n"); return 1; } // ??USB????,?????? for (ssize_t i = 0; i < cnt; i++) { libusb_device *dev = devs[i]; struct libusb_device_descriptor desc; if (libusb_get_device_descriptor(dev, &desc) < 0) { printf("Failed to get device descriptor\n"); return 1; } printf("Device %d: VendorID=0xx, ProductID=0xx\n", i, desc.idVendor, desc.idProduct); } // ?????? libusb_free_device_list(devs, 1); // ??libusb? libusb_exit(ctx); return 0; }
?????????????????USB???VendorID?ProductID??????????????,???????????????????????????libusb?,????????:
gcc -o usb_example usb_example.c -lusb-1.0
?????????????????USB??????