/// <summary> /// Thread function of read data buffer /// </summary> void ReadThread() { var rxEventArgs = new DataRxEventArgs(); do { if (_serial.BytesToRead > 0) { rxEventArgs.Data = (byte)_serial.ReadByte(); DataRxEvent(this, rxEventArgs); } else { Thread.Sleep(10); } } while (true); }
/// <summary> /// 数据到达时候的事件处理函数. /// </summary> /// <param name="o">O.</param> /// <param name="e">E.</param> void OnDataRxEvent(object o, DataRxEventArgs e) { if (_isLineBreak(e.Data)) { _index = 0; _preByte = null; if ("nt" == _lineBreak.Type) { _list.RemoveAt(_list.Count - 1); } if ("length" == _lineBreak.Type) { _list.Add(e.Data); } DataListReadyEvent(this, new DataListReadyEventArgs(_list)); _list = new List <byte>(); } else { _index++; _preByte = e.Data; _list.Add(e.Data); } }