Skip to main content

Interface ISerialPort

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

Assembly: Meadow.Contracts.dll
View Source
Declaration
public interface ISerialPort : IDisposable

Properties

BaudRate

Gets or sets the serial baud rate.

View Source
Declaration
int BaudRate { get; set; }

BytesToRead

Gets the number of bytes of data in the receive buffer.

View Source
Declaration
int BytesToRead { get; }

DataBits

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

View Source
Declaration
int DataBits { get; set; }

IsOpen

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

View Source
Declaration
bool IsOpen { get; }

Parity

Gets or sets the parity-checking protocol.

View Source
Declaration
Parity Parity { get; set; }

PortName

Gets the port name used for communications.

View Source
Declaration
string PortName { get; }

ReceiveBufferSize

The size, in bytes, of the receive buffer that caches message data from the attached peripheral.

View Source
Declaration
int ReceiveBufferSize { get; }

ReadTimeout

The time required for a time-out to occur when a read operation does not finish.

View Source
Declaration
TimeSpan ReadTimeout { get; set; }

WriteTimeout

The time required for a time-out to occur when a write operation does not finish.

View Source
Declaration
TimeSpan WriteTimeout { get; set; }

StopBits

Gets or sets the standard number of stopbits per byte.

View Source
Declaration
StopBits StopBits { get; set; }

Methods

Close()

Closes the port connection and sets the IsOpen property to false.

View Source
Declaration
void Close()

ClearReceiveBuffer()

Discards data from the serial driver's receive buffer.

View Source
Declaration
void ClearReceiveBuffer()

Open()

Opens a new serial port connection.

View Source
Declaration
void Open()

Peek()

Returns the next available byte in the input buffer but does not consume it.

View Source
Declaration
int Peek()
Returns

System.Int32: The byte, cast to an Int32, or -1 if there is no data available in the input buffer.### Read(byte[], int, int) Reads a number of bytes from the SerialPort input buffer and writes those bytes into a byte array at the specified offset.

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

System.Int32: The number of bytes read.

Parameters
TypeNameDescription
System.Byte[]bufferThe byte array to write the input to.
System.Int32offsetThe offset in buffer at which to write the bytes.
System.Int32countThe maximum number of bytes to read. Fewer bytes are read if count is greater than the number of bytes in the input buffer.

ReadAll()

Reads all currently available bytes from the SerialPort

View Source
Declaration
byte[] ReadAll()
Returns

System.Byte[]

ReadByte()

Synchronously reads one byte from the SerialPort input buffer.

View Source
Declaration
int ReadByte()
Returns

System.Int32: The byte, cast to an Int32, or -1 if the end of the stream has been read.### ToString() Returns a friendly string descriptor of the SerialPort

View Source
Declaration
string? ToString()
Returns

System.String

Write(byte[])

Writes data to the serial port.

View Source
Declaration
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
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.

Events

DataReceived

Indicates that data has been received through a port represented by the SerialPort object.

View Source
Declaration
event SerialDataReceivedEventHandler DataReceived
Event Type

Meadow.Hardware.SerialDataReceivedEventHandler

BufferOverrun

Indicates that the internal data buffer has overrun and data has been lost.

View Source
Declaration
event EventHandler BufferOverrun
Event Type

System.EventHandler