Topic: WinHidDevice.ReportDescriptorReconstructor.cs NotImplException - fix
We have a number of devices that are throwing a NotImplementedException() in WinHidDevice.ReportDescriptorReconstructor.cs@171 [v2.1.0] during open. I propose the following code to mitigate the problem. Whether this fixes for all cases I cannot be sure but it seems to for us. I guess it shouldn't be a big deal if no-one else has previously reported this.
Thank you for your efforts.
else if (dataIndexCount == 1)
{
// Array...
int bitCount = reportItem.ReportCount * reportItem.ReportSize;
var usageValue = new byte[(bitCount + 7) / 8];
for (int i = 0; i < usageValue.Length; i++) { usageValue[i] = 0xff; }
int hr = NativeMethods.HidP_SetUsageValueArray(reportType, item.UsagePage, item.LinkCollection, item.UsageIndex, usageValue, (ushort)usageValue.Length, _preparsed, reportBytes, reportBytes.Length);
if (hr == NativeMethods.HIDP_STATUS_SUCCESS)
{
GetDataStartBit(reportBytes, reportItem, maxBit);
}
else if (hr == NativeMethods.HIDP_STATUS_NOT_VALUE_ARRAY) // +++[
{
hr = NativeMethods.HidP_SetUsageValue(reportType, item.UsagePage, item.LinkCollection, item.UsageIndex, 0xffffffff, _preparsed, reportBytes, reportBytes.Length);
if (hr == NativeMethods.HIDP_STATUS_SUCCESS)
{
GetDataStartBit(reportBytes, reportItem, maxBit);
}
else // ]+++
{
throw new NotImplementedException();
}
}
}
else
...
You'll need to add the following two items to NativeMethods.cs as well:
public static readonly int HIDP_STATUS_NOT_VALUE_ARRAY = HIDP_ERROR_CODES(12, 11);
[DllImport("hid.dll", CharSet = CharSet.Auto)]
public unsafe static extern int HidP_SetUsageValue(HIDP_REPORT_TYPE reportType, ushort usagePage, ushort linkCollection, ushort usage, uint usageValue, IntPtr preparsed, byte[] report, int reportLength);