tags:

views:

979

answers:

1

I am working with serial ports c#, CF 2.0

Can this function be trusted to return 0 when there is nothing to read?

while (_sp.BytesToRead > 0)
{
    char[] buffer = new char[255];
    int bytes_read = _sp.Read(buffer, 0, buffer.Length);

    for (int i = 0; i < bytes_read; i++)
    {
        value += buffer[i];
    }


}
ProcessValue(value);

what I want to do it read the data until there are no more bytes to read. _sp is an instance of SerialPort class

+1  A: 

Yes. However, it may throw an exception - so be sure to handle that. See MSDN.

Jon B