![]() |
VOOZH | about |
dotnet add package CSoft.Protocol.Modbus --version 10.2.0
NuGet\Install-Package CSoft.Protocol.Modbus -Version 10.2.0
<PackageReference Include="CSoft.Protocol.Modbus" Version="10.2.0" />
<PackageVersion Include="CSoft.Protocol.Modbus" Version="10.2.0" />Directory.Packages.props
<PackageReference Include="CSoft.Protocol.Modbus" />Project file
paket add CSoft.Protocol.Modbus --version 10.2.0
#r "nuget: CSoft.Protocol.Modbus, 10.2.0"
#:package CSoft.Protocol.Modbus@10.2.0
#addin nuget:?package=CSoft.Protocol.Modbus&version=10.2.0Install as a Cake Addin
#tool nuget:?package=CSoft.Protocol.Modbus&version=10.2.0Install as a Cake Tool
一个简洁易用的 Modbus RTU/TCP 通信库,支持泛型和 Attribute 驱动的数据映射。
public class SensorData
{
[CHProtocol(1)] // 寄存器地址 1
public float Temperature { get; set; }
[CHProtocol(3)] // 寄存器地址 3
public ushort Humidity { get; set; }
[CHProtocol(5)] // 寄存器地址 5
public float Pressure { get; set; }
[CHProtocol(7, count: 4)] // string 需要声明寄存器数量(4 寄存器 = 8 字节)
public string DeviceName { get; set; } = string.Empty;
}
// 创建 Modbus 主站(默认 RTU 模式)
IModBusMaster modBus = new ModBusMaster(new SerialPort("COM2"));
await modBus.OpenAsync();
byte address = 0x01;
// 直接读取并映射到类型
var data = await modBus.GetAsync<SensorData>(address);
Console.WriteLine($"温度: {data.Temperature}, 湿度: {data.Humidity}, 压力: {data.Pressure}, 名称: {data.DeviceName}");
var newData = new SensorData
{
Temperature = 25.5f,
Humidity = 60,
Pressure = 1013.25f,
DeviceName = "PUMP-A"
};
await modBus.SetAsync(0x01, newData);
var blockList = BlockList.From<SensorData>();
var channels = await modBus.GetAsync(0x01, blockList);
// 仍支持字符串地址格式:"1"、"01"、"0x01"
var data = await modBus.GetAsync<SensorData>("0x01");
| C# 类型 | Modbus 寄存器数 |
|---|---|
float |
2 |
double |
4 |
ushort |
1 |
uint |
2 |
short |
1 |
int |
2 |
string |
N(必须通过 CHProtocol(..., count: N) 指定) |
// TCP 模式
var modbusTcp = new ModBusMaster(new TcpClient("192.168.1.100", 502), ModbusType.TCP);
// 字节序配置
modBus.IsHighByteBefore_Req = false; // 请求低字节在前
modBus.IsHighByteBefore_Rsp = false; // 响应低字节在前
dotnet add package CSoft.Protocol.Modbus
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on CSoft.Protocol.Modbus:
| Package | Downloads |
|---|---|
|
CSoft.Protocol.TPF146D
泽天温压流146D通讯协议 |
|
|
CSoft.Protocol.TPF113B
泽天温压流113B通讯协议 |
|
|
CSoft.Protocol.DustAnalyzerSampling
泽天抽取粉尘仪通讯协议 |
|
|
CSoft.Protocol.DustAnalyzerSquare
泽天方型粉尘仪通讯协议 |
|
|
CSoft.Protocol.DustAnalyzerCircular
泽天圆型粉尘仪通讯协议 |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 10.2.0 | 111 | 5/28/2026 | |
| 10.1.1 | 112 | 5/19/2026 | |
| 10.1.0 | 104 | 5/11/2026 | |
| 10.0.10 | 126 | 3/31/2026 | |
| 10.0.9 | 120 | 3/30/2026 | |
| 10.0.8 | 255 | 1/14/2026 | |
| 10.0.7 | 193 | 1/14/2026 | |
| 10.0.6 | 196 | 1/13/2026 | |
| 10.0.5 | 185 | 1/13/2026 | |
| 10.0.4 | 186 | 1/13/2026 | |
| 10.0.3 | 194 | 1/9/2026 | |
| 10.0.2 | 212 | 1/8/2026 | |
| 10.0.1 | 158 | 1/8/2026 | 10.0.1 is deprecated because it has critical bugs. |
| 10.0.0 | 375 | 11/12/2025 | 10.0.0 is deprecated because it has critical bugs. |
| 9.3.2 | 354 | 8/5/2025 | 9.3.2 is deprecated because it has critical bugs. |
| 9.3.1 | 367 | 7/29/2025 | 9.3.1 is deprecated because it has critical bugs. |
| 9.3.0 | 653 | 7/24/2025 | 9.3.0 is deprecated because it has critical bugs. |
| 9.2.5 | 1,055 | 7/23/2025 | 9.2.5 is deprecated because it has critical bugs. |
| 9.2.4 | 1,077 | 7/23/2025 | 9.2.4 is deprecated because it has critical bugs. |
| 9.2.3 | 1,087 | 7/22/2025 | 9.2.3 is deprecated because it has critical bugs. |
依赖更新