NewLife.ModbusRTU 2.1.2026.1024

dotnet add package NewLife.ModbusRTU --version 2.1.2026.1024
                    
NuGet\Install-Package NewLife.ModbusRTU -Version 2.1.2026.1024
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NewLife.ModbusRTU" Version="2.1.2026.1024" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NewLife.ModbusRTU" Version="2.1.2026.1024" />
                    
Directory.Packages.props
<PackageReference Include="NewLife.ModbusRTU" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NewLife.ModbusRTU --version 2.1.2026.1024
                    
#r "nuget: NewLife.ModbusRTU, 2.1.2026.1024"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NewLife.ModbusRTU@2.1.2026.1024
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NewLife.ModbusRTU&version=2.1.2026.1024
                    
Install as a Cake Addin
#tool nuget:?package=NewLife.ModbusRTU&version=2.1.2026.1024
                    
Install as a Cake Tool

NewLife.Modbus - ModbusTcp/ModbusRTU

GitHub top language GitHub License Nuget Downloads Nuget Nuget (with prereleases)

Nuget Downloads Nuget Nuget (with prereleases)

🌐 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 (with optional TLS), ModbusUDP, ModbusRTU (serial), ModbusASCII (serial), ModbusRtuOverTCP, ModbusRtuOverUDP, ModbusRtuSimple — 7 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 / SpanWriter for zero-allocation encoding/decoding, reducing GC pressure
  • Batch Optimization: BuildSegments automatically merges consecutive addresses, reading multiple points in a single request to reduce polling overhead
  • IoT Driver Integration: Implements the IDriver standard 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: ModbusRtuSimple targets resource-constrained edge devices with fewer dependencies and smaller memory footprint
  • APM Observability: Built-in ITracer tracing and ILog logging support, integrated with Stardust distributed platform
  • Multi-Framework: net45 / net461 / 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;
using NewLife.IoT.Protocols;
using NewLife.Log;

// 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: 0xFF00);

Master - ModbusRTU Serial Communication

using NewLife.Log;
using NewLife.Serial.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;
using NewLife.Log;

// 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 = (Byte)(i % 2) });

// Start the slave and begin listening
slave.Start();
Console.WriteLine("Modbus Slave started, port 502");

IoT Driver Layer Integration

using NewLife.IoT.Drivers;
using NewLife.IoT.ThingModels;

// 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)
IPoint[] points =
[
    new PointModel { Name = "Temperature", Address = "4x1", Type = "UInt16", Length = 2 },
    new PointModel { Name = "Running", Address = "1x1", Type = "Boolean", Length = 1 },
];
var result = driver.Read(node, points);

Ecosystem Map

NewLife is a layered ecosystem of independently versioned open-source projects. The map below is shared verbatim by every NewLife repository; each project links to its repository and its primary NuGet package.

Project What it does Downloads
Foundation
NewLife.Core Logging, configuration, caching, networking, serialization, scheduling and APM tracing. NuGet
NewLife.XCode Data middleware: single tables at the tens-of-billions scale, automatic sharding, read-write splitting, 10+ databases. NuGet
NewLife.Net High-performance network library: 1.77M pps / 14.5 Gbps on a single machine (TCP 1KB, 2026-10), 4M long-lived TCP connections. NuGet
NewLife.Remoting Protocol communication and RPC framework for client/server applications and IoT devices. NuGet
NewLife.Agent Installs .NET applications as OS daemons: Windows services and Linux systemd. NuGet
NewLife.Templates dotnet new project templates for console, web, API, service, data and IoT projects. NuGet
Data & Messaging
NewLife.Redis Redis client with microsecond latency, millions of ops/s and built-in message queues. NuGet
NewLife.RocketMQ Pure managed RocketMQ client for Apache RocketMQ and Alibaba Cloud Message Queue. NuGet
NewLife.MQTT MQTT client and server, including Alibaba Cloud IoT connectivity. NuGet
NewLife.NovaDb Hybrid database in C#: embedded or networked, relational, time-series, message queue and KV in one. NuGet
NewLife.MySql MySql driver and helper layer built on the NewLife data stack. NuGet
Web, AI & Distributed
NewLife.Cube Rapid admin-platform framework: permissions, SSO, OAuth server and CRUD scaffolding. NuGet
Stardust Distributed service platform: node management, APM, configuration center, registry and release center. NuGet
AntJob Distributed task and real-time data scheduling platform with sharding, retries and backfill. NuGet
NewLife.AI Unified client for 46 LLM providers plus ChatAI, a ready-to-run web chat application. NuGet
Industrial & IoT
NewLife.IoT IoT standard library defining protocol contracts and device abstractions. NuGet
NewLife.Modbus Modbus TCP/RTU/ASCII implementation on top of NewLife.IoT. NuGet
NewLife.Siemens Siemens PLC protocol on top of NewLife.IoT. NuGet
NewLife.Omron Omron PLC protocol on top of NewLife.IoT. NuGet
NewLife.Melsec Mitsubishi Melsec PLC protocol on top of NewLife.IoT. NuGet
NewLife.OPC OPC client for industrial data access. —
NewLife.BACnet BACnet building-automation protocol stack. NuGet
ZeroIoT Lightweight open-source IoT platform with gateway and device management. —
Vehicle Telematics
NewLife.JT808 JT/T 808 vehicle positioning protocol: 70+ message bodies, 2011/2013/2019. NuGet
NewLife.JT809 JT/T 809 platform-to-platform protocol for transport authorities. NuGet
NewLife.JT1078 JT/T 1078 in-vehicle video: RTP parsing, FLV/fMP4 remuxing and live streaming. NuGet
Domain Components
NewLife.Office One package for Excel, Word, PPT, PDF and 15+ document formats. NuGet
NewLife.Audio Cross-platform audio: codecs, device I/O, DSP, containers and streaming. NuGet
NewLife.Video Video codecs, container formats, frame processing and streaming. NuGet
NewLife.Map Unified interface over Baidu, AMap, Tencent and Tianditu with geocoding and coordinate conversion. NuGet
NewLife.IP IPv4 geolocation with an offline memory-mapped database and an online API fallback. NuGet
Tools & Products
CrazyCoder Developer toolbox: network, serial port, crypto, regex, Modbus and MQTT. NuGet
GitCandy Self-hosted Git source code management system. —
LuckyClover Installs the matching .NET runtime automatically when launched from an older host. —

