我需要获取有关我的Windows机器上插入的HID设备的idProduct和idVendor的信息。如何获取给定HID设备的USB_DEVICE_DESCRIPTOR?
我搜索了互联网,但我只找到了使用WinUSB库查询并获取USB_DEVICE_DESCRIPTOR的设备示例。我的理解是我无法使用WinUSB插入HID设备。
那么我需要为HID设备使用什么?
答案 0 :(得分:1)
如果您使用的是HidLibrary,则可以获得如下设备:
_device = HidDevices.Enumerate(VendorId, ProductId, UsagePage).FirstOrDefault();
if (_device != null) {
_device.OpenDevice();
string product = GetProductString(_device);
string mfg = GetManufacturerString(_device);
}
后两个函数定义如下:
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;
}