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.

Inheritance Hierarchy

System. . :: . .Object
  System. . :: . .MarshalByRefObject
    System.IO. . :: . .Stream
      System.IO.Ports..::..SerialPort

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

Syntax

'Declaration
Public Class SerialPort _
    Inherits Stream
public class SerialPort : Stream
public ref class SerialPort : public Stream
type SerialPort =  
    class
        inherit Stream
    end
public class SerialPort extends Stream

The SerialPort type exposes the following members.

Constructors

  Name Description
Public method SerialPort(String) Initializes a new instance of the SerialPort class using the specified port name.
Public method SerialPort(String, Int32) Initializes a new instance of the SerialPort class using the specified port name and baud rate.
Public method SerialPort(String, Int32, Parity) Initializes a new instance of the SerialPort class using the specified port name, baud rate, and parity bit.
Public method SerialPort(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 method SerialPort(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

Properties

  Name Description
Public property BaseStream Gets the underlying Stream object for a SerialPort object.
Public property BaudRate Gets or sets the serial baud rate.
Public property BytesToRead Gets the number of bytes of data in the receive buffer.
Public property BytesToWrite Gets the number of bytes of data in the send buffer.
Public property CanRead Gets a value indicating whether the current stream supports reading. (Overrides Stream. . :: . .CanRead.)
Public property CanSeek Gets a value indicating whether the current stream supports seeking. (Overrides Stream. . :: . .CanSeek.)
Public property CanTimeout Gets a value that indicates whether the current stream can time out. (Overrides Stream. . :: . .CanTimeout.)
Public property CanWrite Gets a value that indicates whether the current stream supports writing. (Overrides Stream. . :: . .CanWrite.)
Public property DataBits Gets or sets the standard length of data bits per byte.
Public property Handshake Gets or sets the handshaking protocol for serial port transmission of data.
Public property IsOpen Gets a value indicating the open or closed status of the SerialPort object.
Public property Length Gets the length in bytes of the stream. (Overrides Stream. . :: . .Length.)
Public property Parity Gets or sets the parity-checking protocol.
Public property PortName Gets or sets the port for communications, including but not limited to all available COM ports.
Public property Position Gets or sets the position in the current stream. (Overrides Stream. . :: . .Position.)
Public property ReadTimeout Gets or sets the number of milliseconds before a time-out occurs when a read operation does not finish. (Overrides Stream. . :: . .ReadTimeout.)
Public property StopBits Gets or sets the standard number of stopbits per byte.
Public property WriteTimeout Gets or sets the number of milliseconds before a time-out occurs when a write operation does not finish. (Overrides Stream. . :: . .WriteTimeout.)

Top

Methods

  Name Description
Public method Close Closes the port connection, sets the IsOpen property to false, and disposes of the internal Stream object. (Overrides Stream. . :: . .Close() () () ().)
Public method DiscardInBuffer Discards data from the serial driver's receive buffer.
Public method DiscardOutBuffer Discards data from the serial driver's transmit buffer.
Public method Dispose() () () () Releases all resources used by the Stream. (Inherited from Stream.)
Protected method Dispose(Boolean) Releases the unmanaged resources used by the SerialPort and optionally releases the managed resources. (Overrides Stream. . :: . .Dispose(Boolean).)
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Cleans up resources. (Inherited from Stream.)
Public method Flush Sends any data waiting in the send buffer of this SerialPort and clears the buffer. (Overrides Stream. . :: . .Flush() () () ().)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Open Opens a new serial port connection.
Public method Read Reads 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 method ReadByte Reads 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 method Seek Sets the position within the current stream. (Overrides Stream. . :: . .Seek(Int64, SeekOrigin).)
Public method SetLength Sets the length of the current stream. (Overrides Stream. . :: . .SetLength(Int64).)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method Write Writes a specified number of bytes to the serial port using data from a buffer. (Overrides Stream. . :: . .Write(array<Byte> [] () [] [], Int32, Int32).)
Public method WriteByte Writes a byte to the current position in the stream and advances the position within the stream by one byte. (Inherited from Stream.)

Top

Events

  Name Description
Public event DataReceived Represents the method that will handle the data received event of a SerialPort object.
Public event ErrorReceived Represents the method that handles the error event of a SerialPort object.

Top

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

Thread Safety

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

See Also

Reference

System.IO.Ports Namespace