本文主要是介绍DGIOT国内首家轻量级物联网开源平台——真实ModbusRTU接入实战教程,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
[小 迪 导读]:
本教程在掌握基础modbusRTU标准协议概念和业务流程之后,通过真实的支持ModbusRTU标准协议的设备和DTU来进行实战演练。
系统需要使用两个设备以及若干导线:
- 温湿度传感器:采用的是SHT20传感器 Modbus工业级
- DTU:采用的是有人的口红CAT-1 DTU DR154
系统架构逻辑图如下,包括设备模拟,通道通信,模型设置,应用显示部分
操作步骤:
1.设备接线
电表信息
模块 | 温湿度变送器 |
---|---|
型号 | SHT20传感器 |
类型 | Modbus 工业级 高精度 温湿度监测 |
- SHT20传感器
DTU信息
品牌 | 有人 |
---|---|
型号 | DR154(RS485) |
密码(Pwd) | usr_cn |
- dtu图片
操作步骤
SHT20传感器连接电源
SHT20传感器根据端口图正负连接电源正负,电源可以选用电源适配器。
DTU连接电源
根据DTU上的端口图,红色线(电源线)连接DC+,黑色线(地线)连接DC-
连接DTU和SHT20传感器
根据端口图,SHT20传感器的A端口连接DTU端口的RX(A),SHT20传感器的B端口连接DTU端口的TX(B)
说明 RX为接收,TX为发送
2.dtu配置
1.DTU正面二维码下方标识正负极连接电源,A,B端连接电表,到开手机微信扫码,扫描DTU二维码进入小程序,打开蓝牙连接与DTU背部IMEI相同编号的蓝牙,进入连接,密码为usr_cn。
2.打开参数设置,设置工作模式:地址设为部署的平台地址;端口号设为20111。
说明 地址为服务器地址,端口号为服务器端口号,若无自己的物联网服务器,可选择地址:prod.dgiotcloud.cn,端口号设为20111
警告 设置dtu时,工作模式设置完后需保存再设置串口,不能一次性设置,一次性设置会导致设置不完全
勾选注册包功能,注册包数据类型选择IMEI码,将会自动生成一个IMEI码。
3.打开参数设置,设置串口设置:波特率设为9600,校验位选择NONE。
说明 支持ModbusRTU的设备:参数可以询问商家或者商品介绍获取设备的参数
![file](https://img-blog.csdnimg.cn/img_convert/3340abedc5c60f61940ea0fb7c6c6612.png)3.创建采集通道
1.创建ModbusRTU采集通道。位置在通道管理-创建通道
2.选择Modbus采集通道并配置
3.产品添加通道后需对通道进行重启
4.通道日志查看
5.创建产品
1.要连接ModbusRTU,创建一种产品即可
2.创建产品
ModbusRTU
3.产品物模型配置
将以下物模型代码直接复制即可
ModbusRTU
{"events": [],"properties": [{"accessMode": "r","dataForm": {"address": "0X10","afn": "","byteType": "","bytelen": "","collection": "%%humid/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","dis": [{"data": "2","key": "0000","undefined": "0000"}],"operatetype": "readIregs","originaltype": "short16_AB","registersnumber": "1","slaveid": "temp_humid"},"dataType": {"das": [],"specs": {"max": 100,"min": 0,"precision": 3,"step": 0,"unit": "%"},"type": "float"},"devicetype": "温湿度传感器","identifier": "humid","index": 0,"isaccumulate": false,"isshow": true,"isstorage": true,"moduleType": "properties","name": "湿度","required": true,"updateAt": "1659081134998"},{"accessMode": "r","dataForm": {"address": "0X10","afn": "","byteType": "","bytelen": "","collection": "%%temp/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","dis": [{"data": "2","key": "0000","undefined": "0000"}],"operatetype": "readIregs","originaltype": "short16_AB","registersnumber": "1","slaveid": "temp_humid"},"dataType": {"das": [],"specs": {"max": 100,"min": -100,"precision": 3,"step": 0,"unit": "℃"},"type": "float"},"devicetype": "温湿度传感器","identifier": "temp","index": 1,"isaccumulate": false,"isshow": true,"isstorage": true,"moduleType": "properties","name": "温度","required": true,"updateAt": "1659081126141"},{"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": "3"},"dataSource": {"": [],"_dlinkindex": "","address": "0X0001","dis": [{"data": "2","key": "0000","undefined": "0000"}],"operatetype": "readIregs","originaltype": "bit","registersnumber": "2","slaveid": "0X01"},"dataType": {"das": [],"specs": {"max": 10000000000000000,"min": 0,"precision": 3,"step": 0,"unit": ""},"type": "int"},"devicetype": "温湿度传感器","identifier": "temp_humid","index": 2,"isaccumulate": false,"isshow": false,"isstorage": false,"moduleType": "properties","name": "温湿度","required": true,"updateAt": "1656584724858"}],"services": [],"tags": []
}
4.如何复制物模型
在产品管理-配置-物模型-查看物模型处
将物模型代码复制粘贴即可
复制完后可以点击编辑查看配置情况,dgiot针对modbusRTU多个数据的情况提供一次性全部读取的方案。
负责采集的物模型的下方数据来源与设备参数配置的一致
6.SHT20传感器设备连接的DTU注册成功
1.SHT20传感器设备连接的DTU注册成功
2.SHT20传感器设备连接的DTU上线成功3.设备地图显示成功
7.ModbusRTU数据采集成功
1.SHT20传感器实时数据
2.ModbusRTU历史数据[小 迪 提醒]
没有多个数据的modbusRTU设备的用户可以使用虚拟modbus软件自行模拟。
虚拟modbus连接点击了解详情。
[小 迪 点评]
- dgiot支持ModbusRTU协议的设备接入,有真实设备的用户尝试进行设备接入演练。
- 真实设备的接入针对新手玩家,dgiot的接线步骤将会提供很大的帮助。
想了解更多 dgiot 的具体细节,欢迎大家在GitHub上查看相关源代码。
这篇关于DGIOT国内首家轻量级物联网开源平台——真实ModbusRTU接入实战教程的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!