LinkForge.Modbus
0.1.0
.NET 8.0
This package targets .NET 8.0. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
dotnet add package LinkForge.Modbus --version 0.1.0
NuGet\Install-Package LinkForge.Modbus -Version 0.1.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="LinkForge.Modbus" Version="0.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LinkForge.Modbus" Version="0.1.0" />
<PackageReference Include="LinkForge.Modbus" />
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 LinkForge.Modbus --version 0.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LinkForge.Modbus, 0.1.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 LinkForge.Modbus@0.1.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=LinkForge.Modbus&version=0.1.0
#tool nuget:?package=LinkForge.Modbus&version=0.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
LinkForge
面向 .NET 的工业通讯组件库,聚焦可独立发布为 NuGet 的传输层与协议层能力,当前已完成 TCP 通道与 Modbus TCP 的首个纵向闭环。
📦 NuGet 包
| 包名 | 说明 | 安装命令 |
|---|---|---|
LinkForge.Abstractions |
通道契约与基础异常模型 | dotnet add package LinkForge.Abstractions --version 0.1.0 |
LinkForge.Transports.Tcp |
基于 Socket/TcpClient 的 TCP 通道实现 |
dotnet add package LinkForge.Transports.Tcp --version 0.1.0 |
LinkForge.Modbus |
Modbus TCP 协议封装与常用功能码支持 |
dotnet add package LinkForge.Modbus --version 0.1.0 |
🧱 当前结构
src/LinkForge.Abstractions统一通道契约与基础异常模型。src/LinkForge.Transports.Tcp不依赖第三方库的 TCP 通道实现。src/LinkForge.Modbus当前提供Modbus TCP协议实现与常用功能码支持。samples/LinkForge.Sample.ModbusTcp最小可运行调用示例。tests面向传输层与协议层的回归测试工程。
✅ 当前能力
LinkForge.Transports.Tcp提供零第三方依赖的 TCP 通道实现,支持连接、发送、接收、超时控制。LinkForge.Modbus当前已支持以下Modbus TCP功能码:0x01读线圈0x02读离散输入0x03读保持寄存器0x04读输入寄存器0x05写单个线圈0x06写单个寄存器0x10写多个寄存器
- 协议层已包含:
- MBAP 头校验
- 事务标识符校验
- 单元标识符校验
- 异常响应转换为
ModbusException - 响应超时与半包接收处理
🎯 设计原则
KISS优先打通一个完整纵切面,不提前引入串口、重试、日志、连接池等复杂能力。YAGNI只实现当前明确需要的公共契约、TCP 传输与Modbus TCP常用能力。DRY协议层只依赖IChannel,后续UDP、串口、网关通道都可以复用同一套协议处理代码。SOLID传输层与协议层解耦,协议客户端不直接绑定具体 TCP 实现。
🚀 快速开始
dotnet add package LinkForge.Modbus --version 0.1.0
dotnet add package LinkForge.Transports.Tcp --version 0.1.0
using LinkForge.Modbus;
using LinkForge.Transports.Tcp;
using TcpChannel channel = new TcpChannel(new TcpChannelOptions
{
Host = "192.168.0.10",
Port = 502
});
using ModbusTcpClient client = new ModbusTcpClient(channel, new ModbusTcpClientOptions
{
UnitIdentifier = 1
});
await client.ConnectAsync();
ushort[] values = await client.ReadHoldingRegistersAsync(startAddress: 0, quantity: 2);
await client.DisconnectAsync();
如果需要完整可运行示例,可执行:
dotnet run --project "samples/LinkForge.Sample.ModbusTcp/LinkForge.Sample.ModbusTcp.csproj" -- --host 192.168.0.10 --port 502 --unit 1
也可以通过环境变量传参:
$env:LINKFORGE_MODBUS_HOST="192.168.0.10"
$env:LINKFORGE_MODBUS_PORT="502"
$env:LINKFORGE_MODBUS_UNIT_ID="1"
dotnet run --project "samples/LinkForge.Sample.ModbusTcp/LinkForge.Sample.ModbusTcp.csproj"
🧪 构建与验证
dotnet build "LinkForge.sln"
dotnet test "LinkForge.sln"
dotnet pack "LinkForge.sln" -c Release
生成的包默认输出到 artifacts/packages。
🛣️ 后续规划
- 继续补充异常响应、断连、超时、半包与事务号不匹配等回归场景。
- 视协议规划新增
LinkForge.Transports.Serial,再扩展Modbus RTU。 - 在抽象稳定后继续落地
S7、MC、OPC UA等独立包。
📄 许可证
本仓库使用 Apache License 2.0,详见根目录 LICENSE。
| 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 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. |
| .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 was computed. |
| .NET Framework | net461 was computed. 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.
-
.NETStandard 2.0
- LinkForge.Abstractions (>= 0.1.0)
-
net8.0
- LinkForge.Abstractions (>= 0.1.0)
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 |
|---|---|---|
| 0.1.0 | 109 | 3/20/2026 |
0.1.0 初始稳定版,包含公共通道抽象、TCP 传输实现、Modbus TCP 常用功能码与 xUnit 回归测试。