Ejemplo n.º 1
0
        /// <summary>
        /// Transmits control data over a default control endpoint.
        /// </summary>
        /// <param name="setupPacket">An 8-byte setup packet which contains parameters for the control request.
        /// See section 9.3 USB Device Requests of the Universal Serial Bus Specification Revision 2.0 for more information. </param>
        /// <param name="buffer">Data to be sent/received from the device.</param>
        /// <param name="bufferLength">Length of the buffer param.</param>
        /// <param name="lengthTransferred">Number of bytes sent or received (depends on the direction of the control transfer).</param>
        /// <returns>True on success.</returns>
        public override bool ControlTransfer(ref UsbSetupPacket setupPacket, IntPtr buffer, int bufferLength, out int lengthTransferred)
        {
            Debug.WriteLine(GetType().Name + ".ControlTransfer() Before", "Libusb-1.0");
            int ret = MonoUsbApi.ControlTransferAsync((MonoUsbDeviceHandle)mUsbHandle,
                                                      setupPacket.RequestType,
                                                      setupPacket.Request,
                                                      setupPacket.Value,
                                                      setupPacket.Index,
                                                      buffer,
                                                      (short)bufferLength,
                                                      UsbConstants.DEFAULT_TIMEOUT);

            Debug.WriteLine(GetType().Name + ".ControlTransfer() Error:" + ((MonoUsbError)ret).ToString(), "Libusb-1.0");
            if (ret < 0)
            {
                UsbError.Error(ErrorCode.MonoApiError, ret, "ControlTransfer Failed", this);
                lengthTransferred = 0;
                return(false);
            }
            lengthTransferred = ret;
            return(true);
        }