System.IO.Ports.SerialPort Class

Represents a serial port resource.

See Also: SerialPort Members

Syntax

[System.Diagnostics.MonitoringDescription("")]
public class SerialPort : System.ComponentModel.Component

Remarks

Use this class to control a serial port file resource. This class provides synchronous and event-driven I/O, access to pin and break states, and access to serial driver properties. Additionally, the functionality of this class can be wrapped in an internal System.IO.Stream object, accessible through the SerialPort.BaseStream property, and passed to classes that wrap or use streams.

The System.IO.Ports.SerialPort class supports the following encodings: System.Text.ASCIIEncoding, System.Text.UTF8Encoding, System.Text.UnicodeEncoding, System.Text.UTF32Encoding, and any encoding defined in mscorlib.dll where the code page is less than 50000 or the code page is 54936. You can use alternate encodings, but you must use the SerialPort.ReadByte or SerialPort.Write(Byte[], int, int) method and perform the encoding yourself.

You use the SerialPort.GetPortNames method to retrieve the valid ports for the current computer.

If a System.IO.Ports.SerialPort object becomes blocked during a read operation, do not abort the thread. Instead, either close the base stream or dispose of the System.IO.Ports.SerialPort object.

Requirements

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