Badges show the primary package of each project; theme, extension and satellite packages are listed on their NuGet pages. The 30+ packages not listed here (FTP, LoRa, Office extensions, protocol drivers and more) are available under the NewLifeX organization and on newlifex.com.

Team

<img src="/_dp/https://newlifex.com/logo.png" width="48" align="right" alt="NewLife" />

Founded in 2002, the NewLife team has spent more than two decades on the .NET and IoT ecosystem, maintains nearly 100 open-source projects (34 of them core to this map), and delivers integrated software and hardware solutions for power, logistics, healthcare, industrial control and internet industries. We live by the motto "learning has no seniority — mastery earns respect".

Open-source components have been downloaded 6.48M times from NuGet (ecosystem-wide, as of 2026-10).

Website: https://newlifex.com · Open source organization: https://github.com/NewLifeX

<details> <summary>WeChat Official Account: 智能大石头 (scan to follow)</summary>

智能大石头

</details>

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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 is compatible.  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 is compatible.  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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on NewLife.ModbusRTU:

Package Downloads
SmartA2

IoT驱动,符合IoT标准库的PC驱动,采集CPU、内存、网络等数据,提供语音播报和重启等服务。

SmartA4

IoT驱动,符合IoT标准库的PC驱动,采集CPU、内存、网络等数据,提供语音播报和重启等服务。

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on NewLife.ModbusRTU:

Repository Stars
NewLifeX/XCoder
新生命码神工具,代码生成、网络工具、API工具、串口工具、正则工具、图标工具、加解密工具、地图接口。
Version Downloads Last Updated
2.1.2026.1024 121 10/24/2026
2.1.2026.1024-beta1440 91 10/24/2026
2.1.2026.1022-beta0202 103 10/22/2026
2.1.2026.902-beta1359 160 9/2/2026
2.1.2026.901 161 9/1/2026
2.1.2026.901-beta1641 119 9/1/2026
2.0.2026.722-beta1103 142 7/22/2026
2.0.2026.610 188 6/10/2026
2.0.2026.609-beta1551 143 6/9/2026
2.0.2026.501 168 5/1/2026
2.0.2026.501-beta1644 140 5/1/2026
2.0.2026.423-beta1215 140 4/23/2026
2.0.2026.303-beta1601 184 3/3/2026
2.0.2026.102-beta1656 212 1/2/2026
2.0.2025.818-beta1641 283 8/18/2025
2.0.2025.803-beta1524 266 8/3/2025
2.0.2025.803-beta1427 214 8/3/2025
2.0.2025.723-beta1756 646 7/23/2025
2.0.2025.701 1,031 7/1/2025
2.0.2025.701-beta1714 261 7/1/2025
Loading failed

升级 NewLife.Core 12.0.2026.1024 与 NewLife.IoT 3.2.2026.1024;运行时消息与配置元数据本地化,词表覆盖 31 种语言;FC43 ReadDevId 支持指定起始 objectId;加固连接打开流程并清理可空性告警;补充 Modbus TCP 帧编解码器测试;从机越界请求返回标准异常响应 EC02/EC03 并按地址精确匹配;主站接收超时抛出 TimeoutException