Пример #1
0
        /// <summary>
        /// Returns the short value of a Hid feature code.
        /// </summary>
        /// <param name="featureCode">The Hid feature code to retrieve.</param>
        /// <param name="result">Receives the result of the operation.</param>
        /// <returns>True if successful.</returns>
        /// <remarks></remarks>
        public bool HidGetFeature(byte featureCode, ref short result)
        {
            bool HidGetFeatureRet = default;
            var  hfile            = HidFeatures.OpenHid(this);

            if (hfile == IntPtr.Zero)
            {
                return(false);
            }
            var mm = new MemPtr();

            mm.Alloc(3L);
            mm.ByteAt(0L) = featureCode;
            if (!UsbLibHelpers.HidD_GetFeature(hfile, mm, 3))
            {
                HidGetFeatureRet = false;
            }
            else
            {
                HidGetFeatureRet = true;
                result           = mm.ShortAtAbsolute(1L);
            }

            mm.Free();
            HidFeatures.CloseHid(hfile);
            return(HidGetFeatureRet);
        }
Пример #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(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);
        }
Пример #3
0
        /// <summary>
        /// Returns the raw byte data for a Hid feature code.
        /// </summary>
        /// <param name="featureCode">The Hid feature code to retrieve.</param>
        /// <param name="result">Receives the result of the operation.</param>
        /// <param name="expectedSize">The expected size, in bytes, of the result.</param>
        /// <returns>True if successful.</returns>
        /// <remarks></remarks>
        public bool HidGetFeature(byte featureCode, ref byte[] result, int expectedSize)
        {
            bool HidGetFeatureRet = default;
            var  hfile            = HidFeatures.OpenHid(this);

            if (hfile == IntPtr.Zero)
            {
                return(false);
            }
            var mm = new MemPtr();

            mm.Alloc(expectedSize + 1);
            mm.ByteAt(0L) = featureCode;
            if (!UsbLibHelpers.HidD_GetFeature(hfile, mm, expectedSize))
            {
                HidGetFeatureRet = false;
            }
            else
            {
                HidGetFeatureRet = true;
                result           = mm.ToByteArray(1L, expectedSize);
            }

            HidFeatures.CloseHid(hfile);
            mm.Free();
            return(HidGetFeatureRet);
        }