On Mon, 21 Apr 2008 21:00:23 -0700, Peter Huish <hu***@ozemail.com.au>
wrote:
[...]
When I run the application in the debugger I 17 characters read but when
I do not run with the debugger I get a variable number of characters -
most often 8 and being the first n characters sent.
It is almost like something is interrupting the ReadExisting.
I'm no expert on the SerialPort class, but my reading of the
ReadExisting() method is that it returns immediately, with whatever data
is present. You should not expect it to wait until the end of the
transmission.
Of course this also means it's an error for you to call the
DiscardInBuffer() method, since that will throw away whatever bytes might
have come in after ReadExisting() returned but before you call
DiscardInBuffer(). That sounds like a great recipe for losing data.
So, instead you need to change your logic, so that there's a layer between
the reading of the port and the consumption of the data that handles
delimiting the data.
Pete