Library to send/receive data with a device which respects the Modbus protocol for dotnet.
Install the NuGet package into your project.
PM> Install-Package LibModbus
$ dotnet add package LibModbus
- Read Coils (FC1)
- Read Discrete Inputs (FC2)
- Read Holding Registers (FC3)
- Read Input Registers (FC4)
- Write Single Coil (FC5)
- Write Single Register (FC6)
- Write Multiple Coils (FC15)
- Write Multiple Registers (FC16)
var address = "127.0.0.1";
await using var client = new ModbusClientBuilder()
.UseSocket(address)
.Build();
await client.ConnectAsync();
var coils = await client.ReadCoils(2, 10);
var index = 2;
foreach (var coil in coils)
{
var onOrOff = coil ? "on" : "off";
Console.WriteLine($"Coil {index++} is {onOrOff}");
}
- MODBUS Application Protocol Specification v1.1b3 (PDF)
- MODBUS over serial line specification and implementation guide v1.02 (PDF)
- MODBUS Messaging on TCP/IP Implementation Guide v1.0b (PDF)
Copyright 2020 Nick Van Dyck
MIT