Jon,
1) let me first thank you for your excellent article about thread
synchronization
http://www.yoda.arachsys.com/csharp/threads
a must read! It is stuff like this that drives .NET foreward into production
environments.
2) you are concerned about
myPort.Encoding = System.Text.Encoding.UTF8 'support 8 bits
per byte transparent!
well the problem with SerialPort class is that it is not intended to handle
raw bytes - or it is not documented at all.
*** the line above is the official answer by Microsoft given on their
feedback pages for VS.2005 as the only way to read bytes transparently!!! ***
another hint from the german newsgroups was:
use
Encoding.GetEncoding(28591) which is equivalent to
Encoding.GetEncoding(„ISO-8859-1“)
to read bytes transparently.
my comment: it's a mess!
3) you want to know what "phantom data" means.
my app reads a single byte, which is the message ID, then upon this decides
how many more bytes to read because of the message length being constant
depending on the message ID.
Therefore the remaining message was originally read in using Read(bytearray,
offset, length) , which failed then converted to a FOR NEXT loop using
ReadByte.
as it turned out, Read(bytearray, offset, length) reads the data correctly.
In my case this is 5 bytes.
yet afterwards, the next ReadByte() returns one or more bytes from the end
of the previous message, which the app already received.
It's like read(bytearraym,offset, length) does not remove the data from the
input-buffer (whatever and wherever it is).
The funny thing is: the number of phantom bytes varies. It happens however
very often.
I can send you a screenshot showing both my application's output as well as
the output of a RS.232 tracer.
Note: I have this problem both with physical COM ports as well as virtual
COM ports (USB adapter). And I only run at 9600 baud, as a higher speed is
not recommended by USB adapter manufacturers. Why by the way?
thanks
herbert