System.IO.Ports.SerialPort.Write Method

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

Syntax

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

Parameters

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

Remarks

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.

Requirements

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