LitDev.Engines.HIDDevice.ReadCompleted C# (CSharp) Method

ReadCompleted() protected method

Callback for above. Care with this as it will be called on the background thread from the async read
protected ReadCompleted ( IAsyncResult iResult ) : void
iResult IAsyncResult Async result parameter
return void
        protected void ReadCompleted(IAsyncResult iResult)
        {
            byte[] arrBuff = (byte[])iResult.AsyncState;	// retrieve the read buffer
            try
            {
                m_oFile.EndRead(iResult);	// call end read : this throws any exceptions that happened during the read
                try
                {
                    InputReport oInRep = CreateInputReport();	// Create the input report for the device
                    oInRep.SetData(arrBuff);	// and set the data portion - this processes the data received into a more easily understood format depending upon the report type
                    HandleDataReceived(oInRep);	// pass the new input report on to the higher level handler
                }
                finally
                {
                    BeginAsyncRead();	// when all that is done, kick off another read for the next report
                }
            }
            catch (IOException ex)	// if we got an IO exception, the device was removed
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                HandleDeviceRemoved();
                if (OnDeviceRemoved != null)
                {
                    OnDeviceRemoved(this, new EventArgs());
                }
                Dispose();
            }
        }