Ugly stuff made simple, at least.
Hideous is a library for .NET allowing users to interface with HID devices using a simple programming interface that doesn't require them to guess "how the fuck do I use it".
So am I, but I get you. Catch.
usingHideous;varcollection=newHidDeviceCollection(vendorId:0x0B05,productId:0x19B6);foreach(vardeviceincollection){Console.WriteLine(device.Properties);}usingHideous;varcollection=newHidDeviceCollection();/* Same as (0, 0) */foreach(vardeviceincollection){Console.WriteLine(device.Properties);}usingHideous;varcollection=newHidDeviceCollection(0x0B05,0x19B6);varmyDevice=collection.FirstOrDefault(x =>x.Properties.UsagePage==0xFF00);usingHideous;varcollection=newHidDeviceCollection(0x0B05,0x19B6);varmyDevice=collection.FirstOrDefault(
x =>x.Properties.UsagePage==0x0001&&x.Properties.UsageId==0x0006);if(myDevice!=null){myDevice.Connect();/* Descriptor only becomes valid AFTER connection was established. */foreach(varreportinmyDevice.Descriptor.Reports){Console.WriteLine(report);}}usingHideous;varcollection=newHidDeviceCollection(0x0B05,0x19B6);varmyDevice=collection.FirstOrDefault(
x =>x.Properties.UsagePage==0xFF31&&x.Properties.UsageId==0x0076);if(myDevice!=null){myDevice.Connect();while(true){varbytes=newbyte[31];/** * 0x01 refers to the report ID, * not its index in the collection. * * By default reads are non-blocking. * To enforce blocking readsset * myDevice.IsReadBlocking to `true`. * * This method doesn't require prefixing * the data bytes with the report ID. * * The output byte array will be trimmed to the * actual count of bytes read from the device. * * Same deal with Feature reports, but they have * Set and Get methods accordingly. **/varreadBytes=myDevice.Descriptor.InputReports[0x5D].Read(bytes);foreach(varbinreadBytes){Console.WriteLine(b.ToString("X2"));}}}The library currently supports Windows and Linux only - because of the natives extracted when the library first runs, you will find either hidapi.dll or hidapi.so if not already present.
Requires HidApi >= 0.14.0.