STTech.BytesIO.Modbus 3.2.0-beta0706

This is a prerelease version of STTech.BytesIO.Modbus.
dotnet add package STTech.BytesIO.Modbus --version 3.2.0-beta0706
                    
NuGet\Install-Package STTech.BytesIO.Modbus -Version 3.2.0-beta0706
                    
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="STTech.BytesIO.Modbus" Version="3.2.0-beta0706" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="STTech.BytesIO.Modbus" Version="3.2.0-beta0706" />
                    
Directory.Packages.props
<PackageReference Include="STTech.BytesIO.Modbus" />
                    
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 STTech.BytesIO.Modbus --version 3.2.0-beta0706
                    
#r "nuget: STTech.BytesIO.Modbus, 3.2.0-beta0706"
                    
#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 STTech.BytesIO.Modbus@3.2.0-beta0706
                    
#: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=STTech.BytesIO.Modbus&version=3.2.0-beta0706&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=STTech.BytesIO.Modbus&version=3.2.0-beta0706&prerelease
                    
Install as a Cake Tool

STTech.BytesIO.Modbus

STTech.BytesIO.Modbus 是一个基于 STTech.BytesIO 核心架构实现的全方位 Modbus 协议库。由于 Modbus 是基于帧协议的通信标准,它在 BytesIO 的基础上进行了封装与抽象,为开发者提供了更高级别、统一且易用的接口来处理 Modbus RTU、TCP 及 ASCII 通信。


✨ 特性 (Features)

  • 全面协议支持: 无缝覆盖工业界主流的 Modbus RTU, Modbus TCP, 和 Modbus ASCII
  • 标准功能码全支持:
    • 0x01 读线圈 (ReadCoilRegister)
    • 0x02 读离散输入 (ReadDiscreteInputRegister)
    • 0x03 读保持寄存器 (ReadHoldingRegister)
    • 0x04 读输入寄存器 (ReadInputRegister)
    • 0x05 写单个线圈 (WriteSingleCoilRegister)
    • 0x06 写单个保持寄存器 (WriteSingleHoldingRegister)
    • 0x0F 写多个线圈 (WriteMultipleCoilRegisters)
    • 0x10 写多个保持寄存器 (WriteMultipleHoldingRegisters)
  • 灵活的传输层底座: 可以根据需要无缝切换集成的 TCP 客户端 (TcpClient) 或串口客户端 (SerialClient) 作为底层传输通道,复用 BytesIO 强大的断线重连、零拷贝机制。
  • 高性能解包与校验: 内置 Modbus 专用解包器 (ModbusUnpacker),自动进行 CRC/LRC 校验与粘包/半包处理,确保数据帧的完整性与准确性。
  • 虚拟设备支持: 包含 VirtualModbusDevice,方便开发者进行本地联调与模拟测试。

🛠️ 安装 (Installation)

通过 NuGet 包管理器安装:

dotnet add package STTech.BytesIO.Modbus

📖 快速上手 (Quick Start)

1. Modbus TCP 客户端使用示例

使用 ModbusTcpClient 进行基于网络的通信:

using STTech.BytesIO.Modbus;

// 1. 创建 Modbus TCP 客户端
var client = new ModbusTcpClient { Host = "127.0.0.1", Port = 502 };

// 2. 异步连接
var connectResult = await client.ConnectAsync();
if (connectResult.IsSuccess) 
{
    // 3. 读取保持寄存器 (功能码 0x03)
    // 参数: 寄存器起始地址 0, 读取长度 10
    var response = await client.ReadHoldingRegisterAsync(0, 10);
    
    if (response.IsSuccess) 
    {
        // 成功获取到设备返回的原始字节数据
        byte[] rawData = response.Data; 
        Console.WriteLine($"读取成功: {BitConverter.ToString(rawData)}");
    }
    else 
    {
        Console.WriteLine($"读取失败: 错误码 {response.ErrorCode}");
    }
}

2. Modbus RTU (串口) 客户端使用示例

使用 ModbusSerialClient 进行基于串口的通信:

using STTech.BytesIO.Modbus;

// 1. 创建 Modbus RTU 串口客户端
var serialClient = new ModbusSerialClient { PortName = "COM1", BaudRate = 9600 };

// 2. 异步连接
await serialClient.ConnectAsync();

// 3. 写入单个线圈 (功能码 0x05)
// 参数: 站号(如果支持多设备的话,可通过封装的方法或传入), 寄存器地址 10, 值 true
var writeResponse = await serialClient.WriteSingleCoilRegisterAsync(10, true);

if (writeResponse.IsSuccess) {
    Console.WriteLine("线圈写入成功!");
}

3. Modbus 服务端 (虚拟设备) 示例

using STTech.BytesIO.Modbus;

// 创建 Modbus TCP 服务端并启动
var server = new ModbusTcpServer { Port = 502 };
server.Start();

Console.WriteLine("Modbus TCP 服务端已启动...");

🔗 返回主页

返回主项目文档: STTech.BytesIO 主页


Powered by KarFans Industrial Co., LTD.

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 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 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 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.

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
3.2.0-beta0706 0 7/12/2026
3.1.0.1-beta0630 103 6/30/2026
3.1.0-beta0629 94 6/29/2026
3.0.2-beta0324 119 3/23/2026
2.14.6.2-alpha0330 260 3/30/2025
2.14.6.1-alpha0807 208 8/6/2024
2.14.6 594 2/29/2024
2.14.6-alpha0225 196 2/25/2024
2.14.5.1 274 1/9/2024
2.14.5 293 1/7/2024
2.14.4 255 12/24/2023
2.14.3.2-beta1215 252 12/20/2023
2.14.3.1-beta1214 230 12/13/2023
2.14.2.1-beta1205 222 12/4/2023
2.14.1-beta1128 224 11/28/2023
2.13.6.1-alpha1116 271 11/16/2023
2.12.9-Alpha0721 283 7/21/2023
2.11.3-beta0905 580 9/4/2022
2.11.2-beta0903 328 9/3/2022
Loading failed