Exemplo n.º 1
0
        internal Native_Methods.HIDD_ATTRIBUTES DeviceAttributes;//VendorID, ProductID, VersionNumber

        /// <summary>
        ///     Remove any Input reports waiting in the buffer.
        /// </summary>
        ///
        /// <returns> True on success, False on failure. </returns>

        /*
         *  API function:   HidD_FlushQueue
         *  Purpose:    Removes any Input reports waiting in the buffer.
         *  Accepts:    a handle to the device.
         *  Returns:    True on success, False on failure.
         */
        internal Boolean FlushQueue(SafeFileHandle hidHandle)
        {
            try
            {
                Boolean success = Native_Methods.HidD_FlushQueue(hidHandle);
                return(success);
            }
            catch (Exception ex)
            {
                DisplayException(ModuleName, ex);
                throw;
            }
        }
Exemplo n.º 2
0
        ///  <summary>
        ///  Writes an Output report to the device using a control transfer.
        ///  </summary>
        ///
        ///  <returns>
        ///   True on success. False on failure.
        ///  </returns>
        ///

        /*
         *  API function:   HidD_SetOutputReport
         *  Purpose:        Attempts to send an Output report to the device using a control transfer.
         *  Accepts:
         *                  A handle to a HID
         *                  A pointer to a buffer containing the report ID and report
         *                  The size of the buffer.
         *  Returns:        true on success, false on failure.
         */
        internal Boolean SendOutputReportViaControlTransfer(SafeFileHandle hidHandle, Byte[] outputReportBuffer)
        {
            try
            {
                Boolean success = Native_Methods.HidD_SetOutputReport(hidHandle, outputReportBuffer, outputReportBuffer.Length + 1);
                Debug.Print("HidD_SetOutputReport success = " + success);
                return(success);
            }
            catch (Exception ex)
            {
                DisplayException(ModuleName, ex);
                throw;
            }
        }
