public void ListenLoop(CancellationToken cancellationToken) { var msg = new SerialMonitorMessage(); var receivedTime = DateTime.UtcNow; while (!cancellationToken.IsCancellationRequested) { var bt = ReadByte(); var now = DateTime.UtcNow; var delta = now - receivedTime; if (delta > _threshold || _flush) { _flush = false; if (!msg.Empty) { Notify(msg); msg = new SerialMonitorMessage(); } } if (bt.HasValue) { receivedTime = DateTime.UtcNow; msg.Content.Append((char)bt); Notify(msg); } } }
private void Notify(SerialMonitorMessage msg) { _callback(msg); }