sarsnake
sarsnake

Reputation: 27703

Serial port. BytesToRead() function

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

Upvotes: 2

Views: 4508

Answers (1)

user27414
user27414

Reputation:

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

Upvotes: 1

Related Questions