Exemple #1
0
        private void allocTransfer(UsbEndpointBase endpointBase, bool ownsTransfer, int isoPacketSize, int count)
        {
            int numIsoPackets = 0;

            if (isoPacketSize > 0)
            {
                numIsoPackets = count / isoPacketSize;
            }
            freeTransfer();
            mTransfer               = MonoUsbTransfer.Alloc(numIsoPackets);
            mOwnsTransfer           = ownsTransfer;
            mTransfer.Type          = endpointBase.Type;
            mTransfer.Endpoint      = endpointBase.EpNum;
            mTransfer.NumIsoPackets = numIsoPackets;

            if (!mCompleteEventHandle.IsAllocated)
            {
                mCompleteEventHandle = GCHandle.Alloc(mTransferCompleteEvent);
            }
            mTransfer.PtrUserData = GCHandle.ToIntPtr(mCompleteEventHandle);

            if (numIsoPackets > 0)
            {
                mTransfer.SetIsoPacketLengths(isoPacketSize);
            }
        }
        private static int libusb_control_transfer(MonoUsbDeviceHandle deviceHandle, MonoUsbControlSetupHandle controlSetupHandle, int timeout)
        {
            MonoUsbTransfer  transfer        = MonoUsbTransfer.Alloc(0);
            ManualResetEvent completeEvent   = new ManualResetEvent(false);
            GCHandle         gcCompleteEvent = GCHandle.Alloc(completeEvent);

            transfer.FillControl(deviceHandle, controlSetupHandle, controlTransferDelegate, GCHandle.ToIntPtr(gcCompleteEvent), timeout);

            int r = (int)transfer.Submit();

            if (r < 0)
            {
                transfer.Free();
                gcCompleteEvent.Free();
                return(r);
            }

            while (!completeEvent.WaitOne(0, false))
            {
                r = MonoUsbApi.HandleEvents(sessionHandle);
                if (r < 0)
                {
                    if (r == (int)MonoUsbError.ErrorInterrupted)
                    {
                        continue;
                    }
                    transfer.Cancel();
                    while (!completeEvent.WaitOne(0, false))
                    {
                        if (MonoUsbApi.HandleEvents(sessionHandle) < 0)
                        {
                            break;
                        }
                    }
                    transfer.Free();
                    gcCompleteEvent.Free();
                    return(r);
                }
            }

            if (transfer.Status == MonoUsbTansferStatus.TransferCompleted)
            {
                r = transfer.ActualLength;
            }
            else
            {
                r = (int)MonoUsbApi.MonoLibUsbErrorFromTransferStatus(transfer.Status);
            }

            transfer.Free();
            gcCompleteEvent.Free();
            return(r);
        }
        private void allocTransfer(UsbEndpointBase endpointBase, bool ownsTransfer, int isoPacketSize, int count)
        {
            int numIsoPackets = 0;

            // Patch for using libusb-1.0 on windows with libusbwK.sys
            EndpointType endpointType = endpointBase.Type;

            if (UsbDevice.IsLinux)
            {
                if (isoPacketSize > 0)
                {
                    numIsoPackets = count / isoPacketSize;
                }
            }
            else
            {
                if (endpointType == EndpointType.Isochronous)
                {
                    endpointType = EndpointType.Bulk;
                }
            }
            ///////////////////////////////////////////////////////////////

            freeTransfer();
            mTransfer               = MonoUsbTransfer.Alloc(numIsoPackets);
            mOwnsTransfer           = ownsTransfer;
            mTransfer.Type          = endpointType;
            mTransfer.Endpoint      = endpointBase.EpNum;
            mTransfer.NumIsoPackets = numIsoPackets;

            if (!mCompleteEventHandle.IsAllocated)
            {
                mCompleteEventHandle = GCHandle.Alloc(mTransferCompleteEvent);
            }
            mTransfer.PtrUserData = GCHandle.ToIntPtr(mCompleteEventHandle);


            if (numIsoPackets > 0)
            {
                mTransfer.SetIsoPacketLengths(isoPacketSize);
            }
        }