Class ModbusTcpClient
- Namespace
- FluentModbus
- Assembly
- FluentModbus.dll
A Modbus TCP client.
public class ModbusTcpClient : ModbusClient, IDisposable
- Inheritance
-
ModbusTcpClient
- Implements
- Inherited Members
Constructors
ModbusTcpClient()
Creates a new Modbus TCP client for communication with Modbus TCP servers or bridges, routers and gateways for communication with serial line end units.
public ModbusTcpClient()
Properties
ConnectTimeout
Gets or sets the connect timeout in milliseconds. Default is 1000 ms.
public int ConnectTimeout { get; set; }
Property Value
IsConnected
Gets the connection status of the underlying TCP client.
public bool IsConnected { get; }
Property Value
ReadTimeout
Gets or sets the read timeout in milliseconds. Default is Infinite.
public int ReadTimeout { get; set; }
Property Value
WriteTimeout
Gets or sets the write timeout in milliseconds. Default is Infinite.
public int WriteTimeout { get; set; }
Property Value
Methods
Connect()
Connect to localhost at port 502 with LittleEndian as default byte layout.
public void Connect()
Connect(ModbusEndianness)
Connect to localhost at port 502.
public void Connect(ModbusEndianness endianness)
Parameters
endiannessModbusEndiannessSpecifies the endianness of the data exchanged with the Modbus server.
Connect(IPAddress)
Connect to the specified remoteIpAddress at port 502.
public void Connect(IPAddress remoteIpAddress)
Parameters
remoteIpAddressIPAddressThe IP address of the end unit with LittleEndian as default byte layout. Example: IPAddress.Parse("192.168.0.1").
Connect(IPAddress, ModbusEndianness)
Connect to the specified remoteIpAddress at port 502.
public void Connect(IPAddress remoteIpAddress, ModbusEndianness endianness)
Parameters
remoteIpAddressIPAddressThe IP address of the end unit. Example: IPAddress.Parse("192.168.0.1").
endiannessModbusEndiannessSpecifies the endianness of the data exchanged with the Modbus server.
Connect(IPEndPoint)
Connect to the specified remoteEndpoint with LittleEndian as default byte layout.
public void Connect(IPEndPoint remoteEndpoint)
Parameters
remoteEndpointIPEndPointThe IP address and port of the end unit.
Connect(IPEndPoint, ModbusEndianness)
Connect to the specified remoteEndpoint.
public void Connect(IPEndPoint remoteEndpoint, ModbusEndianness endianness)
Parameters
remoteEndpointIPEndPointThe IP address and port of the end unit.
endiannessModbusEndiannessSpecifies the endianness of the data exchanged with the Modbus server.
Connect(string)
Connect to the specified remoteEndpoint.
public void Connect(string remoteEndpoint)
Parameters
remoteEndpointstringThe IP address and optional port of the end unit with LittleEndian as default byte layout. Examples: "192.168.0.1", "192.168.0.1:502", "::1", "[::1]:502". The default port is 502.
Connect(string, ModbusEndianness)
Connect to the specified remoteEndpoint.
public void Connect(string remoteEndpoint, ModbusEndianness endianness)
Parameters
remoteEndpointstringThe IP address and optional port of the end unit. Examples: "192.168.0.1", "192.168.0.1:502", "::1", "[::1]:502". The default port is 502.
endiannessModbusEndiannessSpecifies the endianness of the data exchanged with the Modbus server.
Disconnect()
Disconnect from the end unit.
public void Disconnect()
Dispose()
Diposes the current instance.
public void Dispose()
Dispose(bool)
protected virtual void Dispose(bool disposing)
Parameters
disposingbool
Initialize(TcpClient, ModbusEndianness)
Initialize the Modbus TCP client with an externally managed TcpClient.
public void Initialize(TcpClient tcpClient, ModbusEndianness endianness)
Parameters
tcpClientTcpClientThe externally managed TcpClient.
endiannessModbusEndiannessSpecifies 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
unitIdentifierbyteThe unit identifier.
functionCodeModbusFunctionCodeThe function code.
extendFrameAction<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
unitIdentifierbyteThe unit identifier.
functionCodeModbusFunctionCodeThe function code.
extendFrameAction<ExtendedBinaryWriter>An action to be called to extend the prepared Modbus frame with function code specific data.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests. The default value is None.