Skip to main content

Class SerialPortShim

Represents a shim for the serial port implementation, providing an interface for Modbus communication.

Assembly: Meadow.Modbus.dll​
View Source​
Declaration
public class SerialPortShim : ISerialPort, IDisposable

Implements:
Meadow.Hardware.ISerialPort, System.IDisposable

Properties​

IsDisposed​

View Source​
Declaration
public bool IsDisposed { get; }

IsOpen​

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

View Source​
Declaration
public bool IsOpen { get; }

PortName​

Gets the port name used for communications.

View Source​
Declaration
public string PortName { get; }

BytesToRead​

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

View Source​
Declaration
public int BytesToRead { get; }

ReceiveBufferSize​

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

View Source​
Declaration
public int ReceiveBufferSize { get; }

DataBits​

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

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

Parity​

Gets or sets the parity-checking protocol.

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

StopBits​

Gets or sets the standard number of stopbits per byte.

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

BaudRate​

Gets or sets the serial baud rate.

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

ReadTimeout​

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

View Source​
Declaration
public TimeSpan ReadTimeout { get; set; }

WriteTimeout​

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

View Source​
Declaration
public TimeSpan WriteTimeout { get; set; }

Methods​

ClearReceiveBuffer()​

Discards data from the serial driver's receive buffer.

View Source​
Declaration
public void ClearReceiveBuffer()

Close()​

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

View Source​
Declaration
public void Close()

Open()​

Opens a new serial port connection.

View Source​
Declaration
public void Open()

Peek()​

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

View Source​
Declaration
public 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
public 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
public byte[] ReadAll()
Returns​

System.Byte[]

ReadByte()​

Synchronously reads one byte from the SerialPort input buffer.

View Source​
Declaration
public int ReadByte()
Returns​

System.Int32: The byte, cast to an Int32, or -1 if the end of the stream has been read.

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.

Dispose(bool)​

View Source​
Declaration
protected virtual void Dispose(bool disposing)
Parameters​
TypeName
System.Booleandisposing

Dispose()​

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

View Source​
Declaration
public void Dispose()

Events​

DataReceived​

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

View Source​
Declaration
public 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
public event EventHandler BufferOverrun
Event Type​

System.EventHandler

Implements​