System.IO.Ports.SerialPort Members

The members of System.IO.Ports.SerialPort are listed below.

See Also: Inherited members from System.ComponentModel.Component

Public Constructors

Initializes a new instance of the System.IO.Ports.SerialPort class.

Initializes a new instance of the System.IO.Ports.SerialPort class using the specified System.ComponentModel.IContainer object.

Initializes a new instance of the System.IO.Ports.SerialPort class using the specified port name.

Initializes a new instance of the System.IO.Ports.SerialPort class using the specified port name and baud rate.

Initializes a new instance of the System.IO.Ports.SerialPort class using the specified port name, baud rate, and parity bit.

Initializes a new instance of the System.IO.Ports.SerialPort class using the specified port name, baud rate, parity bit, and data bits.

Initializes a new instance of the System.IO.Ports.SerialPort class using the specified port name, baud rate, parity bit, data bits, and stop bit.

Public Fields

const
InfiniteTimeoutint (-1).

Indicates that no time-out should occur.

Public Properties

[read-only]
BaseStreamSystem.IO.Stream.

Gets the underlying System.IO.Stream object for a System.IO.Ports.SerialPort object.

BaudRateint.

Gets or sets the serial baud rate.

BreakStatebool.

Gets or sets the break signal state.

[read-only]
BytesToReadint.

Gets the number of bytes of data in the receive buffer.

[read-only]
BytesToWriteint.

Gets the number of bytes of data in the send buffer.

[read-only]
CDHoldingbool.

Gets the state of the Carrier Detect line for the port.

[read-only]
CtsHoldingbool.

Gets the state of the Clear-to-Send line.

DataBitsint.

Gets or sets the standard length of data bits per byte.

DiscardNullbool.

Gets or sets a value indicating whether null bytes are ignored when transmitted between the port and the receive buffer.

[read-only]
DsrHoldingbool.

Gets the state of the Data Set Ready (DSR) signal.

DtrEnablebool.

Gets or sets a value that enables the Data Terminal Ready (DTR) signal during serial communication.

EncodingSystem.Text.Encoding.

Gets or sets the byte encoding for pre- and post-transmission conversion of text.

HandshakeHandshake.

Gets or sets the handshaking protocol for serial port transmission of data.

[read-only]
IsOpenbool.

Gets a value indicating the open or closed status of the System.IO.Ports.SerialPort object.

NewLinestring.

Gets or sets the value used to interpret the end of a call to the SerialPort.ReadLine and SerialPort.WriteLine(string) methods.

ParityParity.

Gets or sets the parity-checking protocol.

ParityReplacebyte.

Gets or sets the byte that replaces invalid bytes in a data stream when a parity error occurs.

PortNamestring.

Gets or sets the port for communications, including but not limited to all available COM ports.

ReadBufferSizeint.

Gets or sets the size of the System.IO.Ports.SerialPort input buffer.

ReadTimeoutint.

Gets or sets the number of milliseconds before a time-out occurs when a read operation does not finish.

ReceivedBytesThresholdint.

Gets or sets the number of bytes in the internal input buffer before a SerialPort.DataReceived event occurs.

RtsEnablebool.

Gets or sets a value indicating whether the Request to Send (RTS) signal is enabled during serial communication.

StopBitsStopBits.

Gets or sets the standard number of stopbits per byte.

WriteBufferSizeint.

Gets or sets the size of the serial port output buffer.

WriteTimeoutint.

Gets or sets the number of milliseconds before a time-out occurs when a write operation does not finish.

Public Methods

Close()

Closes the port connection, sets the SerialPort.IsOpen property to false, and disposes of the internal System.IO.Stream object.

DiscardInBuffer()

Discards data from the serial driver's receive buffer.

DiscardOutBuffer()

Discards data from the serial driver's transmit buffer.

static
GetPortNames() : string[]

Gets an array of serial port names for the current computer.

Open()

Opens a new serial port connection.

Read(byte[], int, int) : int

Reads a number of bytes from the System.IO.Ports.SerialPort input buffer and writes those bytes into a byte array at the specified offset.

Read(char[], int, int) : int

Reads a number of characters from the System.IO.Ports.SerialPort input buffer and writes them into an array of characters at a given offset.

ReadByte() : int

Synchronously reads one byte from the System.IO.Ports.SerialPort input buffer.

ReadChar() : int

Synchronously reads one character from the System.IO.Ports.SerialPort input buffer.

ReadExisting() : string

Reads all immediately available bytes, based on the encoding, in both the stream and the input buffer of the System.IO.Ports.SerialPort object.

ReadLine() : string

Reads up to the SerialPort.NewLine value in the input buffer.

ReadTo(string) : string

Reads a string up to the specified value in the input buffer.

Write(string)

Writes the specified string to the serial port.

Write(byte[], int, int)

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

Write(char[], int, int)

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

WriteLine(string)

Writes the specified string and the SerialPort.NewLine value to the output buffer.

Protected Methods

override
Dispose(bool)

Releases the unmanaged resources used by the System.IO.Ports.SerialPort and optionally releases the managed resources.

Public Events

DataReceived

Represents the method that will handle the data received event of a System.IO.Ports.SerialPort object.

ErrorReceived

Represents the method that handles the error event of a System.IO.Ports.SerialPort object.

PinChanged

Represents the method that will handle the serial pin changed event of a System.IO.Ports.SerialPort object.