Why are you zeroing out the timer value when it reaches 1000? Why not for the test at least just let it count up.
//if (Globals.Tags.timer.Value++ == 1000)
Globals.Tags.timer.Value = 0;
_bufferReceiveLength = _serialPort.BytesToRead;
if (_bufferReceiveLength > 0)
//We have data, but we will not read it unless it is less than
// '_bufferReceiveLength < _serialPort.ReadBufferSize'
//Why not read the data? Why wait for it to be less than ReadBufferSize?
if (_bufferReceiveLength < _serialPort.ReadBufferSize)
_serialPort.Read(_bufferReceive, 0, _bufferReceiveLength);
Try this code instead of the above:
serialPort.ReadTimeout = 25;
//Check to make sure we have data to read in
if(serialPort.BytesToRead > 0)
//Looks like we have data.
//Now it is possible for the amount of data we have to be larger than the
if(serialPort.BytesToRead > serialPort.ReadBufferSize)
//Only read in the ReadBufferSize, not more!
serialPort.Read(buffer, 0, serialPort.ReadBufferSize);
serialPort.Read(buffer, 0, serialPort.BytesToRead);
"Because the BytesToRead property represents both the SerialPort buffer and the Windows-created buffer, it can return a greater value than the ReadBufferSize property, which represents only the Windows-created buffer."