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 | |
---|---|---|
SerialPort(String) | Initializes a new instance of the SerialPort class using the specified port name. | |
SerialPort(String, Int32) | Initializes a new instance of the SerialPort class using the specified port name and baud rate. | |
SerialPort(String, Int32, Parity) | Initializes a new instance of the SerialPort class using the specified port name, baud rate, and parity bit. | |
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. | |
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 | |
---|---|---|
BaseStream | Gets the underlying Stream object for a SerialPort object. | |
BaudRate | Gets or sets the serial baud rate. | |
BytesToRead | Gets the number of bytes of data in the receive buffer. | |
BytesToWrite | Gets the number of bytes of data in the send buffer. | |
CanRead | Gets a value indicating whether the current stream supports reading. (Overrides Stream. . :: . .CanRead.) | |
CanSeek | Gets a value indicating whether the current stream supports seeking. (Overrides Stream. . :: . .CanSeek.) | |
CanTimeout | Gets a value that indicates whether the current stream can time out. (Overrides Stream. . :: . .CanTimeout.) | |
CanWrite | Gets a value that indicates whether the current stream supports writing. (Overrides Stream. . :: . .CanWrite.) | |
DataBits | Gets or sets the standard length of data bits per byte. | |
Handshake | Gets or sets the handshaking protocol for serial port transmission of data. | |
IsOpen | Gets a value indicating the open or closed status of the SerialPort object. | |
Length | Gets the length in bytes of the stream. (Overrides Stream. . :: . .Length.) | |
Parity | Gets or sets the parity-checking protocol. | |
PortName | Gets or sets the port for communications, including but not limited to all available COM ports. | |
Position | Gets or sets the position in the current stream. (Overrides Stream. . :: . .Position.) | |
ReadTimeout | Gets or sets the number of milliseconds before a time-out occurs when a read operation does not finish. (Overrides Stream. . :: . .ReadTimeout.) | |
StopBits | Gets or sets the standard number of stopbits per byte. | |
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 | |
---|---|---|
Close | Closes the port connection, sets the IsOpen property to false, and disposes of the internal Stream object. (Overrides Stream. . :: . .Close() () () ().) | |
DiscardInBuffer | Discards data from the serial driver's receive buffer. | |
DiscardOutBuffer | Discards data from the serial driver's transmit buffer. | |
Dispose() () () () | Releases all resources used by the Stream. (Inherited from Stream.) | |
Dispose(Boolean) | Releases the unmanaged resources used by the SerialPort and optionally releases the managed resources. (Overrides Stream. . :: . .Dispose(Boolean).) | |
Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | |
Finalize | Cleans up resources. (Inherited from Stream.) | |
Flush | Sends any data waiting in the send buffer of this SerialPort and clears the buffer. (Overrides Stream. . :: . .Flush() () () ().) | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
Open | Opens a new serial port connection. | |
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).) | |
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.) | |
Seek | Sets the position within the current stream. (Overrides Stream. . :: . .Seek(Int64, SeekOrigin).) | |
SetLength | Sets the length of the current stream. (Overrides Stream. . :: . .SetLength(Int64).) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) | |
Write | Writes a specified number of bytes to the serial port using data from a buffer. (Overrides Stream. . :: . .Write(array<Byte> [] () [] [], Int32, Int32).) | |
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 | |
---|---|---|
DataReceived | Represents the method that will handle the data received event of a SerialPort object. | |
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.