i'm reading a rs232 port and i call the readexisting:
string x = port.ReadExisting();
string y;
if(x.Contains("\r"))
{
do something;
}
else
{
y = x + port.ReadExisting();
}
this doesn't keep looping. i want it to keep reading the port and concatenating the string until the port sends a "\r" character. how should i do this?

2 answers
thanks vulpes, i used a while loop.
answered one year ago by:
237
I'd just use port.ReadLine() which will block until (by default) "\r\n" is received.
If you're only expecting "\r" then change the port's NewLine property to that.
ReadLine() doesn't return the Newline characters themselves but they are removed from the input buffer.
To avoid blocking indefinitely, you can set the port's ReadTimeout property to a reasonable value and catch the resulting TimeoutException:
answered one year ago by:
17279