SerialPort Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Represents a serial port resource.

Namespace:  System.IO.Ports
Assembly:  Microsoft.SPOT.Hardware.SerialPort (in Microsoft.SPOT.Hardware.SerialPort.dll)

public ref class SerialPort : public Stream

The SerialPort type exposes the following members.

  NameDescription
Public methodSerialPort(String)Initializes a new instance of the SerialPort class using the specified port name.
Public methodSerialPort(String, Int32)Initializes a new instance of the SerialPort class using the specified port name and baud rate.
Public methodSerialPort(String, Int32, Parity)Initializes a new instance of the SerialPort class using the specified port name, baud rate, and parity bit.
Public methodSerialPort(String, Int32, Parity, Int32)Initializes a new instance of the SerialPort class using the specified port name, baud rate, parity bit, and data bits.
Public methodSerialPort(String, Int32, Parity, Int32, StopBits)Initializes a new instance of the SerialPort class using the specified port name, baud rate, parity bit, data bits, and stop bit.
Top

  NameDescription
Public propertyBaseStreamGets the underlying Stream object for a SerialPort object.
Public propertyBaudRateGets or sets the serial baud rate.
Public propertyBytesToReadGets the number of bytes of data in the receive buffer.
Public propertyBytesToWriteGets the number of bytes of data in the send buffer.
Public propertyCanReadGets a value indicating whether the current stream supports reading. (Overrides Stream..::..CanRead.)
Public propertyCanSeekGets a value indicating whether the current stream supports seeking. (Overrides Stream..::..CanSeek.)
Public propertyCanTimeoutGets a value that indicates whether the current stream can time out. (Overrides Stream..::..CanTimeout.)
Public propertyCanWriteGets a value that indicates whether the current stream supports writing. (Overrides Stream..::..CanWrite.)
Public propertyDataBitsGets or sets the standard length of data bits per byte.
Public propertyHandshakeGets or sets the handshaking protocol for serial port transmission of data.
Public propertyIsOpenGets a value indicating the open or closed status of the SerialPort object.
Public propertyLengthGets the length in bytes of the stream. (Overrides Stream..::..Length.)
Public propertyParityGets or sets the parity-checking protocol.
Public propertyPortNameGets or sets the port for communications, including but not limited to all available COM ports.
Public propertyPositionGets or sets the position in the current stream. (Overrides Stream..::..Position.)
Public propertyReadTimeoutGets or sets the number of milliseconds before a time-out occurs when a read operation does not finish. (Overrides Stream..::..ReadTimeout.)
Public propertyStopBitsGets or sets the standard number of stopbits per byte.
Public propertyWriteTimeoutGets or sets the number of milliseconds before a time-out occurs when a write operation does not finish. (Overrides Stream..::..WriteTimeout.)
Top

  NameDescription
Public methodCloseCloses the port connection, sets the IsOpen property to false, and disposes of the internal Stream object. (Overrides Stream..::..Close()()()().)
Public methodDiscardInBufferDiscards data from the serial driver's receive buffer.
Public methodDiscardOutBufferDiscards data from the serial driver's transmit buffer.
Public methodDispose()()()()Releases all resources used by the Stream. (Inherited from Stream.)
Protected methodDispose(Boolean)Releases the unmanaged resources used by the SerialPort and optionally releases the managed resources. (Overrides Stream..::..Dispose(Boolean).)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeCleans up resources. (Inherited from Stream.)
Public methodFlushSends any data waiting in the send buffer of this SerialPort and clears the buffer. (Overrides Stream..::..Flush()()()().)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodOpenOpens a new serial port connection.
Public methodReadReads a number of bytes from the SerialPort input buffer and writes those bytes into a byte array at the specified offset. (Overrides Stream..::..Read(array<Byte>[]()[][], Int32, Int32).)
Public methodReadByteReads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream. (Inherited from Stream.)
Public methodSeekSets the position within the current stream. (Overrides Stream..::..Seek(Int64, SeekOrigin).)
Public methodSetLengthSets the length of the current stream. (Overrides Stream..::..SetLength(Int64).)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodWriteWrites a specified number of bytes to the serial port using data from a buffer. (Overrides Stream..::..Write(array<Byte>[]()[][], Int32, Int32).)
Public methodWriteByteWrites a byte to the current position in the stream and advances the position within the stream by one byte. (Inherited from Stream.)
Top

  NameDescription
Public eventDataReceivedRepresents the method that will handle the data received event of a SerialPort object.
Public eventErrorReceivedRepresents the method that handles the error event of a SerialPort object.
Top

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 Stream object, accessible through the BaseStream property, and passed to classes that wrap or use streams.

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show: