色猫咪av在线网址_91精品国产福利在线观看雪梨还会玩转热点_丁香花的视频免费观看_国产手机在线A∨免费视频_十八禁av无码免费网站APP_综合色一区二区亚洲_日韩精品小电影_漂亮人妻熟睡中被公侵犯_全新成人高清无码片_高级厕所偷窥白领美女嘘嘘

當前位置: 首頁 >應(yīng)用方案 >技術(shù)應(yīng)用 >

Modbus協(xié)議棧實現(xiàn)IO設(shè)備接入Node-RED網(wǎng)關(guān)的教程案例

案例教程簡介

Modbus協(xié)議常被用在工業(yè)現(xiàn)場,用于各類設(shè)備的數(shù)據(jù)采集以及遠程控制,Node-RED社區(qū)有很多開發(fā)者為Modbus協(xié)議提供了各種類型的Modbus節(jié)點,有用于邊緣采集的“node-red-node-arc-modbus” ,也有通用Modbus協(xié)議?!?/span>node-red-contrib-modbus”,接下來就通過使用Modbus協(xié)議棧演示Modbus IO設(shè)備接入Node-RED網(wǎng)關(guān)。

安裝步驟

1  Node-RED網(wǎng)關(guān)Modbus節(jié)點

與以往添加節(jié)點的方式一樣,先選擇菜單,進入“節(jié)點管理”,輸入節(jié)點名稱“node-red-contrib-modbus”,帶搜索完成后選擇對應(yīng)的節(jié)點,點擊安裝,帶安裝完成后會出現(xiàn)一系列的Modbus操作節(jié)點。

本片文章主要對靜態(tài)操作節(jié)點Modbus-Read”、“Modbus-Write”、“Modbus-Response”,以及動態(tài)操作節(jié)點“Modbus-Flex-Connector”、“Modbus-Flex-Getter”、“Modbus-Flex-Write”進行說明,利用上述節(jié)點即可實現(xiàn)遠程IO數(shù)據(jù)的采集和控制。

Modbus節(jié)點介紹

Modbus-Read”,網(wǎng)關(guān)作為主機,配置靜態(tài)連接參數(shù)以及靜態(tài)Modbus參數(shù),通過網(wǎng)絡(luò)、串口,以及配置的協(xié)議(Modbus RTUModbus TCP)去讀取指定Modbus從機的指定寄存器數(shù)據(jù)。

Modbus-Write”,網(wǎng)關(guān)作為主機,配置靜態(tài)連接參數(shù)以及靜態(tài)Modbus參數(shù),通過網(wǎng)絡(luò)、串口,以及配置的協(xié)議(Modbus RTUModbus TCP)與傳入的參數(shù)配置指定Modbus從機的指定寄存器數(shù)據(jù)。

Modbus-Read”與“Modbus-Write”在使用前都需要提前配置網(wǎng)關(guān)如何連接設(shè)備,左圖說明通過串口查詢的配置,右圖說明通過網(wǎng)絡(luò)查詢的配置;

2  Node-RED網(wǎng)關(guān)Modbus節(jié)點

Modbus-Read”節(jié)點需要配置設(shè)備的地址(Unit-id,我這里配置為104,也可以不輸入,若不輸入則采用連接時配置的默認設(shè)備地址,還需要配置采用的功能碼,我這通過讀取AO的整型值為例(查詢IO設(shè)備的寄存器表可以得到AO存放在40100-40103),所以FC(功能碼)配置為3(讀取保持寄存器),如果讀取AI該配置FC4(讀取輸入寄存器,查詢IO設(shè)備的寄存器表可以得到AO存放在30100-30103),在配置節(jié)點的地址為100,寄存器數(shù)量為4,自動輪詢?yōu)?/span>10s(可根據(jù)自己需要調(diào)整時基為毫秒、秒、分、時),選擇上一步配置的連接參數(shù)。

3  Node-RED網(wǎng)關(guān)Modbus節(jié)點

