libusb如何获得vid和pid
Libusb how to get VID and PID
我有一些代码,可以找到所有连接的USB设备,其供应商和Productid。
我需要一个可以通过VID找到连接的设备的程序,并从监视器或触摸板中找到PID。我找到了具有类视频的libusb_class_code
,但我没有找到任何返回libusb_class_code
的功能。
libusb_context *context = nullptr;
libusb_device **list = nullptr;
libusb_init(&context);
int count = libusb_get_device_list(context, &list);
for (size_t idx = 0; idx < count; ++idx)
{
libusb_device *device = list[idx];
libusb_device_descriptor desc = { 0 };
libusb_get_device_descriptor(device, &desc);
cout << "idVendor " << desc.idVendor << "t";
cout << "idProduct " << desc.idProduct << endl;
}
如果要通过vid and pid访问给定的设备,则有一个专用函数 libusb_open_device_with_vid_pid
。
这是一个简单的示例,它显示了如何打开设备,处理接口,读取数据然后关闭数据。
。libusb_context *context = NULL ;
libusb_device_handle *dev_handle = NULL ;
libusb_device **devs ;
int rc = 0 ;
ssize_t count ; //holding number of devices in list
//----------------------------------------------------------------------------
// Initialize the library
//----------------------------------------------------------------------------
rc = libusb_init(&context);
assert(rc == 0);
//----------------------------------------------------------------------------
// open usb device by vendor ID and Product ID
//----------------------------------------------------------------------------
dev_handle = libusb_open_device_with_vid_pid(context,VENDOR_ID,PRODUCT_ID);
assert(dev_handle == NULL);
//----------------------------------------------------------------------------
// Check that the kernel is attached
//----------------------------------------------------------------------------
if(libusb_kernel_driver_active(dev_handle, 0))
{
rc = libusb_detach_kernel_driver(dev_handle, 0); // detach driver
assert(rc == 0);
}
//----------------------------------------------------------------------------
// claim the interface
//----------------------------------------------------------------------------
rc = libusb_claim_interface(dev_handle, 0);
assert(rc < 0);
//----------------------------------------------------------------------------
// start the bulk transfer
//----------------------------------------------------------------------------
rc = libusb_bulk_transfer(dev_handle, (64 | LIBUSB_ENDPOINT_OUT), data, 4, &actual, 0);
assert (rc != 0 || actual != 5);
//----------------------------------------------------------------------------
// release the interface before closing the device
//----------------------------------------------------------------------------
rc = libusb_release_interface(dev_handle, 0);
assert(rc != 0);
//----------------------------------------------------------------------------
// close the device
//----------------------------------------------------------------------------
libusb_close(dev_handle);
//----------------------------------------------------------------------------
// exit
//----------------------------------------------------------------------------
libusb_exit(context);
相关文章:
- 使用 VID、PID、+SN 查找 USB 端口号
- 对于四轴飞行器,PID中I控制器的理想值应该是多少
- 在 fork() 之后,我在我的程序中不断得到相同的 pid
- 两个进程可以通过跟踪附加到同一个 PID 吗?
- 如何获取进程的整数PID?
- Linux:获取孙子的pid C++
- 在 C 中获取背景外壳命令的 PID
- 通过 pid 窗口判断进程是否存在
- PID 不使用 fork() 定义类型
- 我想获取我在C++中创建的每个进程的 PID,并在特定时间后终止每个进程
- 从某些 PID C++ 开始
- MacOS - 如何使用 C/C++ 获取具有 PID 的进程用户/所有者
- 如何在Mac OSX C 中找到任何过程的PID
- (LINX-IPC 协议)如何确定具有 PID 的进程是否在C++中运行
- 如何使用 /dev/xxx 路径中的C++获取 Ubuntu 中设备的 USB VID、PID 和序列号
- 使用提升从 pid 获取"binary file"/"executable"的路径?
- C Windows-如何从其PID(错误)获取过程路径
- libusb如何获得vid和pid
- 在 Linux 中基于 USB VID:PID 获取设备路径
- 使用设备VID/PID打开usb串口