Endpoint members common to Read, Write, Bulk, and Interrupt T:LibUsbDotNet.Main.EndpointType.
Inheritance: IDisposable
 public override bool WritePipe(UsbEndpointBase endPointBase, IntPtr pBuffer, int bufferLength, out int lengthTransferred, int isoPacketSize, IntPtr pOverlapped)
 {
     //var fileHandle = (SafeFileHandle)endPointBase.Device.Handle;
     //var file = new FileStream(handle, FileAccess.ReadWrite, 65, true);
     //    file.Write(output, 0, bufferLength+1);
    var res = Kernel32.WriteFile(endPointBase.Device.Handle, pBuffer, bufferLength, out lengthTransferred, pOverlapped);
     
     return res > 0;
         //return Hid.NativeMethods.HidD_SetOutputReport(, pBuffer, bufferLength);
 }
Esempio n. 2
0
 public UsbStreamAsyncTransfer(UsbEndpointBase usbEndpoint,
                               byte[] buffer,
                               int offset,
                               int count,
                               AsyncCallback callback,
                               object state,
                               int timeout)
 {
     mUsbEndpoint = usbEndpoint;
     mOffset = offset;
     mCount = count;
     mState = state;
     mTimeout = timeout;
     mCallback = callback;
     mGCBuffer = GCHandle.Alloc(buffer, GCHandleType.Pinned);
 }
Esempio n. 3
0
 public UsbStreamAsyncTransfer(UsbEndpointBase usbEndpoint,
                               byte[] buffer,
                               int offset,
                               int count,
                               AsyncCallback callback,
                               object state,
                               int timeout)
 {
     mUsbEndpoint = usbEndpoint;
     mOffset      = offset;
     mCount       = count;
     mState       = state;
     mTimeout     = timeout;
     mCallback    = callback;
     mGCBuffer    = GCHandle.Alloc(buffer, GCHandleType.Pinned);
 }
Esempio n. 4
0
        /// <summary>
        /// Creates a new transfer queue instance.
        /// </summary>
        /// <param name="endpointBase">The endpoint to transfer data to/from.</param>
        /// <param name="maxOutstandingIO">The number of transfers to <see cref="UsbTransfer.Submit"/> before waiting for a completion.</param>
        /// <param name="bufferSize">The size of each data buffer.</param>
        /// <param name="timeout">The maximum time to wait for each transfer.</param>
        /// <param name="isoPacketSize">For isochronous use only.  The iso packet size.  If 0, the endpoints max packet size is used.</param>
        public UsbTransferQueue(UsbEndpointBase endpointBase, int maxOutstandingIO, int bufferSize, int timeout, int isoPacketSize)
        {
            EndpointBase     = endpointBase;
            IsoPacketSize    = isoPacketSize;
            Timeout          = timeout;
            BufferSize       = bufferSize;
            MaxOutstandingIO = maxOutstandingIO;

            mTransferHandles = new Handle[maxOutstandingIO];

            mBuffer = new byte[maxOutstandingIO][];
            for (int i = 0; i < maxOutstandingIO; i++)
            {
                mBuffer[i] = new byte[bufferSize];
            }

            IsoPacketSize = isoPacketSize > 0 ? isoPacketSize : endpointBase.EndpointInfo.Descriptor.MaxPacketSize;
        }
        private void allocTransfer(UsbEndpointBase endpointBase, bool ownsTransfer, int isoPacketSize, int count)
        {
            int numIsoPackets = 0;
            if (isoPacketSize > 0)
                numIsoPackets = count/isoPacketSize;
            freeTransfer();
            mTransfer = LibUsbTransfer.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);


        }
 /// <summary></summary>
 protected UsbTransfer(UsbEndpointBase endpointBase)
 {
     mEndpointBase = endpointBase;
 }
        /// <summary>
        /// Creates a new transfer queue instance.
        /// </summary>
        /// <param name="endpointBase">The endpoint to transfer data to/from.</param>
        /// <param name="maxOutstandingIO">The number of transfers to <see cref="UsbTransfer.Submit"/> before waiting for a completion.</param>
        /// <param name="bufferSize">The size of each data buffer.</param>
        /// <param name="timeout">The maximum time to wait for each transfer.</param>
        /// <param name="isoPacketSize">For isochronous use only.  The iso packet size.  If 0, the endpoints max packet size is used.</param>
        public UsbTransferQueue(UsbEndpointBase endpointBase, int maxOutstandingIO, int bufferSize, int timeout, int isoPacketSize)
        {
            EndpointBase = endpointBase;
            IsoPacketSize = isoPacketSize;
            Timeout = timeout;
            BufferSize = bufferSize;
            MaxOutstandingIO = maxOutstandingIO;

            mTransferHandles = new Handle[maxOutstandingIO];

            mBuffer = new byte[maxOutstandingIO][];
            for(int i=0; i < maxOutstandingIO; i++)
                mBuffer[i] = new byte[bufferSize];

            IsoPacketSize = isoPacketSize > 0 ? isoPacketSize : endpointBase.EndpointInfo.Descriptor.MaxPacketSize;
        }
 public MonoUsbTransferContext(UsbEndpointBase endpointBase)
     : base(endpointBase)
 {
 }
 protected TransferContextBase(UsbEndpointBase endpointBase)
 {
     mEndpointBase = endpointBase;
 }
 public OverlappedTransferContext(UsbEndpointBase endpointBase)
     : base(endpointBase)
 {
 }
