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
Handshake
Gets or sets the handshaking protocol for serial port transmission of data. Default is Handshake.None.
public Handshake Handshake { get; set; }
Property Value
IsConnected
Gets the connection status of the underlying serial port.
public bool IsConnected { get; }
Property Value
Parity
Gets or sets the parity-checking protocol. Default is Parity.Even.
public Parity Parity { get; set; }
Property Value
ReadTimeout
Gets or sets the read timeout in milliseconds. Default is 1000 ms.
public int ReadTimeout { get; set; }
Property Value
StopBits
Gets or sets the standard number of stopbits per byte. Default is StopBits.One.
public StopBits StopBits { get; set; }
Property Value
WriteTimeout
Gets or sets the write timeout in milliseconds. Default is 1000 ms.
public int WriteTimeout { get; set; }
Property Value
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
stringThe 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
stringThe COM port to be used, e.g. COM1.
endianness
ModbusEndiannessSpecifies 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
IModbusRtuSerialPortThe externally managed IModbusRtuSerialPort.
endianness
ModbusEndiannessSpecifies 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
byteThe unit identifier.
functionCode
ModbusFunctionCodeThe function code.
extendFrame
Action<ExtendedBinaryWriter>An action to be called to extend the prepared Modbus frame with function code specific data.
Returns
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
byteThe unit identifier.
functionCode
ModbusFunctionCodeThe function code.
extendFrame
Action<ExtendedBinaryWriter>An action to be called to extend the prepared Modbus frame with function code specific data.
cancellationToken
CancellationTokenThe token to monitor for cancellation requests. The default value is None.