下面要給大家介紹的是如何使用海創(chuàng)-IIoT平臺快速的采集歐姆龍PLC的數(shù)據(jù),我們使用的是CP1E-N20DR-A型號的PLC,采用HOSTLINK協(xié)議。
一.選擇產(chǎn)品
1、CP1E-N20DR-ACP1E
2、海創(chuàng)Box智能采集網(wǎng)關(guān)
3、串口服務(wù)器
二.設(shè)置PLC串口通訊
在歐姆龍PLC編程軟件CX-Programmer里面設(shè)置PLC的串口通訊的波特率、數(shù)據(jù)位、校驗(yàn)位、停止位、單元號和采集協(xié)議。
下圖為寄存器地址
三.采集數(shù)據(jù)
在桌面中打開海創(chuàng)-IIoT可視化編輯工具,進(jìn)入可視化編輯器。本次教程需要用到如下節(jié)點(diǎn),在左側(cè)節(jié)點(diǎn)欄中拖拽出使用
1、’定時(shí)器周期性觸發(fā)輸入時(shí)間戳或者相應(yīng)的字符
2、HostLink歐姆龍HostLink采集協(xié)議
下圖為本案例HostLink歐姆龍控件的配置內(nèi)容
下圖為服務(wù)器配置內(nèi)容
3、調(diào)試用于調(diào)試節(jié)點(diǎn)輸出
把三個(gè)控件用線連接起來組成一個(gè)流,點(diǎn)擊部署最后的效果如下圖所示
四.代碼示例
以上教程可以通過拷貝下面代碼實(shí)現(xiàn)快速復(fù)用,在新建的流程中點(diǎn)擊界面右側(cè)菜單欄-導(dǎo)入-剪貼板,在文本框中粘貼下面代碼后點(diǎn)擊確定,即可快速復(fù)用
[
{
"id": "47bba1db.0ca98",
"type": "inject",
"z": "aac35e85.a1cec",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 235,
"y": 240,
"wires": [
[
"bb8b0e84.34dc9"
]
]
},
{
"id": "bb8b0e84.34dc9",
"type": "iot-hostlink",
"z": "aac35e85.a1cec",
"name": "",
"server": "a9ca7528.fe2da8",
"columns": [
{
"Key": "D0000",
"Lable": "D區(qū)第0位",
"Area": "D",
"Address": "0000",
"Number": "1",
"ValueType": "Int16BE",
"Arithmetic": ""
},
{
"Key": "D0001",
"Lable": "D區(qū)第1位",
"Area": "D",
"Address": "0001",
"Number": "1",
"ValueType": "UInt16BE",
"Arithmetic": ""
}
],
"x": 350,
"y": 240,
"wires": [
[
"ec2ebc2f.77bd5"
]
]
},
{
"id": "ec2ebc2f.77bd5",
"type": "debug",
"z": "aac35e85.a1cec",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"x": 535,
"y": 240,
"wires": []
},
{
"id": "a9ca7528.fe2da8",
"type": "iot-hostlink-client",
"z": "",
"name": "",
"communicate": "Serial",
"host": "COM1",
"post": "502",
"baudrate": "115200",
"databits": "7",
"stopbits": "2",
"parity": "Even",
"expand": {
"UnitId": "0"
}
}
]