Share via


SerialPort.Write Method

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

Namespace: System.IO.Ports
Assembly: Microsoft.SPOT.Hardware (in microsoft.spot.hardware.dll)

Syntax

[MethodImplAttribute(InternalCall)]
public int 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.

Return Value

The number of bytes written.

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 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.

Version Information

Available in the .NET Micro Framework versions 3.0, 4.0, 4.1, and 4.2.

See Also

Reference

SerialPort Class
SerialPort Members
System.IO.Ports Namespace