libusb is a C library that provides generic access to USB devices. It is intended to be used by developers to facilitate the production of applications that communicate with USB hardware.
It is portable: Using a single cross-platform API, it provides access to USB devices on Linux, macOS, Windows, etc.
It is user-mode: No special privilege or elevation is required for the application to communicate with a device.
It is version-agnostic: All versions of the USB protocol, from 1.0 to 3.1 (latest), are supported.
1、首先需要安装libusb
sudo apt-get install libusb-1.0-0-dev
2、输入如下代码,并命名为list_devices.cpp
#include <cassert>
#include <cstdio>
#include <libusb-1.0/libusb.h>
int main() {
libusb_context *context = NULL;
libusb_device **list = NULL;
i