SerialPort.Write Method (String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Writes the specified string to the serial port.

Namespace:   System.IO.Ports
Assembly:  System (in System.dll)

public void Write(
	string text


Type: System.String

The string for output.

Exception Condition

The specified port is not open.


str is null.


The operation did not complete before the time-out period ended.

Use this method when you want to write a string as output to a serial port.

If there are too many bytes in the output buffer and Handshake is set to XOnXOff then the SerialPort object may raise a TimeoutException while it waits for the device to be ready to accept more data.

By default, SerialPort uses ASCIIEncoding to encode the characters. ASCIIEncoding encodes all characters greater than 127 as (char)63 or '?'. To support additional characters in that range, set Encoding to UTF8Encoding, UTF32Encoding, or UnicodeEncoding.

.NET Framework
Available since 2.0
Return to top