Files
AMWD.Protocols.Modbus/AMWD.Protocols.Modbus.Serial
Andreas Müller 05759f8e12 Fixes for SerialRtuProxy
- Adding UnitTests
- Fixing some bugs
- Updating UnitTest dependencies
2025-01-27 17:27:23 +01:00
..
2024-04-02 19:34:27 +02:00
2025-01-27 17:27:23 +01:00
2025-01-27 17:27:23 +01:00
2025-01-27 17:27:23 +01:00

Modbus Protocol for .NET | Serial

The Modbus Serial protocol implementation.

Example

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

string serialPort = "COM5";

using var client = new ModbusSerialClient(serialPort);
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 ASCII protocol instead, you can do this on initialization:

// [...]

using var client = new ModbusSerialClient(serialPort)
{
	Protocol = new AsciiProtocol();
};

// [...]

Sources

  • Protocol Specification: v1.1b3
  • Modbus Serial line: v1.02

Published under MIT License (see choose a license)