SuperModbusClient 1.0.0
dotnet add package SuperModbusClient --version 1.0.0
NuGet\Install-Package SuperModbusClient -Version 1.0.0
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="SuperModbusClient" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SuperModbusClient" Version="1.0.0" />
<PackageReference Include="SuperModbusClient" />
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 SuperModbusClient --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SuperModbusClient, 1.0.0"
#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 SuperModbusClient@1.0.0
#: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=SuperModbusClient&version=1.0.0
#tool nuget:?package=SuperModbusClient&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SuperModbusClient
面向工业现场的 .NET 8 Modbus TCP 客户端通讯库,高可靠、长时间稳定运行、尽量减少通讯次数。
设计目标与能力
- 从站上下线状态事件:
SlaveStatusChanged(断线 / 上线) - 自动断线重连 + 手动重连:
ReconnectAsync - 通讯参数运行中更新后重连:
UpdateConnectionOptionsAsync - 端序仅在实例化时配置:
ABCD / BADC / CDAB / DCBA - 单一变量注册入口:
RegisterVariable(ModbusArea, address, type, bitIndex?, tag?) - 支持寄存器按位变量(如
4x0120.14→HoldingRegister + 地址 + bitIndex) - 每个变量独立值变化事件:
ModbusVariable.ValueChanged(仅返回实际值) - 地址可乱序注册,内部动态规划自动分块,尽量减少轮询请求次数
- 读写长度按实际变量类型精确计算,不使用固定长度粗读粗写
- 支持通过变量属性或标签读写:
variable.Value/client["Tag"] - 断线或异常期间仍可本地读写:写入先进入缓存队列,通讯恢复后自动下发并刷新
快速示例
using SuperModbusClient.Modbus;
var options = new ModbusConnectionOptions
{
Host = "127.0.0.1",
Port = 502,
UnitId = 1,
PollInterval = TimeSpan.FromMilliseconds(200),
ReconnectInterval = TimeSpan.FromSeconds(2)
};
await using var client = new ModbusTcpClient(options, ModbusEndianMode.ABCD);
client.SlaveStatusChanged += (_, e) =>
{
Console.WriteLine($"[{e.Timestamp:HH:mm:ss}] {e.PreviousStatus} -> {e.CurrentStatus} | {e.Reason}");
};
var b2 = client.RegisterVariable(ModbusArea.HoldingRegister, 0, ModbusVariableType.Bool, bitIndex: 1, tag: "B2");
var num1 = client.RegisterVariable(ModbusArea.HoldingRegister, 0, ModbusVariableType.Int16, tag: "Num1");
var pressure = client.RegisterVariable(ModbusArea.HoldingRegister, 2, ModbusVariableType.Float, tag: "Pressure");
b2.ValueChanged += value => Console.WriteLine($"B2 变化 -> {value}");
num1.ValueChanged += value => Console.WriteLine($"Num1 变化 -> {value}");
client.GetVariable("Pressure").ValueChanged += value => Console.WriteLine($"Pressure 变化 -> {value}");
await client.StartAsync();
// 属性写入
b2.Value = true;
// 标签写入
client["Num1"] = (short)1234;
// 标签读取(返回最近一次轮询值,或离线时本地缓存值)
var currentPressure = client["Pressure"];
核心文件
Modbus/ModbusTcpClient.cs:通讯核心(连接、重连、轮询、写入、事件)Modbus/ModbusConnectionOptions.cs:连接参数及边界校验Modbus/ModbusVariableDefinition.cs:变量定义与类型规则Modbus/ModbusValueCodec.cs:数据编解码与端序处理Modbus/ModbusVariable.cs:变量对象(标签、属性读写、单变量变化事件)
说明
- 变量写入统一通过
variable.Value = ...或client["Tag"] = ...。 - 断线/异常期间本地可读写,恢复后自动补写到从站
- Int16/Int32/寄存器位写入长度与指令精确性
- 地址乱序注册后的自动分块与通讯效率优化
- 重连抖动场景下连续读写稳定性(恢复后自动追平最后值)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 138 | 3/10/2026 |