我如何在Windows上的HID设备的情况下获得供应商和产品字符串
本文关键字:情况下 供应商 字符串 Windows 上的 HID | 更新日期: 2023-09-27 17:52:35
我需要获得关于我的Windows机器上插入的HID设备的idProduct和idVendor的信息。如何获得给定HID设备的USB_DEVICE_DESCRIPTOR ?
我搜索了互联网,但我只发现了使用WinUSB库查询设备并获得USB_DEVICE_DESCRIPTOR的示例。我的理解,我不能使用WinUSB插入的HID设备。
那么我需要使用什么来使用HID设备呢?
如果你在使用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;
}