/// <summary> /// Fired when data has been received over USB /// </summary> /// <param name="oInRep">Input report received</param> protected override void HandleDataReceived(InputReport oInRep) { // Fire the event handler if assigned if (OnButtonChanged != null) { BuzzInputReport oBuzIn = (BuzzInputReport)oInRep; OnButtonChanged(this, new BuzzButtonChangedEventArgs(oBuzIn.Buttons, this.BuzzerIndex)); } }
/// <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) { if (m_oFile == null) { // We've already disposed this object, don't do anymore reading return; } 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) // if we got an IO exception, the device was removed { HandleDeviceRemoved(); if (OnDeviceRemoved != null) { OnDeviceRemoved(this, new EventArgs()); } Dispose(); } catch (Exception) { // Ignore other types of errors } }
/// <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) { }