Пример #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(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);
        }
Пример #2
0
        /// <summary>
        /// Opens a HID device for access.
        /// </summary>
        /// <param name="device">The HidDeviceInfo object of the device.</param>
        /// <returns>A handle to the open device (close with CloseHid).</returns>
        /// <remarks></remarks>
        public static IntPtr OpenHid(HidDeviceInfo device)
        {
            IntPtr OpenHidRet = default;

            try
            {
                OpenHidRet = 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);
            }
            catch
            {
                return(IntPtr.Zero);
            }

            return(OpenHidRet);
        }