Modbus-Write”和“Read都具有地址、寄存器地址、數(shù)量、連接服務(wù)器,相同的參數(shù)配置方法相同不在單獨說明,寫入節(jié)點還需要傳入數(shù)據(jù),如右圖,傳入4個寄存器參數(shù)。

4  Node-RED網(wǎng)關(guān)Modbus節(jié)點

Modbus-Response”用于輸出前端Modbus節(jié)點的返回數(shù)據(jù)在Node-RED控制臺顯示的節(jié)點,一般不使用。

Modbus-Flex-Connector”用于與Modbus設(shè)備動態(tài)建立連接的節(jié)點,使用該節(jié)點需要傳入連接所需的參數(shù),以及配置存儲連接信息的空間(配置一個新的服務(wù)器節(jié)點,IP和端口可以任意配置,其余參數(shù)根據(jù)實際需求調(diào)整,這里采用TCP連接并通過Modbus TCP協(xié)議通信,超時時間為1000),其余參數(shù)可通過前端節(jié)點傳入。

5  Node-RED網(wǎng)關(guān)Modbus節(jié)點

添加inject”節(jié)點,添加“payload”對象,輸入JSON數(shù)據(jù){"connectorType":"TCP","tcpHost":"192.168.88.35","tcpPort":502},點擊部署,可通過手動觸發(fā)連接;

6  Node-RED網(wǎng)關(guān)Modbus節(jié)點

連接成功后調(diào)試日志接口輸出一下數(shù)據(jù);

7  Node-RED網(wǎng)關(guān)Modbus節(jié)點

Modbus-Flex-Getter”用于動態(tài)查詢IO設(shè)備參數(shù),需要傳入設(shè)備地址、功能碼、首地址寄存器、寄存器數(shù)量,目前該控件支持01、02、03、04功能碼,動態(tài)連接一樣,在節(jié)點前端添加一個“inject”傳入Modbus請求參數(shù);

8  Node-RED網(wǎng)關(guān)Modbus節(jié)點

Modbus-Flex-Write”用于動態(tài)寫入IO設(shè)備數(shù)據(jù),需要傳入設(shè)備地址、功能碼、首地址寄存器、寄存器數(shù)量、操作數(shù)據(jù),目前該控件支持單個操作的0506也支持連續(xù)操作的1516功能碼,與其他動態(tài)連接的節(jié)點一樣,在節(jié)點前端添加一個“inject”傳入Modbus請求參數(shù)和數(shù)據(jù);

9  Node-RED網(wǎng)關(guān)Modbus節(jié)點

下面為節(jié)點配置,可通過Node-RED導(dǎo)入功能復(fù)制本文案例;

10  Node-RED網(wǎng)關(guān)Modbus節(jié)點


動態(tài)連接參數(shù)輸入:

