Table of Contents

Class ModbusRtuClient

Namespace
FluentModbus
Assembly
FluentModbus.dll

A Modbus RTU client.

public class ModbusRtuClient : ModbusClient, IDisposable
Inheritance
ModbusRtuClient
Implements
Inherited Members

Constructors

ModbusRtuClient()

Creates a new Modbus RTU client for communication with Modbus RTU servers or bridges, routers and gateways for communication with TCP end units.

public ModbusRtuClient()

Properties

BaudRate

Gets or sets the serial baud rate. Default is 9600.

public int BaudRate { get; set; }

Property Value

int

Handshake

Gets or sets the handshaking protocol for serial port transmission of data. Default is Handshake.None.

public Handshake Handshake { get; set; }

Property Value

Handshake

IsConnected

Gets the connection status of the underlying serial port.

public bool IsConnected { get; }

Property Value

bool

Parity

Gets or sets the parity-checking protocol. Default is Parity.Even.

public Parity Parity { get; set; }

Property Value

Parity

ReadTimeout

Gets or sets the read timeout in milliseconds. Default is 1000 ms.

public int ReadTimeout { get; set; }

Property Value

int

StopBits

Gets or sets the standard number of stopbits per byte. Default is StopBits.One.

public StopBits StopBits { get; set; }

Property Value

StopBits

WriteTimeout

Gets or sets the write timeout in milliseconds. Default is 1000 ms.

public int WriteTimeout { get; set; }

Property Value

int

Methods

Close()

Closes the opened COM port and frees all resources.

public void Close()

Connect(string)

Connect to the specified port with LittleEndian as default byte layout.

public void Connect(string port)

Parameters

port string

The COM port to be used, e.g. COM1.

Connect(string, ModbusEndianness)

Connect to the specified port.

public void Connect(string port, ModbusEndianness endianness)

Parameters

port string

The COM port to be used, e.g. COM1.

endianness ModbusEndianness

Specifies the endianness of the data exchanged with the Modbus server.

Dispose()

Disposes the current instance.

public void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

Initialize(IModbusRtuSerialPort, ModbusEndianness)

Initialize the Modbus TCP client with an externally managed IModbusRtuSerialPort.

public void Initialize(IModbusRtuSerialPort serialPort, ModbusEndianness endianness)

Parameters

serialPort IModbusRtuSerialPort

The externally managed IModbusRtuSerialPort.

endianness ModbusEndianness

Specifies the endianness of the data exchanged with the Modbus server.

TransceiveFrame(byte, ModbusFunctionCode, Action<ExtendedBinaryWriter>)

Sends the requested modbus message and waits for the response.

protected override Span<byte> TransceiveFrame(byte unitIdentifier, ModbusFunctionCode functionCode, Action<ExtendedBinaryWriter> extendFrame)

Parameters

unitIdentifier byte

The unit identifier.

functionCode ModbusFunctionCode

The function code.

extendFrame Action<ExtendedBinaryWriter>

An action to be called to extend the prepared Modbus frame with function code specific data.

Returns

Span<byte>

TransceiveFrameAsync(byte, ModbusFunctionCode, Action<ExtendedBinaryWriter>, CancellationToken)

Sends the requested modbus message and waits for the response.

protected override Task<Memory<byte>> TransceiveFrameAsync(byte unitIdentifier, ModbusFunctionCode functionCode, Action<ExtendedBinaryWriter> extendFrame, CancellationToken cancellationToken = default)

Parameters

unitIdentifier byte

The unit identifier.

functionCode ModbusFunctionCode

The function code.

extendFrame Action<ExtendedBinaryWriter>

An action to be called to extend the prepared Modbus frame with function code specific data.

cancellationToken CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task<Memory<byte>>