ReadExisting
reads all data available in the internal input buffer. This might be multiple data sets if the previous read was too long ago and might also be an incomplete last data set.
So you need some kind of detection to differentiate between data sets and if the last data are complete. This depends on the format of your data. Often a data set is terminated by a line feed which can then be used. If so,
ReadLine
can be used instead (and should be used because it makes processing the data much simpler).
But when
ReadLine
does not return, there seems to be no or a different end of line indicator. If there is a different indicator, you can set it using the
SerialPort.NewLine Property (System.IO.Ports)[
^] to let
ReadLine
return when that character is received.
So it depends on the end of line / data set indicator that is used by your sensors.