public bool ReadFeatureData(out byte[] data, byte reportId = 0)
{
if (_deviceCapabilities.FeatureReportByteLength > 0)
{
data = new byte[_deviceCapabilities.FeatureReportByteLength];
byte[] array = CreateFeatureOutputBuffer();
array[0] = reportId;
IntPtr intPtr = IntPtr.Zero;
bool flag = false;
try
{
intPtr = OpenDeviceIO(_devicePath, 0u);
flag = NativeMethods.HidD_GetFeature(intPtr, array, array.Length);
if (flag)
{
Array.Copy(array, 0, data, 0, Math.Min(data.Length, _deviceCapabilities.FeatureReportByteLength));
}
}
catch (Exception innerException)
{
throw new Exception($"Error accessing HID device '{_devicePath}'.", innerException);
}
finally
{
if (intPtr != IntPtr.Zero)
{
CloseDeviceIO(intPtr);
}
}
return(flag);
}
data = new byte[0];
return(false);
}