Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

SerialPort::Write Method (String^)

 

Writes the specified string to the serial port.

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

public:
void Write(
	String^ text
)

Parameters

text
Type: System::String^

The string for output.

Exception Condition
InvalidOperationException

The specified port is not open.

ArgumentNullException

str is null.

TimeoutException

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
Show:
© 2017 Microsoft