How to get Vendor and Product strings in case of a HID device in Windows?

I need to get information about idProduct and idVendor of a connected HID device on my Windows machine. How to get USB_DEVICE_DESCRIPTOR for this HID device?

I searched on the Internet, but I found examples of devices that are queried using the WinUSB library, and getting USB_DEVICE_DESCRIPTOR. I understand that I can not use WinUSB to connect a HID device.

What do I need to use for a HID device?

+1
source share
1 answer

If you use 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); } 

Using the last two functions defined as follows:

  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; } 
+1
source

Source: https://habr.com/ru/post/976247/


All Articles