[小 迪 导读]:
本教程在掌握基础modbusRTU标准协议概念和业务流程之后,通过真实的支持ModbusRTU标准协议的设备和DTU来进行实战演练。
系统需要使用一个测试软件:
系统架构逻辑图如下,包括设备模拟,通道通信,模型设置,应用显示部分
操作步骤:
1.创建产品
产品信息
产品添加通道后需对通道进行重启
2.创建物模型
物模型代码
{
"properties": [
{
"accessMode": "rw",
"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": "主动上报"
},
"dataSource": {
"": [],
"_dlinkindex": 1,
"address": "0X00",
"operatetype": "writeCoil",
"originaltype": "bit",
"registersnumber": "1",
"slaveid": "0X01"
},
"dataType": {
"das": [],
"specs": {
"1": "开",
"10": "关"
},
"type": "enum"
},
"devicetype": "开关控制器",
"identifier": "switch",
"isaccumulate": false,
"isshow": false,
"isstorage": false,
"moduleType": "properties",
"name": "开关",
"required": true,
"updateAt": "1664250089119",
"index": 0
}
]
}
3.添加低代码
{
"type": "form",
"body": [
{
"id": "u:52fbc3355570",
"mode": "inline",
"name": "switch",
"type": "switch",
"label": "开关机",
"onText": "开",
"option": "",
"offText": "关",
"trueValue": 1,
"falseValue": 10,
"validateApi": {
"url": "iotapi/classes/Device/parse_objectid",
"method": "put",
"headers": {
"store": "localStorage",
"dgiotReplace": "parse_objectid"
},
"requestAdaptor": "return {\r\n ...api,\r\n data:{\r\n profile:{\r\n switch:api.data.switch \r\n }\r\n }\r\n}"
},
"optionAtLeft": false,
"submitOnChange": true
}
],
"title": "开关机控制器",
"trueValue": true,
"falseValue": false,
"submitText": "",
"optionAtLeft": false
}
4.根据通道的登录报文帧头个数自定义设备名
打开网络调试助手
根据登录报文帧头个数填写15位(通道登录报文帧头测试可自定义,实际情况参考物理设备的登录报文编码个数),点击发送
5.查看登录的设备
找到之前产品内创建的低代码表单
选择开关,可以在网络调试助手上看到平台发送的报文,此报文也会是modbus设备收到的报文,实际情况参考物理设备使用说明
[小 迪 点评]
- dgiot支持ModbusRTU协议的设备接入,有真实设备的用户尝试进行设备接入演练,同时提供05功能码支持对设备控制。