NewLife.Modbus
2.1.2026.901
See the version list below for details.
dotnet add package NewLife.Modbus --version 2.1.2026.901
NuGet\Install-Package NewLife.Modbus -Version 2.1.2026.901
<PackageReference Include="NewLife.Modbus" Version="2.1.2026.901" />
<PackageVersion Include="NewLife.Modbus" Version="2.1.2026.901" />
<PackageReference Include="NewLife.Modbus" />
paket add NewLife.Modbus --version 2.1.2026.901
#r "nuget: NewLife.Modbus, 2.1.2026.901"
#:package NewLife.Modbus@2.1.2026.901
#addin nuget:?package=NewLife.Modbus&version=2.1.2026.901
#tool nuget:?package=NewLife.Modbus&version=2.1.2026.901
NewLife.Modbus - ModbusTcp/ModbusRTU
🌐 Languages: English | 简体中文 | Español | Português | Français | العربية | Русский | Deutsch | 日本語 | 한국어
Complete Modbus protocol implementation including ModbusTCP / ModbusRTU / ModbusASCII and multiple network variants, built on NewLife.IoT standard interfaces with IoTEdge gateway support.
Source: https://github.com/NewLifeX/NewLife.Modbus
Nuget: NewLife.Modbus / NewLife.ModbusRTU
Docs: 需求文档 / 架构设计 / 功能清单 / 竞品分析
Highlights
- Most Complete Protocol: Implements Modbus Application Protocol Specification V1.1b3 with all 19 function codes (12 public + 7 advanced), covering over 99% of common industrial operations; supports the Enron/Daniel floating-point extension for oil & gas registers
- Multiple Transport Variants: ModbusTCP, ModbusTCP/TLS (encrypted), ModbusUDP, ModbusRTU (serial), ModbusASCII (serial), ModbusRtuOverTCP, ModbusRtuOverUDP, ModbusRtuSimple — 8 variants in total
- Full Master & Slave: Complete implementations of both Master (client) and Slave (server), with Slave supporting concurrent multi-client connections
- Zero-Allocation Encoding: Hot paths use
SpanReader/SpanWriterfor zero-allocation encoding/decoding, reducing GC pressure - Batch Optimization:
BuildSegmentsautomatically merges consecutive addresses, reading multiple points in a single request to reduce polling overhead - IoT Driver Integration: Implements the
IDriverstandard interface for zero-code integration with IoTEdge platform, with 6 drivers to choose from - Advanced Features: Auto-reconnect, async/await API, multi-slave network model, custom function code registration, broadcast mode
- Lightweight Serial:
ModbusRtuSimpletargets resource-constrained edge devices with fewer dependencies and smaller memory footprint - APM Observability: Built-in
ITracertracing andILoglogging support, integrated with Stardust distributed platform - Multi-Framework:
net45 / net462 / netstandard2.0 / netstandard2.1 / net6.0 / net7.0 / net8.0 / net9.0 / net10.0
Supported Transport Variants
| Variant | NuGet Package | Description |
|---|---|---|
| ModbusTCP | NewLife.Modbus |
Standard Modbus TCP/IP with MBAP header + PDU, port 502 |
| ModbusUDP | NewLife.Modbus |
Modbus over UDP, connectionless transport |
| ModbusRtuOverTCP | NewLife.Modbus |
RTU frames (with CRC) over TCP transport |
| ModbusRtuOverUDP | NewLife.Modbus |
RTU frames (with CRC) over UDP transport |
| ModbusRTU | NewLife.ModbusRTU |
Serial binary compact format, CRC-16 validation |
| ModbusASCII | NewLife.ModbusRTU |
Serial ASCII hexadecimal format, LRC validation |
| ModbusRtuSimple | NewLife.ModbusRTU |
Lightweight simplified serial implementation, direct SerialPort access, suitable for resource-constrained edge scenarios |
Quick Start
Install NuGet Package
# TCP/UDP scenario (no serial port needed)
dotnet add package NewLife.Modbus
# Serial RTU/ASCII scenario
dotnet add package NewLife.ModbusRTU
Master - ModbusTCP Read/Write Registers
using NewLife.IoT.Protocols;
// Create ModbusTCP connection
var modbus = new ModbusTcp
{
Server = "192.168.1.100:502",
Timeout = 3000,
Log = XTrace.Log, // Optional: enable communication log
};
modbus.Open();
// Read holding registers (FC03), station 1, starting address 0, read 10 registers
var registers = modbus.ReadRegister(host: 1, address: 0, count: 10);
Console.WriteLine($"Register values: {registers?.Join(", ")}");
// Read coils (FC01)
var coils = modbus.ReadCoil(host: 1, address: 0, count: 8);
Console.WriteLine($"Coil states: {coils?.Join(", ")}");
// Write single register (FC06)
modbus.WriteRegister(host: 1, address: 0, value: 1234);
// Write multiple registers (FC16)
modbus.WriteRegisters(host: 1, address: 0, values: [100, 200, 300]);
// Write single coil (FC05)
modbus.WriteCoil(host: 1, address: 0, value: true);
Master - ModbusRTU Serial Communication
using NewLife.IoT.Protocols;
// Create ModbusRTU serial connection
var modbus = new ModbusRtu
{
PortName = "COM3", // Windows: "COM3", Linux: "/dev/ttyS0"
Baudrate = 9600,
Log = XTrace.Log,
};
modbus.Open();
// Read holding registers (FC03)
var registers = modbus.ReadRegister(host: 1, address: 0, count: 5);
// Write multiple registers (FC16)
modbus.WriteRegisters(host: 1, address: 0, values: [0xABCD, 0xEF01]);
Slave - TCP Simulation Server
using NewLife.IoT;
using NewLife.IoT.Models;
// Create and configure the slave
var slave = new ModbusSlave
{
Port = 502,
Log = XTrace.Log,
};
// Preset register data (holding registers, FC03/FC06 operations)
for (var i = 0; i < 100; i++)
slave.Registers.Add(new RegisterUnit { Address = (UInt16)i, Value = (UInt16)(i * 10) });
// Preset coil data (FC01/FC05 operations)
for (var i = 0; i < 16; i++)
slave.Coils.Add(new CoilUnit { Address = (UInt16)i, Value = i % 2 == 0 });
// Start the slave and begin listening
slave.Start();
Console.WriteLine("Modbus Slave started, port 502");
IoT Driver Layer Integration
using NewLife.IoT.Drivers;
// Create TCP driver (supports IoTEdge driver standard interface)
var driver = new ModbusTcpDriver();
var parameter = new ModbusTcpParameter
{
Server = "192.168.1.100:502",
Host = 1,
Timeout = 3000,
BatchStep = 1, // Points with address gap ≤1 are auto-merged into batch requests
BatchSize = 100, // Maximum 100 points per batch
};
// Open driver (single connection reused)
var node = driver.Open(device: null, parameter);
// Batch read (automatically merges consecutive addresses to reduce request count)
var points = new[] { /* ThingModel point definitions */ };
var result = driver.Read(node, points);
NewLife Development Team
Founded in 2002, the NewLife team (新生命团队) is an IoT industry solution provider dedicated to software/hardware consulting, system architecture planning, and development services.
The team leads over 80 open-source projects widely adopted across various industries, with over 4 million cumulative NuGet downloads.
Our big-data middleware NewLife.XCode, scheduling platform AntJob, distributed platform Stardust, caching/queue component NewLife.Redis, and IoT platform FIoT have been successfully deployed in power, education, internet, telecom, transportation, logistics, industrial control, healthcare, and cultural heritage sectors.
We continuously improve our services to become a trusted long-term partner for our clients, and strive through innovation to become a leading IoT service provider in China.
Founded in 2002, some open-source projects have over 20 years of history; the source repository retains all change records since 2010
Website: https://newlifex.com
Open Source: https://github.com/newlifex
QQ Group: 1600800/1600838
WeChat Official Account:
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.5
- NewLife.Core (>= 11.19.2026.901)
- NewLife.IoT (>= 3.1.2026.801)
-
.NETFramework 4.6.1
- NewLife.Core (>= 11.19.2026.901)
- NewLife.IoT (>= 3.1.2026.801)
-
.NETStandard 2.0
- NewLife.Core (>= 11.19.2026.901)
- NewLife.IoT (>= 3.1.2026.801)
-
.NETStandard 2.1
- NewLife.Core (>= 11.19.2026.901)
- NewLife.IoT (>= 3.1.2026.801)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on NewLife.Modbus:
| Package | Downloads |
|---|---|
|
NewLife.ModbusRTU
Modbus RTU/ASCII serial protocol library for .NET. Supports binary RTU (CRC-16), ASCII (LRC), and lightweight RtuSimple variants over SerialPort on Windows and Linux. Built on NewLife.IoT standard interfaces with APM tracing support and built-in runtime messages in 31 languages. | Modbus RTU/ASCII 串口协议库,支持二进制 RTU(CRC-16)、ASCII(LRC)与轻量 RtuSimple 变体,适配 Windows 与 Linux 串口,基于 NewLife.IoT 标准接口,内置 APM 链路追踪与 31 种语言运行时消息。 |
|
|
NewLife.Schneider
Schneider PLC communication driver based on Modbus TCP. 基于 Modbus TCP 的施耐德 PLC 通信驱动库。 |
|
|
NewLife.Panasonic
松下PLC协议 |
|
|
NewLife.Fuji
富士PLC协议 |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on NewLife.Modbus:
| Repository | Stars |
|---|---|
|
NewLifeX/X
Core basic components: log (file / network), configuration (XML / JSON / HTTP), cache (memory / redis), network (TCP / UDP / HTTP), RPC framework, serialization (binary / XML / JSON), APM performance tracking. 核心基础组件,日志(文件/网络)、配置(XML/Json/Http)、缓存(内存/Redis)、网络(Tcp/Udp/Http)、RPC框架、序列化(Binary/XML/Json)、APM性能追踪。
|
| Version | Downloads | Last Updated |
|---|---|---|
| 2.1.2026.1024 | 328 | 10/24/2026 |
| 2.1.2026.1024-beta1440 | 129 | 10/24/2026 |
| 2.1.2026.1022-beta0202 | 142 | 10/22/2026 |
| 2.1.2026.902-beta1359 | 627 | 9/2/2026 |
| 2.1.2026.901 | 220 | 9/1/2026 |
| 2.1.2026.901-beta1641 | 151 | 9/1/2026 |
| 2.0.2026.722-beta1103 | 184 | 7/22/2026 |
| 2.0.2026.610 | 390 | 6/10/2026 |
| 2.0.2026.609-beta1551 | 181 | 6/9/2026 |
| 2.0.2026.501 | 215 | 5/1/2026 |
| 2.0.2026.501-beta1644 | 173 | 5/1/2026 |
| 2.0.2026.423-beta1215 | 182 | 4/23/2026 |
| 2.0.2026.303-beta1601 | 214 | 3/3/2026 |
| 2.0.2026.102-beta1656 | 241 | 1/2/2026 |
| 2.0.2025.818-beta1641 | 304 | 8/18/2025 |
| 2.0.2025.803-beta1524 | 290 | 8/3/2025 |
| 2.0.2025.803-beta1426 | 212 | 8/3/2025 |
| 2.0.2025.723-beta1756 | 667 | 7/23/2025 |
| 2.0.2025.701 | 2,731 | 7/1/2025 |
| 2.0.2025.701-beta1713 | 259 | 7/1/2025 |
新增 Modbus TCP/TLS 加密传输支持;新增 Enron Modbus 浮点数扩展协议;新增 FC07/11/12/17/20/22/24 等主从功能码;支持自定义功能码注册;增强连接自动重连稳定性;新增与 NModbus 3.x 竞品交叉兼容测试;测试用例全面异步化