Skip to main content

Class SerialMessagePort

Represents a port that is capable of serial (UART) communications.

Has a streamlined API over class SerialPort that deals in messages.

This is a modern, asynchronous take on serial communications that is thread-safe and asynchronous in nature. This is the recommended way to use serial on Meadow for nearly all use cases.

Assembly: Meadow.dll
View Source
Declaration
public class SerialMessagePort : SerialMessageProcessor, ISerialMessagePort

Inheritance: System.Object -> Meadow.Hardware.SerialMessageProcessor

Implements:
Meadow.Hardware.ISerialMessagePort

Properties

BaudRate

Gets or sets the serial baud rate.

View Source
Declaration
public int BaudRate { get; set; }

PortName

Gets the port name used for communications.

View Source
Declaration
public string PortName { get; }

IsOpen

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

View Source
Declaration
public bool IsOpen { get; }

Parity

Gets or sets the parity-checking protocol.

View Source
Declaration
public Parity Parity { get; set; }

DataBits

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

View Source
Declaration
public int DataBits { get; set; }

StopBits

Gets or sets the standard number of stop bits per byte.

View Source
Declaration
public StopBits StopBits { get; set; }

Fields

classicSerialPort

The underlying classic serial port used for communication.

View Source
Declaration
protected ISerialPort classicSerialPort

Methods

From(ISerialPort, byte[], bool)

Creates a new instance of Meadow.Hardware.SerialMessagePort using the specified parameters for suffix-based message processing.

View Source
Declaration
public static SerialMessagePort From(ISerialPort commsPort, byte[] suffixDelimiter, bool preserveDelimiter)
Returns

Meadow.Hardware.SerialMessagePort.

Parameters
TypeNameDescription
Meadow.Hardware.ISerialPortcommsPortThe underlying serial port.
System.Byte[]suffixDelimiterThe suffix delimiter for message termination.
System.BooleanpreserveDelimiterFlag indicating whether to preserve the delimiter in the received message.

From(ISerialPort, byte[], bool, int)

Creates a new instance of Meadow.Hardware.SerialMessagePort using the specified parameters for prefix-based message processing.

View Source
Declaration
public static SerialMessagePort From(ISerialPort commsPort, byte[] prefixDelimiter, bool preserveDelimiter, int messageLength)
Returns

Meadow.Hardware.SerialMessagePort.

Parameters
TypeNameDescription
Meadow.Hardware.ISerialPortcommsPortThe underlying serial port.
System.Byte[]prefixDelimiterThe prefix delimiter for message parsing.
System.BooleanpreserveDelimiterFlag indicating whether to preserve the delimiter in the received message.
System.Int32messageLengthThe expected message length (excluding the prefix delimiter).

Init()

Initializes the buffer and underlying serial port

View Source
Declaration
protected void Init()

Open()

Opens a new serial port connection

View Source
Declaration
public void Open()

Close()

Closes the port connection and sets the IsOpen property to false

View Source
Declaration
public void Close()

Write(byte[])

Writes data to the serial port

View Source
Declaration
public int Write(byte[] buffer)
Returns

System.Int32

Parameters
TypeName
System.Byte[]buffer

Write(byte[], int, int)

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

View Source
Declaration
public int Write(byte[] buffer, int offset, int count)
Returns

System.Int32

Parameters
TypeNameDescription
System.Byte[]bufferThe byte array that contains the data to write to the port.
System.Int32offsetThe zero-based byte offset in the buffer parameter at which to begin copying bytes to the port.
System.Int32countThe number of bytes to write.

ClearReceiveBuffer()

Discards all data from the receive buffer

View Source
Declaration
public void ClearReceiveBuffer()

Implements