Esempio n. 11
0
 public UsbStream(UsbEndpointBase usbEndpoint)
 {
     mUsbEndpoint = usbEndpoint;
 }
        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);
        }
Esempio n. 13
0
 public UsbStream(UsbEndpointBase usbEndpoint) { mUsbEndpoint = usbEndpoint; }
Esempio n. 14
0
        private static void FillEndpointInfo(TreeNode tvEndpoint, UsbEndpointBase i)
        {
            tvEndpoint.Nodes.Add(string.Format("{0}: {1}", "Endpoint Number", i.EpNum));
            tvEndpoint.Nodes.Add(string.Format("{0}: {1} (0x{2:X2})", "Type", i.Type, (int)i.Type));

            FillEndpointInfo(tvEndpoint, i.EndpointInfo);
        }
Esempio n. 15
0
        //public abstract bool WritePipe(UsbEndpointBase endPointBase,
        //                               Byte[] buffer,
        //                               int bufferLength,
        //                               out int lengthTransferred,
        //                               int isoPacketSize,
        //                               IntPtr pOverlapped);

        public abstract bool WritePipe(UsbEndpointBase endPointBase,
                                       IntPtr pBuffer,
                                       int bufferLength,
                                       out int lengthTransferred,
                                       int isoPacketSize,
                                       IntPtr pOverlapped);
Esempio n. 16
0
 /// <summary></summary>
 protected UsbTransfer(UsbEndpointBase endpointBase)
 {
     mEndpointBase = endpointBase;
 }
Esempio n. 17
0
        //public override bool WritePipe(UsbEndpointBase endPointBase,
        //                               byte[] Buffer,
        //                               int BufferLength,
        //                               out int LengthTransferred,
        //                               int isoPacketSize,
        //                               IntPtr pOVERLAPPED) { return WinUsb_WritePipe(endPointBase.Device.Handle, endPointBase.EpNum, Buffer, BufferLength, out LengthTransferred, pOVERLAPPED); }

        public override bool WritePipe(UsbEndpointBase endPointBase,
                                       IntPtr pBuffer,
                                       int BufferLength,
                                       out int LengthTransferred,
                                       int isoPacketSize,
                                       IntPtr pOVERLAPPED) { return WinUsb_WritePipe(endPointBase.Device.Handle, endPointBase.EpNum, pBuffer, BufferLength, out LengthTransferred, pOVERLAPPED); }
 public UsbCommand(UsbEndpointBase ep, byte[] buffer, int timeout)
 {
     this.endPoint = ep;
     this.buffer = buffer;
     this.timeout = timeout;
     this.bytesReadOrWritten = -1;
     this.executed = false;
     this.resultCode = ErrorCode.None;
     this.result = null;
 }
Esempio n. 19
0
        public override bool ReadPipe(UsbEndpointBase endPointBase,
                                      IntPtr buffer,
                                      int bufferLength,
                                      out int lengthTransferred,
                                      int isoPacketSize,
                                      IntPtr pOverlapped)
        {
            LibUsbRequest req = new LibUsbRequest();
            req.Endpoint.ID = endPointBase.EpNum;
            req.Endpoint.PacketSize = isoPacketSize;
            req.Timeout = UsbConstants.DEFAULT_TIMEOUT;

            int cltCode = endPointBase.Type == EndpointType.Isochronous ? LibUsbIoCtl.ISOCHRONOUS_READ : LibUsbIoCtl.INTERRUPT_OR_BULK_READ; 


            return Kernel32.DeviceIoControl(endPointBase.Device.Handle,
                                            cltCode,
                                            req,
                                            LibUsbRequest.Size,
                                            buffer,
                                            bufferLength,
                                            out lengthTransferred,
                                            pOverlapped);
        }
 public override bool ReadPipe(UsbEndpointBase endPointBase, IntPtr pBuffer, int bufferLength, out int lengthTransferred, int isoPacketSize, IntPtr pOverlapped)
 {
     var res = Kernel32.ReadFile(endPointBase.Device.Handle, pBuffer, bufferLength, out lengthTransferred, pOverlapped);
     return res > 0;
 }