예제 #1
0
 ///<summary>
 ///Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 ///</summary>
 public void Dispose()
 {
     if (!mbDisposed)
     {
         if (GetType() == typeof(UsbEndpointReader))
         {
             UsbEndpointReader reader = (UsbEndpointReader)this;
             if (reader.DataReceivedEnabled)
             {
                 reader.DataReceivedEnabled = false;
             }
             System.Windows.Forms.Application.DoEvents();
         }
         System.Windows.Forms.Application.DoEvents();
         freeAsync(mTransferContext);
         System.Windows.Forms.Application.DoEvents();
         mUsbDevice.ActiveEndpoints.removeFromList(this);
         System.Windows.Forms.Application.DoEvents();
         mbDisposed = true;
     }
 }
예제 #2
0
        private void ReadData(object obj)
        {
            int               ret             = 0;
            TransferContext   transferContext = (TransferContext)obj;
            UsbEndpointReader reader          = (UsbEndpointReader)transferContext.mEndpointBase;

            reader.mDataReceivedEnabled = true;

            try
            {
                while (ret >= 0 && !reader.mEventCancelReadThread.WaitOne(0, false))
                {
                    lock (oLockTransferContext)
                        transferContext.Reset();

                    ret = setupAsync(transferContext);

                    if (ret >= 0)
                    {
                        bool bContinue = true;
                        while (bContinue)
                        {
                            ret = submitAsync(transferContext);
                            if (ret >= 0)
                            {
ReapRetry:
                                ret = reapAsyncNoCancel(transferContext);

                                if (ret < 0)
                                {
                                    if (ret == (int)ErrorCodes.ETIMEDOUT)
                                    {
                                        if (!transferContext.mbAsyncCancelled && !reader.mEventCancelReadThread.WaitOne(0, false))
                                        {
                                            goto ReapRetry;
                                        }
                                        else
                                        {
                                            ret = (int)ErrorCodes.EINTR;
                                        }
                                    }
                                }
                            }

                            lock (oLockTransferContext)
                                bContinue = ((transferContext.mCurrentRemaining > 0) && (ret == transferContext.mRequested));
                        }

                        freeAsync(transferContext);
                    }

                    if (ret >= 0)
                    {
                        EventHandler <DataReceivedArgs> temp = reader.DataReceived;
                        if (temp != null)
                        {
                            temp(this, new DataReceivedArgs(transferContext.Buffer, transferContext.currentTransmitted));
                        }
                    }
                }
            }
            catch (ThreadAbortException)
            {
                Debug.Print("ThreadAbortException:" + GetType().FullName + ".ReadData");
            }
            finally
            {
                if (transferContext.mContext.IsValid)
                {
                    freeAsync(transferContext);
                }

                reader.mDataReceivedEnabled = false;
                reader.TransferLock.Release();
            }
        }
예제 #3
0
파일: UsbDevice.cs 프로젝트: zoobab/CH554
        /// <summary>
        /// Opens an endpoint for reading
        /// </summary>
        /// <param name="readEndpoint">Endpoint number for read operations.</param>
        /// <param name="readBufferSize">Size of the read buffer allocated for the <see cref="UsbEndpointReader.DataReceived"/> event.</param>
        /// <returns>A <see cref="UsbEndpointReader"/> class ready for reading.
        /// If the specified endpoint has allready been opened, the original <see cref="UsbEndpointReader"/> object will be returned.
        /// </returns>
        public UsbEndpointReader OpenInterruptEndpointReader(ReadEndpoints readEndpoint, int readBufferSize)
        {
            UsbEndpointReader epNew = new UsbEndpointReader(this, EndpointTypes.Interrupt, 0, readBufferSize, readEndpoint);

            return((UsbEndpointReader)mActiveEndpoints.Add(epNew));
        }
예제 #4
0
파일: UsbDevice.cs 프로젝트: zoobab/CH554
        /// <summary>
        /// Opens an endpoint for reading
        /// </summary>
        /// <param name="readEndpoint">Endpoint number for read operations.</param>
        /// <returns>A <see cref="UsbEndpointReader"/> class ready for reading.
        /// If the specified endpoint has allready been opened, the original <see cref="UsbEndpointReader"/> object will be returned.
        /// </returns>
        public UsbEndpointReader OpenInterruptEndpointReader(ReadEndpoints readEndpoint)
        {
            UsbEndpointReader epNew = new UsbEndpointReader(this, EndpointTypes.Interrupt, 0, UsbEndpointReader.DEF_READ_BUFFER_SIZE, readEndpoint);

            return((UsbEndpointReader)mActiveEndpoints.Add(epNew));
        }
예제 #5
0
파일: UsbDevice.cs 프로젝트: zoobab/CH554
        /// <summary>
        /// Opens an endpoint for reading
        /// </summary>
        /// <param name="readEndpoint">Endpoint number for read operations.</param>
        /// <param name="readBufferSize">Size of the read buffer allocated for the <see cref="UsbEndpointReader.DataReceived"/> event.</param>
        /// <param name="endPointType">One of the <see cref="EndpointTypes"/> enumerations.</param>
        /// <param name="packetSize">The packet size to use when endPointType is set to <see cref="EndpointTypes.Isochronous"/>.</param>
        /// <returns>A <see cref="UsbEndpointReader"/> class ready for reading.
        /// If the specified endpoint has allready been opened, the original <see cref="UsbEndpointReader"/> object will be returned.
        /// </returns>
        public UsbEndpointReader OpenEndpointReader(ReadEndpoints readEndpoint, int readBufferSize, EndpointTypes endPointType, int packetSize)
        {
            UsbEndpointReader epNew = new UsbEndpointReader(this, endPointType, packetSize, readBufferSize, readEndpoint);

            return((UsbEndpointReader)mActiveEndpoints.Add(epNew));
        }