|
|
|
@ -17,7 +17,10 @@ namespace RS232Test |
|
|
|
|
private const char STX = (char)0x02; |
|
|
|
|
private const char CR = (char)0x0D; |
|
|
|
|
private const char LF = (char)0x0A; |
|
|
|
|
private string inStream = ""; |
|
|
|
|
|
|
|
|
|
private const string SEPERATOR = "\r\n"; |
|
|
|
|
|
|
|
|
|
private string serialStream = ""; |
|
|
|
|
|
|
|
|
|
private object receiveLock = new object(); |
|
|
|
|
|
|
|
|
@ -119,22 +122,22 @@ namespace RS232Test |
|
|
|
|
if (data.Length < 1) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
inStream = String.Concat(inStream, data); |
|
|
|
|
string message = EqTocReceive(inStream, "\r\n"); |
|
|
|
|
serialStream = String.Concat(serialStream, data); |
|
|
|
|
string packetString = pullPacketString(); |
|
|
|
|
Console.WriteLine(); |
|
|
|
|
EqTocPrint(message); |
|
|
|
|
EqTocPrint(packetString); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private string EqTocReceive(string stream, string seperator) |
|
|
|
|
private string pullPacketString() |
|
|
|
|
{ |
|
|
|
|
int etxIndex = inStream.IndexOf(seperator); |
|
|
|
|
int etxIndex = serialStream.IndexOf(SEPERATOR); |
|
|
|
|
if (etxIndex < 0) |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
string message = inStream.Substring(0, etxIndex); |
|
|
|
|
inStream = inStream.Remove(0, etxIndex + seperator.Length); |
|
|
|
|
string packetString = serialStream.Substring(0, etxIndex); |
|
|
|
|
serialStream = serialStream.Remove(0, etxIndex + SEPERATOR.Length); |
|
|
|
|
|
|
|
|
|
return message; |
|
|
|
|
return packetString; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void EqTocPrint(string message) |
|
|
|
|