System.IO.Ports.SerialPort.Write Method

Writes a specified number of bytes to the serial port using data from a buffer.


public void Write (byte[] buffer, int offset, int count)


The byte array that contains the data to write to the port.
The zero-based byte offset in the buffer parameter at which to begin copying bytes to the port.
The number of bytes to write.


Use this method when you want to write to a byte buffer to create output to a serial port.

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

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


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