Export (0) Print
Expand All

SerialPort.Write Method (Char[], Int32, Int32)

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

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

public void Write (
	char[] buffer,
	int offset,
	int count
)
public void Write (
	char[] buffer, 
	int offset, 
	int count
)
public function Write (
	buffer : char[], 
	offset : int, 
	count : int
)
Not applicable.

Parameters

buffer

The character 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 characters to write.

Exception typeCondition

ArgumentNullException

The buffer passed is a null reference (Nothing in Visual Basic).

InvalidOperationException

The specified port is not open.

ArgumentOutOfRangeException

The offset or count parameters are outside a valid region of the buffer being passed. Either offset or count is less than zero.

ArgumentException

offset plus count is greater than the length of the buffer.

TimeoutException

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

Use this method when you want to write to a character buffer to create 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 then 127 as (char)63 or '?'. To support additional characters in that range, set Encoding to UTF8Encoding, UTF32Encoding, or UnicodeEncoding.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft