Table of Contents

Interface IModbusRtuSerialPort

Namespace
FluentModbus
Assembly
FluentModbus.dll

A serial port for Modbus RTU communication.

public interface IModbusRtuSerialPort

Properties

IsOpen

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

bool IsOpen { get; }

Property Value

bool

PortName

Gets the port for communications, including but not limited to all available COM ports.

string PortName { get; }

Property Value

string

Methods

Close()

Closes the port connection, sets the IsOpen property to true, and disposes of the internal Stream object.

void Close()

Open()

Opens a new serial port connection.

void Open()

Read(byte[], int, int)

Reads a number of bytes from the serial port input buffer and writes those bytes into a byte array at the specified offset.

int Read(byte[] buffer, int offset, int count)

Parameters

buffer byte[]

The byte array to write the input to.

offset int

The offset in buffer at which to write the bytes.

count int

The maximum number of bytes to read. Fewer bytes are read if count is greater than the number of bytes in the input buffer.

Returns

int

The number of bytes read.

ReadAsync(byte[], int, int, CancellationToken)

Asynchronously reads a number of bytes from the serial port input buffer and writes those bytes into a byte array at the specified offset.

Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken token)

Parameters

buffer byte[]

The byte array to write the input to.

offset int

The offset in buffer at which to write the bytes.

count int

The maximum number of bytes to read. Fewer bytes are read if count is greater than the number of bytes in the input buffer.

token CancellationToken

A token to cancel the current operation.

Returns

Task<int>

The number of bytes read.

Write(byte[], int, int)

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

void Write(byte[] buffer, int offset, int count)

Parameters

buffer byte[]

The byte array that contains the data to write to the port.

offset int

The zero-based byte offset in the buffer parameter at which to begin copying bytes to the port.

count int

The number of bytes to write.

WriteAsync(byte[], int, int, CancellationToken)

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

Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token)

Parameters

buffer byte[]

The byte array that contains the data to write to the port.

offset int

The zero-based byte offset in the buffer parameter at which to begin copying bytes to the port.

count int

The number of bytes to write.

token CancellationToken

A token to cancel the current operation.

Returns

Task