Class ModbusTcpClient
Modbus TCP client implementation.
Assembly: Meadow.Modbus.dll
View Source
public class ModbusTcpClient : ModbusClientBase, IModbusBusClient, IDisposable
Inheritance: System.Object -> Meadow.Modbus.ModbusClientBase
Implements:
Meadow.Modbus.IModbusBusClient, System.IDisposable
Properties
Destination
Gets the destination IP address for the Modbus TCP client.
View Source
public IPAddress Destination { get; }
Port
Gets the port used for the Modbus TCP communication.
View Source
public short Port { get; }
Fields
DefaultModbusTCPPort
The default Modbus TCP port (502).
View Source
public const short DefaultModbusTCPPort = 502
Methods
DisposeManagedResources()
Releases the managed resources used by the Modbus client.
View Source
protected override void DisposeManagedResources()
Connect(IPEndPoint)
Connect to an endpoint. Allows for reusing the ModbusTcpClient.
View Source
public Task Connect(IPEndPoint destination)
Returns
System.Threading.Tasks.Task
Parameters
| Type | Name |
|---|---|
System.Net.IPEndPoint | destination |
Connect(string, short)
Connect to an endpoint. Allows for reusing the ModbusTcpClient.
View Source
public Task Connect(string destinationAddress, short port = 502)
Returns
System.Threading.Tasks.Task
Parameters
| Type | Name |
|---|---|
System.String | destinationAddress |
System.Int16 | port |
Connect(IPAddress, short)
Connect to an endpoint. Allows for reusing the ModbusTcpClient.
View Source
public Task Connect(IPAddress destination, short port = 502)
Returns
System.Threading.Tasks.Task
Parameters
| Type | Name |
|---|---|
System.Net.IPAddress | destination |
System.Int16 | port |
Connect()
Connects to the Modbus device.
View Source
public override Task Connect()
Returns
System.Threading.Tasks.Task
Disconnect()
Disconnects from the Modbus device.
View Source
public override void Disconnect()
GenerateWriteMessage(byte, ModbusFunction, ushort, byte[])
Generates the message for writing data to a Modbus device.
View Source
protected override byte[] GenerateWriteMessage(byte modbusAddress, ModbusFunction function, ushort register, byte[] data)
Returns
System.Byte[]
Parameters
| Type | Name |
|---|---|
System.Byte | modbusAddress |
| Meadow.Modbus.ModbusFunction | function |
System.UInt16 | register |
System.Byte[] | data |
GenerateReportMessage(byte)
Generates the message for requesting a device report its identifier
View Source
protected override byte[] GenerateReportMessage(byte modbusAddress)
Returns
System.Byte[]
Parameters
| Type | Name |
|---|---|
System.Byte | modbusAddress |
GenerateReadMessage(byte, ModbusFunction, ushort, int)
Generates the message for reading data from a Modbus device.
View Source
protected override byte[] GenerateReadMessage(byte modbusAddress, ModbusFunction function, ushort startRegister, int registerCount)
Returns
System.Byte[]
Parameters
| Type | Name |
|---|---|
System.Byte | modbusAddress |
| Meadow.Modbus.ModbusFunction | function |
System.UInt16 | startRegister |
System.Int32 | registerCount |
DeliverMessage(byte[])
Delivers the Modbus message to the device.
View Source
protected override Task DeliverMessage(byte[] message)
Returns
System.Threading.Tasks.Task
Parameters
| Type | Name |
|---|---|
System.Byte[] | message |
ReadResult(ModbusFunction, byte)
Reads the result of the Modbus function.
View Source
protected override Task<byte[]> ReadResult(ModbusFunction function, byte expectedAddress)
Returns
System.Threading.Tasks.Task<System.Byte[]>
Parameters
| Type | Name |
|---|---|
| Meadow.Modbus.ModbusFunction | function |
System.Byte | expectedAddress |
Implements
- Meadow.Modbus.IModbusBusClient
System.IDisposable