iml6yu.DataService.ModbusTCP
1.2.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package iml6yu.DataService.ModbusTCP --version 1.2.0
NuGet\Install-Package iml6yu.DataService.ModbusTCP -Version 1.2.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="iml6yu.DataService.ModbusTCP" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="iml6yu.DataService.ModbusTCP" Version="1.2.0" />
<PackageReference Include="iml6yu.DataService.ModbusTCP" />
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 iml6yu.DataService.ModbusTCP --version 1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: iml6yu.DataService.ModbusTCP, 1.2.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 iml6yu.DataService.ModbusTCP@1.2.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=iml6yu.DataService.ModbusTCP&version=1.2.0
#tool nuget:?package=iml6yu.DataService.ModbusTCP&version=1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
iml6yu.DataService.ModbusTCP
iml6yu.DataService.ModbusTCP is a .NET library for slave of Modbus TCP data.
用法
ILogger logger;
DataServiceModbusOption option = new DataServiceModbusOption
{
IpAddress="",
Port=502, //TCP端口号
};
var dataService = new DataService.ModbusTCP.DataServiceModbusTCP(option, logger);
//启动Slave服务
dataService.StartServicer(token);
依赖
<PackageReference Include="System.IO.Ports" Version="8.0.0" />
<PackageReference Include="NModbus.Serial" Version="3.0.81" />
配置
{
"ServiceName": "DCSExampleTCP",
//Start: 这部分属于服务监听配置,根基实际情况配置ComName(串口RTU)或IPAddress(TCP)
"IPAddress": null, // null表示使用本机IP地址 Ip.Any 如果配置ComName表示的是串口通信
"Port": 502,
//End: 这部分属于服务监听配置,根基实际情况配置ComName(串口RTU)或IPAddress(TCP)
"Slaves": [
{
"Id": 1,
"Heart": {
"HeartType": "Number",
"HeartAddress": "1.ReadInputRegisters.61",
"HeartInterval": 5
},
//默认值
"DefaultValues": [
{
"Address": "1.Coils.0",
"DefaultValue": false
},
{
"Address": "1.Inputs.0",
"DefaultValue": false
},
{
"Address": "1.HoldingRegisters.0",
"DefaultValue": 0
},
{
"Address": "1.HoldingRegisters2.0",
"DefaultValue": 0
},
{
"Address": "1.HoldingRegisters4.0",
"DefaultValue": 0
},
{
"Address": "1.HoldingRegisters2ByteSwap.0",
"DefaultValue": 0
},
{
"Address": "1.HoldingRegisters4ByteSwap.0",
"DefaultValue": 0
}
]
}
]
}
源码
- DataServiceModbusOption (一个数据服务的配置)
- 源码
public class DataServiceModbusOption
{
/// <summary>
/// 服务名称
/// </summary>
public required string ServiceName { get; set; }
/// <summary>
/// 从站列表
/// </summary>
public List<DataServiceModbusSlaveOption> Slaves { get; set; }
#region TCP
public string? IPAddress { get; set; }
public int? Port { get; set; }
#endregion
#region RTU
/// <summary>
/// 端口号
/// </summary>
public string? ComName { get; set; }
/// <summary>
/// 波特率
/// </summary>
public int? BaudRate { get; set; }
/// <summary>
/// 校验位
/// </summary>
public Parity? Parity { get; set; }
/// <summary>
/// 数据位
/// </summary>
public int? DataBits { get; set; }
/// <summary>
/// 停止位
/// </summary>
public StopBits? StopBits { get; set; }
#endregion
}
- DataServiceModbusSlaveOption (每一个slave的store配置)
- 源码
public class DataServiceModbusSlaveOption
{
public byte Id { get; set; }
public HeartOption Heart { get; set; }
/// <summary>
/// 默认值
/// </summary>
public List<DataServiceStoreDefaultObjectItem> DefaultValues { get; set; }
}
- HeartOption (心跳配置)
- 源码
public class HeartOption
{
/// <summary>
/// 心跳类型
/// </summary>
public HeartType HeartType { get; set; }
/// <summary>
/// 心跳地址
/// </summary>
public string HeartAddress { get; set; }
/// <summary>
/// 心跳数据更新间隔 秒
/// </summary>
public int HeartInterval { get; set; }
}
- ModbusReadWriteType (读写类型)
- 源码
public enum ModbusReadWriteType
{
/// <summary>
/// 用于读取和控制远程设备的开关状态,通常用于控制继电器等开关设备, Reads from 1 to 2000 contiguous coils status.
/// </summary>
Coils,
/// <summary>
/// 用于读取远程设备的输入状态,通常用于读取传感器等输入设备的状态, Reads from 1 to 2000 contiguous discrete input status.
/// </summary>
Inputs,
/// <summary>
/// 用于存储和读取远程设备的数据,通常用于存储控制参数、设备状态等信息, Reads contiguous block of holding registers.
/// </summary>
HoldingRegisters,
/// <summary>
/// 32bit (默认大端 ABCD) 读取2个short 用于存储和读取远程设备的数据,通常用于存储控制参数、设备状态等信息, Reads contiguous block of holding registers.
/// </summary>
HoldingRegisters2,
/// <summary>
/// 32bit (默认大端 BADC) 读取2个short 用于存储和读取远程设备的数据,通常用于存储控制参数、设备状态等信息, Reads contiguous block of holding registers.
/// </summary>
HoldingRegisters2ByteSwap,
/// <summary>
/// 64bit (默认大端 ABCD EFGH) 读取4个short 用于存储和读取远程设备的数据,通常用于存储控制参数、设备状态等信息, Reads contiguous block of holding registers.
/// </summary>
HoldingRegisters4,
/// <summary>
/// 64bit (默认大端 BADC FEHG) 读取4个short 用于存储和读取远程设备的数据,通常用于存储控制参数、设备状态等信息, Reads contiguous block of holding registers.
/// </summary>
HoldingRegisters4ByteSwap,
/// <summary>
/// 32bit 小端(DCBA) 读取2个short 用于存储和读取远程设备的数据,通常用于存储控制参数、设备状态等信息, Reads contiguous block of holding registers.
/// </summary>
HoldingRegistersLittleEndian2,
/// <summary>
/// 32bit 小端(CDAB) 读取2个short 用于存储和读取远程设备的数据,通常用于存储控制参数、设备状态等信息, Reads contiguous block of holding registers.
/// </summary>
HoldingRegistersLittleEndian2ByteSwap,
/// <summary>
/// 64bit 小端(HGFE DCBA) 读取4个short 用于存储和读取远程设备的数据,通常用于存储控制参数、设备状态等信息, Reads contiguous block of holding registers.
/// </summary>
HoldingRegistersLittleEndian4,
/// <summary>
/// 64bit 小端(FEHG CDAB) 读取4个short 用于存储和读取远程设备的数据,通常用于存储控制参数、设备状态等信息, Reads contiguous block of holding registers.
/// </summary>
HoldingRegistersLittleEndian4ByteSwap,
/// <summary>
/// 用于存储远程设备的输入数据,通常用于存储传感器等输入设备的数据, Reads contiguous block of input registers.
/// </summary>
ReadInputRegisters,
/// <summary>
///32bit(ABCD) 读取2个short 用于存储远程设备的输入数据,通常用于存储传感器等输入设备的数据, Reads contiguous block of input registers.
/// </summary>
ReadInputRegisters2,
/// <summary>
///32bit(BADC) 读取2个short 用于存储远程设备的输入数据,通常用于存储传感器等输入设备的数据, Reads contiguous block of input registers.
/// </summary>
ReadInputRegisters2ByteSwap,
/// <summary>
/// 64bit(ABCD EFGH) 读取4个short 用于存储远程设备的输入数据,通常用于存储传感器等输入设备的数据, Reads contiguous block of input registers.
/// </summary>
ReadInputRegisters4,
/// <summary>
/// 64bit(BADC FEHG) 读取4个short 用于存储远程设备的输入数据,通常用于存储传感器等输入设备的数据, Reads contiguous block of input registers.
/// </summary>
ReadInputRegisters4ByteSwap,
/// <summary>
///32bit(DCBA) 小端 读取2个short 用于存储远程设备的输入数据,通常用于存储传感器等输入设备的数据, Reads contiguous block of input registers.
/// </summary>
ReadInputRegistersLittleEndian2,
/// <summary>
///32bit(CDAB) 小端 读取2个short 用于存储远程设备的输入数据,通常用于存储传感器等输入设备的数据, Reads contiguous block of input registers.
/// </summary>
ReadInputRegistersLittleEndian2ByteSwap,
/// <summary>
/// 64bit(HGFE DCBA) 小端 读取4个short 用于存储远程设备的输入数据,通常用于存储传感器等输入设备的数据, Reads contiguous block of input registers.
/// </summary>
ReadInputRegistersLittleEndian4,
/// <summary>
/// 64bit(GHEF CDAB) 小端 读取4个short 用于存储远程设备的输入数据,通常用于存储传感器等输入设备的数据, Reads contiguous block of input registers.
/// </summary>
ReadInputRegistersLittleEndian4ByteSwap
}
- DataServiceStoreDefaultObjectItem (默认值配置)
- 源码
public class DataServiceStoreDefaultDataItem<TValue> where TValue : notnull
{
/// <summary>
/// 地址
/// </summary>
public string Address { get; set; }
/// <summary>
/// 默认值
/// </summary>
public required TValue DefaultValue { get; set; }
}
public class DataServiceStoreDefaultObjectItem : DataServiceStoreDefaultDataItem<object>
{
}
public class DataServiceStoreDefaultBoolItem : DataServiceStoreDefaultDataItem<bool>
{
}
public class DataServiceStoreDefaultUShortItem : DataServiceStoreDefaultDataItem<ushort>
{
}
最后
如果在使用过程中遇到任何bug或者困难,可以添加WeChat或者是Microsoft Teams
| Microsoft Teams | |
|---|---|
| Join Us |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 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.
-
net6.0
- iml6yu.DataService.Modbus (>= 1.2.0)
-
net8.0
- iml6yu.DataService.Modbus (>= 1.2.0)
-
net9.0
- iml6yu.DataService.Modbus (>= 1.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.