/// <summary> /// Method called when a BG event occured. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BGDataEventHandler(object sender, SerialPort.BGEventArgs e) { switch (e.TypeOfEvent) { case BGEventType.Valid: ParseValid(e.Sentence); break; case BGEventType.CheckSum: ParseCS(e.Sentence); break; case BGEventType.TimeOut: FireTimeOut(); break; case BGEventType.Unknown: BGEventArgs e2 = new BGEventArgs(); e2.TypeOfEvent = e.TypeOfEvent; e2.Sentence = e.Sentence; _NewBG(this, e2); break; default: break; } }
/// <summary> /// Private method for Firing a serialport timeout event /// </summary> private void FireTimeOut() { BGEventArgs e = new BGEventArgs(); e.TypeOfEvent = BGEventType.TimeOut; _NewBG(this, e); }
/// <summary> /// Parse event from BG thread to Parent thread /// </summary> /// <param name="sender">Sender</param> /// <param name="e">BGEventArgs</param> private void BGEventHandler(object sender, BGEventArgs e) { ControlInvoker controlInvoker; controlInvoker = new ControlInvoker(this._Parent); controlInvoker.Invoke(new MethodCallInvoker(ReturnEvent), e); //Send event to parent thread }
/// <summary> /// Fires a NewBG event /// </summary> /// <param name="type">Type of B&G event (Valid, CheckSum, ect...)</param> /// <param name="sentence">Frame </param> private void FireEvent(BGEventType type, byte[] sentence) { if (NewBGData != null) { BGEventArgs e = new BGEventArgs(); e.TypeOfEvent = type; e.Sentence = sentence; try { Control cnt = NewBGData.Target as Control; if (cnt != null && cnt.InvokeRequired) { cnt.BeginInvoke(new NewBGDataHandler(NewBGData), new object[] { this, e }); return; } } catch (Exception ex) { Debug.WriteLine(ex.Message); } NewBGData(this, e); } }
/// <summary> /// Private method for parsing the Valid Frame /// </summary> /// <param name="Valid">Frame</param> private void ParseValid(byte[] frame) { BGEventArgs e = new BGEventArgs(); e.TypeOfEvent = BGEventType.Valid; e.Sentence = frame; _NewBG(this, e); }
/// <summary> /// Private method for parsing the CheckSum Frame /// </summary> /// <param name="CheckSum">Frame</param> private void ParseCS(byte[] frame) { BGEventArgs e = new BGEventArgs(); e.TypeOfEvent = BGEventType.CheckSum; e.Sentence = frame; _NewBG(this, e); }
private void ReturnEvent(Object[] arguments) { BGEventArgs e = (BGEventArgs)arguments[0]; NewBG(this, e); //Fire event back to main application }