AMWD.Protocols.Modbus.Tcp 0.2.1-6

Modbus Protocol for .NET | TCP

The Modbus TCP protocol implementation.

Example

A simple example which reads the voltage between L1 and N of a Janitza device.

string host = "modbus-device.internal";
int port = 502;

using var client = new ModbusTcpClient(host, port);
await client.ConnectAsync(CancellationToken.None);

byte unitId = 5;
ushort startAddress = 19000;
ushort count = 2;

var registers = await client.ReadHoldingRegistersAsync(unitId, startAddress, count);
float voltage = registers.GetSingle();

Console.WriteLine($"The voltage of device #{unitId} between L1 and N is: {voltage:N2}V");

If you want to use the RTU over TCP protocol instead, you can do this on initialization:

// [...]

using var client = new ModbusTcpClient(host, port)
{
	Protocol = new RtuOverTcpProtocol();
};

// [...]

Sources


Published under MIT License (see tl;drLegal)

No packages depend on AMWD.Protocols.Modbus.Tcp.

.NET 6.0

.NET 8.0

.NET Standard 2.0

Version Downloads Last updated
0.2.1-6 3 20.04.2024
0.2.1-5 1 20.04.2024
0.2.1-3 1 20.04.2024
0.2.0 5 02.04.2024
0.1.0 118 28.08.2022
0.0.1-19 4 02.04.2024
0.0.1-18 4 02.04.2024
0.0.1-17 4 02.04.2024
0.0.1-14 4 31.03.2024
0.0.1-13 4 28.03.2024
0.0.1-12 4 28.03.2024
0.0.1-11 4 27.03.2024
0.0.1-10 1 26.03.2024
0.0.1-9 2 25.03.2024
0.0.1-7 8 09.03.2024
0.0.1-6 6 09.03.2024