Exemplo n.º 3
0
        ///  <summary>
        ///  Writes a Feature report to the device.
        ///  </summary>
        ///
        ///  <returns>
        ///   True on success. False on failure.
        ///  </returns>
        ///

        /*
         *  API function:   HidD_SetFeature
         *  Purpose:        Attempts to send a Feature report to the device.
         *  Accepts:
         *                  A handle to a HID
         *                  A pointer to a buffer containing the report ID and report
         *                  The size of the buffer.
         *  Returns:        true on success, false on failure.
         */
        internal Boolean SendFeatureReport(SafeFileHandle hidHandle, Byte[] outFeatureReportBuffer)
        {
            try
            {
                Boolean success = Native_Methods.HidD_SetFeature(hidHandle, outFeatureReportBuffer, outFeatureReportBuffer.Length);
                Debug.Print("HidD_SetFeature success = " + success);
                return(success);
            }
            catch (Exception ex)
            {
                DisplayException(ModuleName, ex);
                throw;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Get HID attributes.
        /// </summary>
        ///
        /// <returns> true on success </returns>
        ///

        /*
         *  API function: HidD_GetAttributes
         *  Purpose:    Retrieves a HIDD_ATTRIBUTES structure containing the Vendor ID,
         *              Product ID, and Product Version Number for a device.
         *  Accepts:
         *              A handle returned by CreateFile.
         *              A pointer to receive a HIDD_ATTRIBUTES structure.
         *  Returns:    True on success, False on failure.
         */
        internal Boolean GetAttributes(SafeFileHandle hidHandle, ref Native_Methods.HIDD_ATTRIBUTES deviceAttributes)
        {
            Boolean success;

            try
            {
                success = Native_Methods.HidD_GetAttributes(hidHandle, ref deviceAttributes);
            }
            catch (Exception ex)
            {
                DisplayException(ModuleName, ex);
                throw;
            }
            return(success);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get the HID-class GUID
        /// </summary>
        ///

        /*
         *  API function:   HidD_GetHidGuid
         *  Purpose:        Retrieves the interface class GUID for the HID class.
         *  Accepts:        A System.Guid object for storing the GUID.
         */
        internal Guid GetHidGuid()
        {
            Guid hidGuid = Guid.Empty;

            try
            {
                Native_Methods.HidD_GetHidGuid(ref hidGuid);
            }
            catch (Exception ex)
            {
                DisplayException(ModuleName, ex);
                throw;
            }
            return(hidGuid);
        }
Exemplo n.º 6
0
        ///  <summary>
        ///  Retrieves a structure with information about a device's capabilities.
        ///  </summary>
        ///
        ///  <returns> An HIDP_CAPS structure. </returns>

        /*
         *  API function:   HidD_GetPreparsedData
         *  Purpose:    Retrieves a pointer to a buffer containing information about the device's capabilities.
         *              HidP_GetCaps and other API functions require a pointer to the buffer.
         *  Requires:
         *              A handle returned by CreateFile.
         *              A pointer to a buffer.
         *  Returns:    True on success, False on failure.
         */
        ///

        /*
         *  API function:   HidP_GetCaps
         *  Purpose:    Find out a device's capabilities.
         *              For standard devices such as joysticks, you can find out the specific capabilities of the device.
         *              For a custom device where the software knows what the device is capable of,this call may be unneeded.
         *  Accepts:
         *              A pointer returned by HidD_GetPreparsedData
         *              A pointer to a HIDP_CAPS structure.
         *  Returns:    True on success, False on failure.
         */
        //

        /*
         *  API function:    HidP_GetValueCaps
         *  Purpose:   Retrieves a buffer containing an array of HidP_ValueCaps structures.
         *             Each structure defines the capabilities of one value.
         *             This application doesn't use this data.
         *  Accepts:
         *              A report type enumerator from hidpi.h,
         *              A pointer to a buffer for the returned array,
         *              The NumberInputValueCaps member of the device's HidP_Caps structure,
         *              A pointer to the PreparsedData structure returned by HidD_GetPreparsedData.
         *  Returns:    True on success, False on failure.
         */
        //

        /*
         *  API function:   HidD_FreePreparsedData
         *  Purpose:        Frees the buffer reserved by HidD_GetPreparsedData.
         *  Accepts:        A pointer to the PreparsedData structure returned by HidD_GetPreparsedData.
         *  Returns:        True on success, False on failure.
         */
        internal Native_Methods.HIDP_CAPS GetDeviceCapabilities(SafeFileHandle hidHandle)
        {
            var preparsedData = new IntPtr();

            try
            {
                Native_Methods.HidD_GetPreparsedData(hidHandle, ref preparsedData);

                Int32 result = Native_Methods.HidP_GetCaps(preparsedData, ref Capabilities);
                if ((result != 0))
                {
                    Debug.WriteLine("");
                    Debug.WriteLine("  Usage: " + Convert.ToString(Capabilities.Usage, 16));
                    Debug.WriteLine("  Usage Page: " + Convert.ToString(Capabilities.UsagePage, 16));
                    Debug.WriteLine("  Input Report Byte Length: " + Capabilities.InputReportByteLength);
                    Debug.WriteLine("  Output Report Byte Length: " + Capabilities.OutputReportByteLength);
                    Debug.WriteLine("  Feature Report Byte Length: " + Capabilities.FeatureReportByteLength);
                    Debug.WriteLine("  Number of Link Collection Nodes: " + Capabilities.NumberLinkCollectionNodes);
                    Debug.WriteLine("  Number of Input Button Caps: " + Capabilities.NumberInputButtonCaps);
                    Debug.WriteLine("  Number of Input Value Caps: " + Capabilities.NumberInputValueCaps);
                    Debug.WriteLine("  Number of Input Data Indices: " + Capabilities.NumberInputDataIndices);
                    Debug.WriteLine("  Number of Output Button Caps: " + Capabilities.NumberOutputButtonCaps);
                    Debug.WriteLine("  Number of Output Value Caps: " + Capabilities.NumberOutputValueCaps);
                    Debug.WriteLine("  Number of Output Data Indices: " + Capabilities.NumberOutputDataIndices);
                    Debug.WriteLine("  Number of Feature Button Caps: " + Capabilities.NumberFeatureButtonCaps);
                    Debug.WriteLine("  Number of Feature Value Caps: " + Capabilities.NumberFeatureValueCaps);
                    Debug.WriteLine("  Number of Feature Data Indices: " + Capabilities.NumberFeatureDataIndices);
                    Int32 vcSize    = Capabilities.NumberInputValueCaps;
                    var   valueCaps = new Byte[vcSize];

                    Native_Methods.HidP_GetValueCaps(Native_Methods.HidP_Input, valueCaps, ref vcSize, preparsedData);
                    // (To use this data, copy the ValueCaps byte array into an array of structures.)
                }
            }
            catch (Exception ex)
            {
                DisplayException(ModuleName, ex);
                throw;
            }
            finally
            {
                if (preparsedData != IntPtr.Zero)
                {
                    Native_Methods.HidD_FreePreparsedData(preparsedData);
                }
            }
            return(Capabilities);
        }// Native_Methods.HIDP_CAPS
Exemplo n.º 7
0
        }// Native_Methods.HIDP_CAPS

        ///  <summary>
        ///  reads a Feature report from the device.
        ///  </summary>
        ///

        /*
         *  API function:   HidD_GetFeature
         *                  Attempts to read a Feature report from the device.
         *  Requires:
         *                  A handle to a HID
         *                  A pointer to a buffer containing the report ID and report
         *                  The size of the buffer.
         *  Returns:        true on success, false on failure.
         */
        internal Boolean GetFeatureReport(SafeFileHandle hidHandle, ref Byte[] inFeatureReportBuffer)
        {
            try
            {
                Boolean success = false;

                if (!hidHandle.IsInvalid && !hidHandle.IsClosed)
                {
                    success = Native_Methods.HidD_GetFeature(hidHandle, inFeatureReportBuffer, inFeatureReportBuffer.Length);
                    Debug.Print("HidD_GetFeature success = " + success);
                }
                return(success);
            }
            catch (Exception ex)
            {
                DisplayException(ModuleName, ex);
                throw;
            }
        }
Exemplo n.º 8
0
        ///  <summary>
        ///  reads an Input report from the device using a control transfer.
        ///  </summary>
        ///

        /*
         *  API function:   HidD_GetInputReport
         *  Purpose:        Attempts to read an Input report from the device using a control transfer.
         *  Requires:
         *                  A handle to a HID
         *                  A pointer to a buffer containing the report ID and report
         *                  The size of the buffer.
         *  Returns:        true on success, false on failure.
         */
        internal Boolean GetInputReportViaControlTransfer(SafeFileHandle hidHandle, ref Byte[] inputReportBuffer)
        {
            var success = false;

            try
            {
                if (!hidHandle.IsInvalid && !hidHandle.IsClosed)
                {
                    success = Native_Methods.HidD_GetInputReport(hidHandle, inputReportBuffer, inputReportBuffer.Length + 1);
                    Debug.Print("HidD_GetInputReport success = " + success);
                }
                return(success);
            }

            catch (Exception ex)
            {
                DisplayException(ModuleName, ex);
                throw;
            }
        }