Files
AMWD.Protocols.Modbus/AMWD.Protocols.Modbus.Tcp/README.md

1.0 KiB

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");

Sources


Published under MIT License (see tl;drLegal)