Пример #1
0
            // For Output reports the host sends to the device.
            // Uses interrupt or control transfers depending on the device and OS.

            protected override bool ProtectedWrite(IntPtr hidHandle, byte[] outputReportBuffer)
            {
                // Purpose    : writes an Output report to the device.
                // Accepts    : HIDHandle - a handle to the device.
                //              OutputReportBuffer - contains the report ID and report to send.
                // Returns    : True on success. False on failure.

                int  NumberOfBytesWritten = 0;
                bool Success = false;

                try
                {
                    // The host will use an interrupt transfer if the the HID has an interrupt OUT
                    // endpoint (requires USB 1.1 or later) AND the OS is NOT Windows 98 Gold (original version).
                    // Otherwise the the host will use a control transfer.
                    // The application doesn't have to know or care which type of transfer is used.

                    // ***
                    // API function: WriteFile
                    // Purpose: writes an Output report to the device.
                    // Accepts:
                    // A handle returned by CreateFile
                    // The output report byte length returned by HidP_GetCaps.
                    // An integer to hold the number of bytes written.
                    // Returns: True on success, False on failure.
                    // ***
                    var overlapped = new NativeOverlapped();

                    Success = USBSharp.WriteFile(hidHandle, ref outputReportBuffer[0], outputReportBuffer.Length, ref NumberOfBytesWritten, ref overlapped);
                    if (Success == false)
                    {
                        int err = USBSharp.GetLastError();
                    }
                }
                catch (Exception ex)
                {
                }

                return(Success);
            }