[{"id":"e45d6bd45793ccad","type":"modbus-flex-connector","z":"5d4fa2aa0a8f4fcf","name":"","maxReconnectsPerMinute":4,"emptyQueue":false,"showStatusActivities":false,"showErrors":false,"server":"904086e697ba6c29","x":370,"y":620,"wires":[["b4159f0075e37cfc"]]},{"id":"902892a0233fc0e2","type":"inject","z":"5d4fa2aa0a8f4fcf","name":"連接參數(shù)輸入","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{"connectorType":"TCP","tcpHost":"192.168.88.35","tcpPort":502}","payloadType":"json","x":110,"y":620,"wires":[["e45d6bd45793ccad"]]},{"id":"904086e697ba6c29","type":"modbus-client","name":"測試設(shè)備","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"failureLogEnabled":true,"tcpHost":"192.168.88.105","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity" :"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"0x3A","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true,"showWarnings":true,"showLogs":true}]

動態(tài)查詢參數(shù):

[{"id":"bb9ead56ab51483e","type":"modbus-flex-getter","z":"5d4fa2aa0a8f4fcf","name":"" , "showStatusActivities":false,"showErrors":false,"showWarnings":true,"logIOActivities":false,"server":"904086e697ba6c29","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"delayOnStart":false,"startDelayTime":"","x":350,"y":720,"wires":[[],["a051c717d9537768"]]},{"id":"181a3bf2d08b472d","type":"inject","z":"5d4fa2aa0a8f4fcf" ,"name" : "動態(tài)查詢AO狀態(tài)","props":[{"p":"payload.fc","v":"3","vt":"num"},{"p":"payload.unitid","v":"105","vt":"str"},{"p":"payload.address" , "v":"100","vt":"str"} , {"p":"payload.quantity","v":"4","vt":"str"}],"repeat":"","crontab":"","once": false ,"onceDelay" : 0.1,"topic":"","x":120,"y":720,"wires":[["bb9ead56ab51483e"]]},{"id":"904086e697ba6c29" , "type":"modbus-client" , "name" : "測試設(shè)備" ,"clienttype":"tcp","bufferCommands" : true," stateLogEnabled":false , "queueLogEnabled" : false,"failureLogEnabled":true,"tcpHost":"192.168.88.105" , "tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD" , "serialBaudrate" : "9600","serialDatabits" : "8","serialStopbits" : "1" , "serialParity":"none" ,"serialConnectionDelay":"100","serialAsciiResponseStartDelimiter" : "0x3A" , "unit_id":"1","commandDelay" :"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true,"showWarnings":true,"showLogs":true}]

動態(tài)修改寄存器:

[{"id":"2d5ea26349786e57","type":"modbus-flex-write" , "z" : "5d4fa2aa0a8f4fcf" , "name" : "","showStatusActivities":false,"showErrors":false,"showWarnings":true,"server":"904086e697ba6c29","emptyMsgOnFail":false,"keepMsgProperties":false,"delayOnStart":false,"startDelayTime":"","x":350,"y":780,"wires":[[],["a051c717d9537768"]]},{"id":"00d9fdbe7e55a434","type":"inject","z":"5d4fa2aa0a8f4fcf","name":"動態(tài)寫入AO","props":[{"p":"payload.value","v":"[20000,20000,20000,20000]","vt":"json"},{"p":"payload.fc" ,"v":"16","vt":"num"},{"p":"payload.unitid","v":"105","vt":"str"},{"p":"payload.address" , "v":"100","vt":"str"},{"p":"payload.quantity","v":"4","vt":"str"}],"repeat" :"","crontab" :"","once":false,"onceDelay" :0.1,"topic" :"","x":110,"y":780,"wires":[["2d5ea26349786e57"]]},{"id":"904086e697ba6c29","type":"modbus-client" ,"name" :"測試設(shè)備" , "clienttype" : "tcp","bufferCommands" : true,"stateLogEnabled" : false," queueLogEnabled": false,"failureLogEnabled" : true,"tcpHost" : "192.168.88.105" , "tcpPort" :"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD" , "serialBaudrate" :"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"0x3A","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true,"showWarnings":true,"showLogs":true}]


今天的分享就到這里啦,EBYTE每一天都致力于更好的助力物聯(lián)化、智能化、自動化的發(fā)展,提升資源利用率,更多串口服務(wù)器、數(shù)傳電臺、lora模塊等無線數(shù)傳模塊產(chǎn)品更多資料,感興趣的小伙伴可以登錄我們的億佰特官網(wǎng)和企業(yè)公眾號(微信號:cdebyte)進行了解,也可以直接撥打400電話咨詢技術(shù)專員!


相關(guān)閱讀:

1、Modbus協(xié)議通信傳輸詳解

2、Node-RED在物聯(lián)網(wǎng)自動化與智能化領(lǐng)域發(fā)展解析

3、Node-RED工具實現(xiàn)電表數(shù)據(jù)上云案例教程分享

4、Node-RED聯(lián)動云平臺物模型實現(xiàn)電表數(shù)據(jù)上報教程


億佰特官網(wǎng) 4000-330-990

https://www.wjx.cn/jq/84863372.aspx