Search code examples
c#winformsserial-port

In serialport communication, data is received multiple times


I made a loopback with TX and RX and tested it with one COM3 port.

serialport.DataReceived += (sender, e) =>
{
  var data = serialport.ReadExisting();
  readRichTextBox.AppendText($"{data}\n"); // Cross-Thread Possibility
}

With \n you can see that the data is received multiple times.

ex) Input hello and hi

h
e
l
l
o
h
i

serialport is the default state.

Expects a result value like this:

hello
hi

Solution

  • I'd say use serialPort.ReadLine() instead of ReadExisting().