Пример #1
0
        /// <summary>
        /// Sets the long value of a Hid feature code.
        /// </summary>
        /// <param name="featureCode">The Hid feature code to set.</param>
        /// <param name="value">The value to set.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public bool HidSetFeature(byte featureCode, long value)
        {
            bool HidSetFeatureRet = default;
            var  hfile            = HidFeatures.OpenHid(this);

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

            mm.Alloc(9L);
            mm.ByteAt(0L)         = featureCode;
            mm.LongAtAbsolute(1L) = value;
            if (!UsbLibHelpers.HidD_SetFeature(hfile, mm, 9))
            {
                HidSetFeatureRet = false;
            }
            else
            {
                HidSetFeatureRet = true;
            }

            HidFeatures.CloseHid(hfile);
            mm.Free();
            return(HidSetFeatureRet);
        }
Пример #2
0
        /// <summary>
        /// Sets the raw byte value of a Hid feature code.
        /// </summary>
        /// <param name="featureCode">The Hid feature code to set.</param>
        /// <param name="value">The value to set.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public bool HidSetFeature(byte featureCode, byte[] value)
        {
            bool HidSetFeatureRet = default;
            var  hfile            = HidFeatures.OpenHid(this);

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

            mm.Alloc(value.Length + 1);
            mm.FromByteArray(value, 1L);
            mm.ByteAt(0L) = featureCode;
            if (!UsbLibHelpers.HidD_SetFeature(hfile, mm, (int)mm.Length))
            {
                HidSetFeatureRet = false;
            }
            else
            {
                HidSetFeatureRet = true;
            }

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