private HidD_GetFeature ( |
||
hidDeviceObject | ||
lpReportBuffer | byte | |
reportBufferLength | int | |
return | bool |
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); }
public bool ReadFeatureData(out byte[] data, byte reportId = 0) { if (_deviceCapabilities.FeatureReportByteLength <= 0) { data = new byte[0]; return(false); } data = new byte[_deviceCapabilities.FeatureReportByteLength]; var buffer = CreateFeatureOutputBuffer(); buffer[0] = reportId; IntPtr hidHandle = IntPtr.Zero; bool success = false; try { if (IsOpen) { hidHandle = Handle; } else { hidHandle = OpenDeviceIO(_devicePath, NativeMethods.ACCESS_NONE); } success = NativeMethods.HidD_GetFeature(hidHandle, buffer, buffer.Length); if (success) { Array.Copy(buffer, 0, data, 0, Math.Min(data.Length, _deviceCapabilities.FeatureReportByteLength)); } } catch (Exception exception) { throw new Exception(string.Format("Error accessing HID device '{0}'.", _devicePath), exception); } finally { if (hidHandle != IntPtr.Zero && hidHandle != Handle) { CloseDeviceIO(hidHandle); } } return(success); }
public bool readFeatureData(byte[] inputBuffer) { return(NativeMethods.HidD_GetFeature(safeReadHandle.DangerousGetHandle(), inputBuffer, inputBuffer.Length)); }