Example #1
0
        /// <summary>
        /// Retrieves a feature from the device.
        /// </summary>
        /// <param name="device"></param>
        /// <param name="code"></param>
        /// <param name="datalen"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static HIDFeatureResult GetHIDFeature(IntPtr device, int code, int datalen = 16)
        {
            HIDFeatureResult GetHIDFeatureRet = default;
            MemPtr           mm = new MemPtr();

            int i = code;

            try
            {
                mm.AllocZero(datalen);
                mm.ByteAt(0L) = (byte)i;
                if (UsbLibHelpers.HidD_GetFeature(device, mm.Handle, (int)mm.Length))
                {
                    GetHIDFeatureRet = new HIDFeatureResult(i, mm);
                }
                else
                {
                    GetHIDFeatureRet = null;
                }

                mm.Free();
            }
            catch
            {
                mm.Free();
                return(null);
            }

            return(GetHIDFeatureRet);
        }
Example #2
0
        /// <summary>
        /// Retrieves a feature from the device.
        /// </summary>
        /// <param name="device"></param>
        /// <param name="code"></param>
        /// <param name="datalen"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static HIDFeatureResult GetHIDFeature(HidDeviceInfo device, int code, int datalen = 16)
        {
            HIDFeatureResult GetHIDFeatureRet = default;
            IntPtr           hFile;

            hFile = IO.CreateFile(device.DevicePath, IO.GENERIC_READ, IO.FILE_SHARE_READ | IO.FILE_SHARE_WRITE, IntPtr.Zero, IO.OPEN_EXISTING, IO.FILE_ATTRIBUTE_NORMAL, default);
            if (hFile == IntPtr.Zero)
            {
                return(null);
            }
            GetHIDFeatureRet = GetHIDFeature(hFile, code, datalen);
            User32.CloseHandle(hFile);
            return(GetHIDFeatureRet);
        }