/// <summary> /// Callback for above. Care with this as it will be called on the background thread from the async read /// </summary> /// <param name="iResult">Async result parameter</param> 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(); } }
/// <summary> /// virtual handler for any action to be taken when data is received. Override to use. /// </summary> /// <param name="oInRep">The input report that was received</param> protected virtual void HandleDataReceived(InputReport oInRep) { }