问题描述
我需要获取有关Windows计算机上插入的HID设备的idProduct和idVendor的信息.如何获得给定HID设备的USB_DEVICE_DESCRIPTOR?
I need to get information about the idProduct and idVendor of a plugged in HID device on my Windows machine. How do I get the USB_DEVICE_DESCRIPTOR for a given HID device?
我搜索了Internet,但仅找到使用WinUSB库查询设备并获取USB_DEVICE_DESCRIPTOR的示例.我的理解是我无法使用WinUSB插入HID设备.
I searched the internet, but I only found examples of devices being queried using the WinUSB library and getting the USB_DEVICE_DESCRIPTOR. My understanding that I cannot use WinUSB for plugged in HID device.
那么我需要为HID设备使用什么?
What do I need to use for a HID device then?
推荐答案
如果您使用的是 HidLibrary ,您可以获得这样的设备:
If you're using HidLibrary, you can get a device like this:
_device = HidDevices.Enumerate(VendorId, ProductId, UsagePage).FirstOrDefault();
if (_device != null) {
_device.OpenDevice();
string product = GetProductString(_device);
string mfg = GetManufacturerString(_device);
}
后两个函数的定义如下:
With the latter two functions defined like this:
private string GetProductString(HidDevice d) {
byte[] bs;
_device.ReadProduct(out bs);
string ps = "";
foreach (byte b in bs) {
if (b > 0)
ps += ((char)b).ToString();
}
return ps;
}
private string GetManufacturerString(HidDevice d) {
byte[] bs;
_device.ReadManufacturer(out bs);
string ps = "";
foreach (byte b in bs) {
if (b > 0)
ps += ((char)b).ToString();
}
return ps;
}
这篇关于在Windows上使用HID设备的情况下,如何获取供应商和产品字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!