问题
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?
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.
What do I need to use for a HID device then?
回答1:
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;
}
来源:https://stackoverflow.com/questions/22611445/how-do-i-get-the-vendor-and-product-strings-in-case-of-a-hid-device-on-windows