HidD_GetFeature() private method

private HidD_GetFeature ( IntPtr hidDeviceObject, byte lpReportBuffer, int reportBufferLength ) : bool
hidDeviceObject System.IntPtr
lpReportBuffer byte
reportBufferLength int
return bool
コード例 #1
0
ファイル: HidDevice.cs プロジェクト: wdatkinson/KFDtool
 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);
 }
コード例 #2
0
ファイル: HidDevice.cs プロジェクト: biletnam/homeControl
        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);
        }
コード例 #3
0
ファイル: HidDevice.cs プロジェクト: yuvalka246/ds4-tool
 public bool readFeatureData(byte[] inputBuffer)
 {
     return(NativeMethods.HidD_GetFeature(safeReadHandle.DangerousGetHandle(), inputBuffer, inputBuffer.Length));
 }