tags:

views:

317

answers:

1

Hi,

I am trying to read data from an RS-232 port. Does anyone have an example of how I get the date 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);

Any help would be most appreciated, as usual.

Thanks, George.

+1  A: 

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.

John Smithers
Does this also cleear out what is in the buffer too or do I have to do that manually ?
George
It's a stream, so you can call `Flush()`. But I don't think you need it. Details here: http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.readexisting.aspx
John Smithers
This is wokring brilliantly, thanks for your help there !
George