System.IO.Ports.SerialPort.ReadExisting Method

Reads all immediately available bytes, based on the encoding, in both the stream and the input buffer of the System.IO.Ports.SerialPort object.

Syntax

public string ReadExisting ()

Returns

The contents of the stream and the input buffer of the System.IO.Ports.SerialPort object.

Remarks

This method returns the contents of the stream and internal buffer of the System.IO.Ports.SerialPort object as a string. This method does not use a time-out. Note that this method can leave trailing lead bytes in the internal buffer, which makes the SerialPort.BytesToRead value greater than zero.

If it is necessary to switch between reading text and reading binary data from the stream, select a protocol that carefully defines the boundary between text and binary data, such as manually reading bytes and decoding the data.

Note:

The System.IO.Ports.SerialPort class buffers data, but the stream object contained in the SerialPort.BaseStream property does not. Therefore, the System.IO.Ports.SerialPort object and the stream object might differ on the number of bytes that are available to read. When bytes are buffered to the System.IO.Ports.SerialPort object, the SerialPort.BytesToRead property includes these bytes in its value; however, these bytes might not be accessible to the stream contained in the SerialPort.BaseStream property.

Requirements

Namespace: System.IO.Ports
Assembly: System (in System.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0