From 74f81bea9ec5992a1c4f1f67b22777ce99bca4a2 Mon Sep 17 00:00:00 2001 From: The6P4C Date: Fri, 29 Sep 2017 11:05:37 +1000 Subject: [PATCH] Ensure greater than zero DLEs are seen before an ETX to signify the end of a packet --- ThunderboltTimeSync/ThunderboltSerialPort.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ThunderboltTimeSync/ThunderboltSerialPort.cs b/ThunderboltTimeSync/ThunderboltSerialPort.cs index 3210a7e..1d262e4 100644 --- a/ThunderboltTimeSync/ThunderboltSerialPort.cs +++ b/ThunderboltTimeSync/ThunderboltSerialPort.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics; using System.IO.Ports; namespace ThunderboltTimeSync { @@ -85,6 +86,8 @@ namespace ThunderboltTimeSync { bool inStuffedDLE = false; foreach (byte b in data) { + Debug.WriteLine(string.Format("{0:X2}", b)); + if (b == CHAR_DLE) { if (!inStuffedDLE) { newData.Add(b); @@ -148,8 +151,8 @@ namespace ThunderboltTimeSync { } } - // Odd number of DLEs means the ETX does in fact signify the end of the packet - if (numberOfPrecedingDLEs % 2 == 1) { + // Odd number (greater than zero) of DLEs means the ETX does in fact signify the end of the packet + if (numberOfPrecedingDLEs % 2 == 1 && numberOfPrecedingDLEs > 0) { ProcessPacket(); packetBuffer.Clear();