Search code examples
c#serial-portbuffering

C# - readin from serial port buffer


I am trying to read data from an RS-232 port. Does anyone have an example of how I get the data from the port/buffer and make sure that I have all the data as it can be multiline data.

Do I simply read it as follows ?

string Rxstring = port.ReadLine();
Console.WriteLine(Rxstring);

Solution

  • Try this:

    using System.IO.Ports;
    ...
    
    private SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
    
    Console.WriteLine(port.ReadExisting());
    

    Details can be found at Coad's Code.