/// <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 { HandleDeviceRemoved(); if (OnDeviceRemoved != null) { OnDeviceRemoved(this, new EventArgs()); } Dispose(); throw (ex); } }
/// <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) { // Fire the event handler if assigned if (DataReceived != null) { DataReceived(this, new DataReceivedEventArgs(oInRep)); } }
protected void ReadCompleted(IAsyncResult iResult) { byte[] asyncState = (byte[])iResult.AsyncState; try { this.m_oFile.EndRead(iResult); try { InputReport oInRep = this.CreateInputReport(); oInRep.SetData(asyncState); this.HandleDataReceived(oInRep); } finally { this.BeginAsyncRead(); } } catch (IOException) { this.HandleDeviceRemoved(); if (this.OnDeviceRemoved != null) { this.OnDeviceRemoved(this, new EventArgs()); } this.Dispose(); } }
protected void ReadCompleted(IAsyncResult iResult) { byte[] data = (byte[])iResult.AsyncState; try { this.m_oFile.EndRead(iResult); try { InputReport inputReport = this.CreateInputReport(); inputReport.SetData(data); this.HandleDataReceived(inputReport); } finally { this.BeginAsyncRead(); } } catch (IOException ex) { Console.WriteLine(ex.Message); this.HandleDeviceRemoved(); if (this.OnDeviceRemoved != null) { this.OnDeviceRemoved(this, new EventArgs()); } this.Dispose(); } }
protected override void HandleDataReceived(InputReport oInRep) { if (this.DataRecieved != null) { SpecifiedInputReport report = (SpecifiedInputReport)oInRep; this.DataRecieved(this, new DataRecievedEventArgs(report.Data)); } }
protected override void HandleDataReceived(InputReport oInRep) { // Fire the event handler if assigned if (DataRecieved != null) { SpecifiedInputReport report = (SpecifiedInputReport)oInRep; DataRecieved(this, new DataRecievedEventArgs(report.Data)); } }
protected override void HandleDataReceived(InputReport oInRep) { // Fire the event handler if assigned if (DataRecieved != null) { try { SpecifiedInputReport report = (SpecifiedInputReport)oInRep; string datastring = Utils.ToHexString(report.Data).Substring(2, 80); if (CheckonResult(datastring)) { DataRecieved(this, new DataRecievedEventArgs(Utils.HexToByte(datastring))); } } catch { } } }
/// <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) { }
protected virtual void HandleDataReceived(InputReport oInRep) { }
public DataReceivedEventArgs(InputReport data) { this.data = data; }