HidD_SetFeature() private method

private HidD_SetFeature ( IntPtr hidDeviceObject, byte lpReportBuffer, int reportBufferLength ) : bool
hidDeviceObject System.IntPtr
lpReportBuffer byte
reportBufferLength int
return bool
Exemplo n.º 1
0
        public bool WriteFeatureData(byte[] data)
        {
            if (_deviceCapabilities.FeatureReportByteLength <= 0)
            {
                return(false);
            }

            var buffer = CreateFeatureOutputBuffer();

            Array.Copy(data, 0, buffer, 0, Math.Min(data.Length, _deviceCapabilities.FeatureReportByteLength));


            IntPtr hidHandle = IntPtr.Zero;
            bool   success   = false;

            try
            {
                hidHandle = OpenDeviceIO(_devicePath, NativeMethods.ACCESS_NONE);

                var overlapped = new NativeOverlapped();
                success = NativeMethods.HidD_SetFeature(hidHandle, buffer, buffer.Length);
            }
            catch (Exception exception)
            {
                throw new Exception(string.Format("Error accessing HID device '{0}'.", _devicePath), exception);
            }
            finally
            {
                if (hidHandle != IntPtr.Zero)
                {
                    CloseDeviceIO(hidHandle);
                }
            }
            return(success);
        }
Exemplo n.º 2
0
 public bool WriteFeatureData(byte[] data)
 {
     if (_deviceCapabilities.FeatureReportByteLength > 0)
     {
         byte[] array = CreateFeatureOutputBuffer();
         Array.Copy(data, 0, array, 0, Math.Min(data.Length, _deviceCapabilities.FeatureReportByteLength));
         IntPtr intPtr = IntPtr.Zero;
         bool   result = false;
         try
         {
             intPtr = OpenDeviceIO(_devicePath, 0u);
             result = NativeMethods.HidD_SetFeature(intPtr, array, array.Length);
         }
         catch (Exception innerException)
         {
             throw new Exception($"Error accessing HID device '{_devicePath}'.", innerException);
         }
         finally
         {
             if (intPtr != IntPtr.Zero)
             {
                 CloseDeviceIO(intPtr);
             }
         }
         return(result);
     }
     return(false);
 }