예제 #1
0
        ///  <summary>
        ///  Initiates a read operation from a bulk IN endpoint.
        ///  To enable reading without blocking the main thread, uses an asynchronous delegate.
        ///  </summary>
        ///
        ///  <remarks>
        ///  To enable reading more than 64 bytes (with device firmware support), increase bytesToRead.
        ///  </remarks>
        public static void ReadBulkData()
        {
            if (DeviceDetected)
            {
                const uint bytesToRead = BulkBufferSize; // CH1+CH2+CHD+frame number

                //  Define a delegate for the ReadViaBulkTransfer method of WinUsbDevice.
                ReadFromDeviceDelegate myReadFromDeviceDelegate =
                    _usbDevice.ReadViaBulkTransfer;

                //  The BeginInvoke method calls MyWinUsbDevice.ReadViaBulkTransfer to attempt
                //  to read data. The method has the same parameters as ReadViaBulkTransfer,
                //  plus two additional parameters:
                //  GetReceivedBulkData is the callback routine that executes when
                //  ReadViaBulkTransfer returns.
                //  MyReadFromDeviceDelegate is the asynchronous delegate object.

                var readState = new AsyncReadState {
                    Success = false, BytesRead = 0, Data = new byte[BulkBufferSize]
                };


                myReadFromDeviceDelegate.BeginInvoke(
                    Convert.ToByte(_usbDevice.DeviceInfo.BulkInPipe),
                    bytesToRead,
                    ref readState.Data,
                    ref readState.BytesRead,
                    out readState.Success,
                    GetReceivedBulkData,
                    readState
                    );
            }
        }
        ///  <summary>
        ///  Initiates a read operation from a bulk IN endpoint.
        ///  To enable reading without blocking the main thread, uses an asynchronous delegate.
        ///  </summary>
        ///
        ///  <remarks>
        ///  To enable reading more than 64 bytes (with device firmware support), increase bytesToRead.
        ///  </remarks>

        private void ReadDataViaBulkTransfer(Byte pipeID)
        {
            IAsyncResult ar          = null;
            UInt32       bytesRead   = 0;
            UInt32       bytesToRead = Convert.ToUInt32(m_frameBuf.Length);
            Boolean      success     = false;

            //  Define a delegate for the ReadViaBulkTransfer method of WinUsbDevice.

            ReadFromDeviceDelegate MyReadFromDeviceDelegate =
                new ReadFromDeviceDelegate(m_WinUsbDevice.ReadViaBulkTransfer);

            try
            {
                //  The BeginInvoke method calls m_WinUsbDevice.ReadViaBulkTransfer to attempt
                //  to read data. The method has the same parameters as ReadViaBulkTransfer,
                //  plus two additional parameters:
                //  GetReceivedBulkData is the callback routine that executes when
                //  ReadViaBulkTransfer returns.
                //  MyReadFromDeviceDelegate is the asynchronous delegate object.

                ar = MyReadFromDeviceDelegate.BeginInvoke
                         (ref pipeID,
                         bytesToRead,
                         ref m_frameBuf,
                         ref bytesRead,
                         ref success,
                         new AsyncCallback(GetReceivedBulkData),
                         MyReadFromDeviceDelegate);

                if (success)
                {
                    //m_bytesRx += bytesRead;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #3
0
        ///  <summary>
        ///  Initiates a read operation from a bulk IN endpoint.
        ///  To enable reading without blocking the main thread, uses an asynchronous delegate.
        ///  </summary>
        ///  
        ///  <remarks>
        ///  To enable reading more than 64 bytes (with device firmware support), increase bytesToRead.
        ///  </remarks> 
        private void ReadDataViaBulkTransfer(Byte pipeID)
        {
            IAsyncResult ar = null;
            UInt32 bytesRead = 0;
            UInt32 bytesToRead = Convert.ToUInt32(m_frameBuf.Length);
            Boolean success = false;

            //  Define a delegate for the ReadViaBulkTransfer method of WinUsbDevice.

            ReadFromDeviceDelegate MyReadFromDeviceDelegate =
                new ReadFromDeviceDelegate(m_WinUsbDevice.ReadViaBulkTransfer);

            try
            {
                //  The BeginInvoke method calls m_WinUsbDevice.ReadViaBulkTransfer to attempt
                //  to read data. The method has the same parameters as ReadViaBulkTransfer,
                //  plus two additional parameters:
                //  GetReceivedBulkData is the callback routine that executes when
                //  ReadViaBulkTransfer returns.
                //  MyReadFromDeviceDelegate is the asynchronous delegate object.

                ar = MyReadFromDeviceDelegate.BeginInvoke
                    (ref pipeID,
                    bytesToRead,
                    ref m_frameBuf,
                    ref bytesRead,
                    ref success,
                    new AsyncCallback(GetReceivedBulkData),
                    MyReadFromDeviceDelegate);

                if (success)
                {
                    //m_bytesRx += bytesRead;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #4
0
        ///  <summary>
        ///  Initiates a read operation from an interrupt IN endpoint.
        ///  To enable reading without blocking the main thread, uses an asynchronous delegate.
        ///  </summary>
        ///  
        ///  <remarks>
        ///  To enable reading more than 2 bytes (with device firmware support), increase bytesToRead.
        ///  </remarks>
        private void ReadDataViaInterruptTransfer()
        {
            IAsyncResult ar = null;
            Byte[] buffer = new Byte[2];
            UInt32 bytesRead = 0;
            UInt32 bytesToRead = System.Convert.ToUInt32(2);
            Boolean success = false;

            try
            {
                //  Define a delegate for the ReadViaInterruptTransfer method of WinUsbDevice.

                ReadFromDeviceDelegate MyReadFromDeviceDelegate = new ReadFromDeviceDelegate(myWinUsbDevice.ReadViaInterruptTransfer);

                //  The BeginInvoke method calls MyWinUsbDevice.ReadViaInterruptTransfer to attempt
                //  to read data. The method has the same parameters as ReadViaInterruptTransfer,
                //  plus two additional parameters:
                //  GetReceivedInterruptData is the callback routine that executes when
                //  ReadViaInterruptTransfer returns.
                //  MyReadFromDeviceDelegate is the asynchronous delegate object.

                ar = MyReadFromDeviceDelegate.BeginInvoke
                    (System.Convert.ToByte(myWinUsbDevice.myDevInfo.interruptInPipe),
                    bytesToRead,
                    ref buffer,
                    ref bytesRead,
                    ref success,
                    new AsyncCallback(GetReceivedInterruptData),
                    MyReadFromDeviceDelegate);
            }
            catch (Exception ex)
            {
                throw;
            }
        }