DGIOT玩转Modbus教程——详谈数据块采集配置 - DGIOT

DGIOT玩转Modbus教程——详谈数据块采集配置

首页实战教程, 技术文章

file
[小 迪 导读]
本教程在掌握基础modbusRTU标准协议概念和业务流程之后,可以通过真实的ModbusRTU标准协议的设备和DTU来进行实战演练。


场景解析:在使用Modbus对设备进行采集时,我们会通过读取多个连续寄存器的数据块来保持多个数据的时间一致性,本文就来详细解读dgiot中的数据块配置


本文以温湿度设备为例:

和读单个寄存器的区别在于要多配一个数据块的物模型,这个数据块的作用在于一次性把多个连续的寄存器数据读取上来,再通过解析这个数据块,把数据分配下去,所以下图中只有数据块是要采集的,温度湿度是通过计算得来的
file

数据块的详细配置

file

1、数据存储配置

数据块配置只读不存储不展示
数据类型建议配置text长度9999,不过不存储情况下,此配置无关紧要
file

2、数据采集配置

采集策略默认20,协议类型MODBUSRTU,其余默认即可
file

3、数据来源(重点)
  • 从机地址:设备从机地址
  • 寄存器功能码:03读保持寄存器
  • 寄存器起始地址:就是第一个寄存器的起始地址,例如本文中,温度的寄存器起始地址是0X0200,湿度的寄存器起始地址是0X0201,此处填0X0200
  • 寄存器个数:本文两个,填2
  • 数据格式(重点)
    file
温湿度配置
1、数据存储和数据采集(温湿度一样)

采集策略选择不采集(计算值)因为采集策略是计算值,采集公式里的变量要填自己的标识符
其他的同以往一样
file

2、数据来源(重点)
  • 从机地址(重点):因为数据来源于数据块,所以填数据块的标识符
  • 寄存器功能码:03读保持寄存器(默认即可)
  • 寄存器起始地址(重点):位于数据块中的位置,从0开始,温度在数据块中位于第一个,所以填0,同理湿度填1
  • 寄存器个数:设备实际寄存器个数
  • 数据格式:设备实际寄存器数据格式

温度数据来源配置
file
湿度数据来源配置
file

物模型代码

{
    "properties": [
        {
            "accessMode": "r",
            "dataForm": {
                "address": "0X10",
                "afn": "",
                "byteType": "",
                "bytelen": "",
                "collection": "%{s}",
                "control": "%{d}",
                "countcollection": "%{s}",
                "countround": "all",
                "countstrategy": 20,
                "da": "",
                "data": "null",
                "dt": "",
                "iscount": "0",
                "offset": 0,
                "operatetype": "readCoils",
                "order": 0,
                "originaltype": "short16_AB",
                "protocol": "MODBUSRTU",
                "rate": 1,
                "round": "all",
                "slaveid": "0X10",
                "strategy": "20"
            },
            "dataSource": {
                "": [],
                "_dlinkindex": "",
                "address": "0X0200",
                "operatetype": "readHregs",
                "originaltype": "bit",
                "registersnumber": "2",
                "slaveid": "0X01"
            },
            "dataType": {
                "das": [],
                "size": 9999,
                "specs": {},
                "type": "text"
            },
            "devicetype": "数据块",
            "identifier": "block_data",
            "index": 0,
            "isaccumulate": false,
            "isshow": false,
            "isstorage": false,
            "moduleType": "properties",
            "name": "温湿度数据块",
            "required": true,
            "updateAt": "1695189804403"
        },
        {
            "accessMode": "r",
            "dataForm": {
                "address": "0X10",
                "afn": "",
                "byteType": "",
                "bytelen": "",
                "collection": "%%{humd}/10",
                "control": "%{d}",
                "countcollection": "%{s}",
                "countround": "all",
                "countstrategy": 20,
                "da": "",
                "data": "null",
                "dt": "",
                "iscount": "0",
                "offset": 0,
                "operatetype": "readCoils",
                "order": 0,
                "originaltype": "short16_AB",
                "protocol": "MODBUSRTU",
                "rate": 1,
                "round": "all",
                "slaveid": "0X10",
                "strategy": "计算值"
            },
            "dataSource": {
                "": [],
                "_dlinkindex": "",
                "address": "1",
                "operatetype": "readHregs",
                "originaltype": "ushort16_AB",
                "registersnumber": "1",
                "slaveid": "block_data"
            },
            "dataType": {
                "das": [],
                "specs": {
                    "max": 100,
                    "min": 0,
                    "precision": 3,
                    "step": 0,
                    "unit": "%"
                },
                "type": "float"
            },
            "devicetype": "温湿度",
            "identifier": "humd",
            "isaccumulate": false,
            "isshow": true,
            "isstorage": true,
            "moduleType": "properties",
            "name": "湿度",
            "required": true,
            "updateAt": "1695196699923",
            "index": 1
        },
        {
            "accessMode": "r",
            "dataForm": {
                "address": "0X10",
                "afn": "",
                "byteType": "",
                "bytelen": "",
                "collection": "%%{wendu}/10",
                "control": "%{d}",
                "countcollection": "%{s}",
                "countround": "all",
                "countstrategy": 20,
                "da": "",
                "data": "null",
                "dt": "",
                "iscount": "0",
                "offset": 0,
                "operatetype": "readCoils",
                "order": 0,
                "originaltype": "short16_AB",
                "protocol": "MODBUSRTU",
                "rate": 1,
                "round": "all",
                "slaveid": "0X10",
                "strategy": "计算值"
            },
            "dataSource": {
                "": [],
                "_dlinkindex": "",
                "address": "0",
                "operatetype": "readHregs",
                "originaltype": "short16_AB",
                "registersnumber": "1",
                "slaveid": "block_data"
            },
            "dataType": {
                "das": [],
                "specs": {
                    "max": 100,
                    "min": 0,
                    "precision": 3,
                    "step": 0,
                    "unit": "℃"
                },
                "type": "float"
            },
            "devicetype": "温湿度",
            "identifier": "wendu",
            "isaccumulate": false,
            "isshow": true,
            "isstorage": true,
            "moduleType": "properties",
            "name": "温度",
            "required": true,
            "updateAt": "1695196712029",
            "index": 2
        }
    ]
}

[小 迪 点 评]

  • dgiot支持ModbusRTU协议的连续寄存器读,有真实设备的用户尝试进行设备接入演练。

想了解更多 dgiot 的具体细节,欢迎大家在GitHub上查看相关源代码。

上一篇:
上一篇:

加小迪为好友
即可加入交流群

点击填写表单
获得解决方案专家帮助
点击前往 GitHub
查看源代码