Table of Contents

Class ModbusRtuSerialPort

Namespace
FluentModbus
Assembly
FluentModbus.dll

A wrapper for a SerialPort.

public class ModbusRtuSerialPort : IModbusRtuSerialPort
Inheritance
ModbusRtuSerialPort
Implements

Constructors

ModbusRtuSerialPort(SerialPort)

Initializes a new instances of the ModbusRtuSerialPort class.

public ModbusRtuSerialPort(SerialPort serialPort)

Parameters

serialPort SerialPort

The serial port to wrap.

Properties

IsOpen

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

public bool IsOpen { get; }

Property Value

bool

PortName

Gets the port for communications.

public string PortName { get; }

Property Value

string

Methods

Close()

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

public void Close()

Open()

Opens a new serial port connection.

public void Open()

Read(byte[], int, int)

Reads from the SerialPort input buffer.

public 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 from the SerialPort input buffer.

public 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 data to the serial port output buffer.

public 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 data to the serial port output buffer.

public 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