iml6yu.DataReceive.ModbusMasterTCP
1.2.0
See the version list below for details.
dotnet add package iml6yu.DataReceive.ModbusMasterTCP --version 1.2.0
NuGet\Install-Package iml6yu.DataReceive.ModbusMasterTCP -Version 1.2.0
<PackageReference Include="iml6yu.DataReceive.ModbusMasterTCP" Version="1.2.0" />
<PackageVersion Include="iml6yu.DataReceive.ModbusMasterTCP" Version="1.2.0" />
<PackageReference Include="iml6yu.DataReceive.ModbusMasterTCP" />
paket add iml6yu.DataReceive.ModbusMasterTCP --version 1.2.0
#r "nuget: iml6yu.DataReceive.ModbusMasterTCP, 1.2.0"
#:package iml6yu.DataReceive.ModbusMasterTCP@1.2.0
#addin nuget:?package=iml6yu.DataReceive.ModbusMasterTCP&version=1.2.0
#tool nuget:?package=iml6yu.DataReceive.ModbusMasterTCP&version=1.2.0
iml6yu.DataReceive.ModbusMasterTCP
概要
iml6yu.DataReceive.ModbusMasterTCP是一个支持ModbusTCP协议的读取类库,支持.net6 .net8 .net9平台。
类库适用于各类数据采集平台,通过配置或者构造函数传入配置文件的形式,分组、分时定时读取数据,将数据采集的功能封装,让开发者可以集中精力处理业务逻辑。
license
MIT License
Copyright (c) 2021 iml6yu
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
用法
使用注入的方式实现
//关于option的实例化,根据智能提示操作
DataReceiverModbusTCPOption option = new DataReceiverModbusTCPOption();
/*
* 注入一个DataReceiverModbusTCP对象
* 参数说明:
* 第一个是配置信息
* 第二个是表示是否自动加载配置(仅当第一个参数给出配置文件路径时才有效)
* 第三个参数是读取点位的配置列表(当第三个参数不是null的时候,第一个参数给出的配置文件路径失效)
*/
builder.Services.AddReceiver(option, true, null);
配置文件 appsetting.json
"XXXXXX": {
"originName": "",//源登录账号
"originPwd": "",//源密码
"originHost": "127.0.0.1",
"originPort": 502,
"reConnectPeriod": 10000, //重连间隔 单位ms
"reConnectTimes": 2, //重连次数
"connectTimeout": 60000, //连接超时时间 单位ms
"receiverName": "warn_receiver", //
"nodeFile": "ConfigFiles/NodeConfigs/test.json",
"autoConnect": false
},
点位配置文件
FullAddress配置格式说明
格式 slaveAddress.ReadType.Bit 说明
- slaveAddress:站点ID,0~255
- ReadType:读取类型 一共有以下几种
- Coils <span style="color:blue">用于读取和控制远程设备的开关状态,通常用于控制继电器等开关设备,Reads from 1 to 2000 contiguous coils status.</span>",读取到的数据类型都是bool
- HoldingRegisters <span style="color:blue">用于存储和读取远程设备的数据,通常用于存储控制参数、设备状态等信息,Reads contiguous block of holding registers.</span>",读取到的数据类型都是ushort
- HoldingRegisters2 大端32位(ABCD) Int32
- HoldingRegisters2ByteSwap 大端32位(BADC) Int32
- HoldingRegisters4 大端64位(ABCD EFGH) Int64
- HoldingRegisters4ByteSwap 大端64位(BADC FEHG) Int64
- HoldingRegistersLittleEndian2 小端32位(DCBA) Int32
- HoldingRegistersLittleEndian2ByteSwap 小端32位(CDAB) Int32
- HoldingRegistersLittleEndian4 小端64位(HGFE DCBA) Int64
- HoldingRegistersLittleEndian4ByteSwap 小端64位(GHEF CDAB) Int64
- Inputs <span style="color:blue">用于读取远程设备的输入状态,通常用于读取传感器等输入设备的状态, Reads from 1 to 2000 contiguous discrete input status.</span>",读取到的数据类型都是bool
- ReadInputRegisters <span style="color:blue">用于存储远程设备的输入数据,通常用于存储传感器等输入设备的数据,Reads contiguous block of input registers.</span>",读取到的数据类型都是ushort
- ReadInputRegisters2 大端32位(ABCD) Int32
- ReadInputRegisters2ByteSwap 大端32位(BADC) Int32
- ReadInputRegisters4 大端64位(ABCD EFGH) Int64
- ReadInputRegisters4ByteSwap 大端64位(BADC FEHG) Int64
- ReadInputRegistersLittleEndian2 小端32位(DCBA) Int32
- ReadInputRegistersLittleEndian2ByteSwap 小端32位(CDAB) Int32
- ReadInputRegistersLittleEndian4 小端64位(HGFE DCBA) Int64
- ReadInputRegistersLittleEndian4ByteSwap 小端64位(GHEF CDAB) Int64
- Bit:点位,数字
例子
- 1.Coils.0
- 1.Coils.1
- 1.Coils.2
常用事件
- ConnectionEvent 连接事件,当连接状态发生变化时触发(第一个参数是Option)
- ErrorEvent 错误事件,当类库内发生错误时触发(第一个参数是Option)
- DataChangedEvent 当数据发生变动时触发(第一个参数是Option)
- DataIntervalEvent 数据定时读取出发事件(第一个参数是Option)
- <span style="color:#3333EE;font-weight: bold;">不常用</span>WarnEvent 警告事件,当类库内发生警告时触发(第一个参数是Option)
- <span style="color:#3333EE;font-weight: bold;">不常用</span>DataSubscribeEvent 当订阅数据发生变动时触发(第一个参数是Option)
常用方法
- StartWorkAsync(CancellationToken token) 开启数据读取线程
- Task StopWorkAsync() 停止数据读取线程
- ReadAllAsync(CancellationToken cancellationToken = default) 读取全部点位数据
- ReadAsync(string address, CancellationToken cancellationToken = default) 读取地址点位数据
- ReadsAsync(IEnumerable<string> addressArray, CancellationToken cancellationToken = default) 读取地址点位数据
- DirectReadAsync(IEnumerable<DataReceiveContractItem> addressArray, CancellationToken cancellationToken = default) 直接读取设备数据,绕过缓存,频繁调用影响性能。
- WriteAsync(DataWriteContract data) 写数据
- WriteAsync(DataWriteContractItem data) 写数据
- WriteAsync<T>(string address, T data) 写数据
- WriteWithVerifyAsync(DataWriteContract data) 写数据并且验证写入是否成功(大多数是因为业务中需要批量写入多条数据,并且设置了写入标志位)
最后
如果在使用过程中遇到任何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. |
-
net6.0
- iml6yu.DataReceive.Core (>= 1.2.0)
- iml6yu.DataReceive.ModbusMaster (>= 1.2.0)
- NModbus (>= 3.0.81)
-
net8.0
- iml6yu.DataReceive.Core (>= 1.2.0)
- iml6yu.DataReceive.ModbusMaster (>= 1.2.0)
- NModbus (>= 3.0.81)
-
net9.0
- iml6yu.DataReceive.Core (>= 1.2.0)
- iml6yu.DataReceive.ModbusMaster (>= 1.2.0)
- NModbus (>= 3.0.81)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.