Simple Modscan like UI for Modbus testing

This flow creates a Tab "Modscan" in Node-Red UI that allows to:

  • Manual SERIAL and TCP connection (NEW FEATURE)
  • Read Modscan Registers And Coils in real time (FC3 and FC1)
  • Convert 2*16bit registers in 32 bit
  • Convert values in HEX rappresentation
  • Convert values in Float IEEE-754 rappresentation
  • Write Registers and Coils (FC5 FC6)
  • Write Hex values (The hex value will be converted to int than sent to Modbus Write Node)

THIS FLOW HAS BEEN EDITED TO WORK WITH LAST NODE-RED-CONTRIB-MODBUS VERSION AT THIS DATE (2.3.2). TO MAKE IT WORK WITH OLDER/FUTURE VERSIONS OF MODBUS CHECK THE OUTPUT OF MODBUS FLEX READ AND USE THE CHANGE NODE TO MOVE READED DATA INTO msg.payload. ATM the payload of modbus-flex-read has 2 fileds: 'buffer' and 'data' so the change node is used to move msg.payload.data into msg.payload.

Modscan

[{"id":"12c49f15.e46c51","type":"tab","label":"MODSCAN","disabled":false,"info":""},{"id":"7e61ae6f.68472","type":"inject","z":"12c49f15.e46c51","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"x":127.1429443359375,"y":683.8571310043335,"wires":[["d63dbc75.a14d9"]]},{"id":"d63dbc75.a14d9","type":"function","z":"12c49f15.e46c51","name":"enable","func":"if(flow.get(\"enabled\")){\n   flow.set(\"count\", flow.get(\"count\") + 1);\n   msg.payload = {'fc': flow.get(\"FC\"), 'unitid': 1, 'address': flow.get(\"address\") , 'quantity': flow.get(\"length\"), 'conversion': flow.get(\"conversion\") };\n}else\n    msg = null;\n    \nreturn msg;","outputs":1,"noerr":0,"x":309.1429443359375,"y":683.8571310043335,"wires":[["8f3635fe.fa05f8"]]},{"id":"2180a06a.3d317","type":"ui_button","z":"12c49f15.e46c51","name":"","group":"e7f8efcf.c9e3b","order":7,"width":"3","height":"1","passthru":false,"label":"Start","color":"","bgcolor":"","icon":"","payload":"1","payloadType":"num","topic":"","x":429.6429443359375,"y":861.8571310043335,"wires":[["e24d0159.6b0a5"]]},{"id":"e24d0159.6b0a5","type":"function","z":"12c49f15.e46c51","name":"enable","func":"flow.set(\"enabled\", true);\nflow.set(\"count\", 0);","outputs":"0","noerr":0,"x":598.1429443359375,"y":861.8571310043335,"wires":[]},{"id":"ca78d977.a26f18","type":"ui_button","z":"12c49f15.e46c51","name":"","group":"e7f8efcf.c9e3b","order":8,"width":"3","height":"1","passthru":false,"label":"Stop","color":"","bgcolor":"","icon":"","payload":"1","payloadType":"num","topic":"","x":429.1429443359375,"y":912.8571310043335,"wires":[["2e983590.9e8bea"]]},{"id":"2e983590.9e8bea","type":"function","z":"12c49f15.e46c51","name":"disable","func":"flow.set(\"enabled\", false);","outputs":"0","noerr":0,"x":605.6429443359375,"y":912.8571310043335,"wires":[]},{"id":"31d34423.322c1c","type":"function","z":"12c49f15.e46c51","name":"save","func":"flow.set(\"address\", msg.payload);","outputs":"0","noerr":0,"x":595.1429443359375,"y":955.8571310043335,"wires":[]},{"id":"d058d019.d7af7","type":"function","z":"12c49f15.e46c51","name":"save","func":"flow.set(\"length\", msg.payload);","outputs":"0","noerr":0,"x":596.1429443359375,"y":1000.8571310043335,"wires":[]},{"id":"61338e7d.ad1f9","type":"function","z":"12c49f15.e46c51","name":"save","func":"flow.set(\"FC\", msg.payload);","outputs":"0","noerr":0,"x":593.1429443359375,"y":1043.8571310043335,"wires":[]},{"id":"8f3635fe.fa05f8","type":"modbus-flex-getter","z":"12c49f15.e46c51","name":"read","showStatusActivities":false,"showErrors":false,"server":"f0111c9.90187e","x":460.1429443359375,"y":682.8571310043335,"wires":[["df2fbfd1.0fc09"],[]]},{"id":"48e673c5.d0dccc","type":"ui_template","z":"12c49f15.e46c51","group":"85f4a53f.ba00c8","name":"","order":2,"width":"24","height":"10","format":"<div style=\"width:100%;\">\n    <div style=\"display:inline-block; width:25%;\" ng-repeat=\"x in msg.payload track by $index\">\n        {{!msg.input.payload.conversion ? \n        ($index + msg.input.payload.address) : \n        (($index*2 + msg.input.payload.address)+'-'+($index*2 + msg.input.payload.address+1))}} : {{ x }}\n    </div>\n</div>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":1296.14306640625,"y":702.8571166992188,"wires":[[]]},{"id":"907667a2.489968","type":"inject","z":"12c49f15.e46c51","name":"init","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":160.1429443359375,"y":862.8571310043335,"wires":[["5dba0e15.dbccc"]]},{"id":"5dba0e15.dbccc","type":"function","z":"12c49f15.e46c51","name":"init","func":"flow.set(\"FC\", 3);\nflow.set(\"address\", 1);\nflow.set(\"length\", 1);\nflow.set(\"enabled\", false);\nflow.set(\"count\", 0);\nflow.set(\"conversion\", 0);\nflow.set(\"hex\", 0);\nflow.set(\"conversion_float\", 0);","outputs":"0","noerr":0,"x":289.1429443359375,"y":862.8571310043335,"wires":[]},{"id":"72af28d.9e745d8","type":"inject","z":"12c49f15.e46c51","name":"init","topic":"","payload":"count","payloadType":"flow","repeat":"1","crontab":"","once":false,"x":482.1429443359375,"y":623.8571310043335,"wires":[["aac4a208.fdcc5"]]},{"id":"aac4a208.fdcc5","type":"ui_text","z":"12c49f15.e46c51","group":"85f4a53f.ba00c8","order":1,"width":"5","height":"1","name":"read count","label":"Total reads: ","format":"{{msg.payload}}","layout":"row-spread","x":637.6429748535156,"y":623.8571329116821,"wires":[]},{"id":"f483b69d.3af4f8","type":"status","z":"12c49f15.e46c51","name":"","scope":["8f3635fe.fa05f8"],"x":113.6429443359375,"y":623.8571310043335,"wires":[["6f45bdc8.26b744"]]},{"id":"6f45bdc8.26b744","type":"ui_text","z":"12c49f15.e46c51","group":"85f4a53f.ba00c8","order":1,"width":"5","height":"1","name":"Modbus status","label":"Status:","format":"{{msg.status.text}}","layout":"row-spread","x":294.1429443359375,"y":623.8571310043335,"wires":[]},{"id":"892cb1b.f24ac5","type":"function","z":"12c49f15.e46c51","name":"16To32Bit","func":"var values32bit = [];\n\nfor(var i=0;i<msg.payload.length;i++){\n    var tmp = msg.payload[i].toString(2);\n    tmp = tmp.length < 16 ? '0'.repeat(16-tmp.length) + tmp : tmp;\n    i++;\n    var tmp1 = i < msg.payload.length ? msg.payload[i].toString(2) : '0000000000000000';\n    tmp1 = tmp1.length < 16 ? '0'.repeat(16-tmp1.length) + tmp1 : tmp1;\n    var value = parseInt(tmp+tmp1,2);\n    if(flow.get('hex')) value = '0x'+value.toString(16).toUpperCase();\n        \n    values32bit.push(value);\n}\n\nmsg.payload = values32bit;\n\nreturn msg;","outputs":1,"noerr":0,"x":885.1429977416992,"y":707.8571300506592,"wires":[["140a01f5.6cb96e"]]},{"id":"2497c0e5.9016f","type":"switch","z":"12c49f15.e46c51","name":"","property":"conversion","propertyType":"flow","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","outputs":2,"x":745.6429443359375,"y":675.8571166992188,"wires":[["2e9079c8.47be26"],["892cb1b.f24ac5"]]},{"id":"3ef5a042.ef64f","type":"ui_switch","z":"12c49f15.e46c51","name":"","label":"32 bit","group":"e7f8efcf.c9e3b","order":4,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"","style":"","onvalue":"1","onvalueType":"num","onicon":"","oncolor":"","offvalue":"0","offvalueType":"num","officon":"","offcolor":"","x":429.6429443359375,"y":1083.8571310043335,"wires":[["226aedef.c0dcb2"]]},{"id":"226aedef.c0dcb2","type":"function","z":"12c49f15.e46c51","name":"save","func":"flow.set(\"conversion\", msg.payload);\nif(!flow.get(\"conversion\") && flow.get(\"conversion_float\"))\n flow.set(\"conversion_float\", 0);","outputs":"0","noerr":0,"x":592.1429443359375,"y":1083.8571310043335,"wires":[]},{"id":"73f5e8d4.a01398","type":"ui_dropdown","z":"12c49f15.e46c51","name":"","label":"FC","place":"FC","group":"e7f8efcf.c9e3b","order":3,"width":0,"height":0,"passthru":false,"options":[{"label":"Read Coil Status FC 1","value":1,"type":"num"},{"label":"Read Holding Register FC 3","value":3,"type":"num"}],"payload":"","topic":"","x":429.1429443359375,"y":1043.8571310043335,"wires":[["61338e7d.ad1f9"]]},{"id":"730b8a3c.19cac4","type":"inject","z":"12c49f15.e46c51","name":"","topic":"","payload":"address","payloadType":"flow","repeat":"","crontab":"","once":true,"x":214.1429443359375,"y":955.8571310043335,"wires":[["3fc345d2.a7405a"]]},{"id":"8eefd91a.e1a208","type":"inject","z":"12c49f15.e46c51","name":"","topic":"","payload":"length","payloadType":"flow","repeat":"","crontab":"","once":true,"x":213.1429443359375,"y":1000.8571310043335,"wires":[["ee944d7f.99dbd"]]},{"id":"e1546a72.378438","type":"inject","z":"12c49f15.e46c51","name":"","topic":"","payload":"FC","payloadType":"flow","repeat":"","crontab":"","once":true,"x":202.1429443359375,"y":1043.8571310043335,"wires":[["73f5e8d4.a01398"]]},{"id":"21346c5f.d9c214","type":"inject","z":"12c49f15.e46c51","name":"","topic":"","payload":"conversion","payloadType":"flow","repeat":"0.1","crontab":"","once":true,"x":230.1429443359375,"y":1083.8571310043335,"wires":[["3ef5a042.ef64f"]]},{"id":"f03adf15.38a45","type":"modbus-flex-write","z":"12c49f15.e46c51","name":"write","showStatusActivities":false,"showErrors":false,"server":"f0111c9.90187e","x":1173.1429443359375,"y":862.8571310043335,"wires":[[],[]]},{"id":"32ae54b5.a1682c","type":"ui_button","z":"12c49f15.e46c51","name":"write","group":"77708401.e47e9c","order":5,"width":"6","height":"1","passthru":false,"label":"WRITE","color":"","bgcolor":"","icon":"","payload":"true","payloadType":"bool","topic":"","x":868.1429443359375,"y":862.8571310043335,"wires":[["2c3267f1.1c55d8"]]},{"id":"2c3267f1.1c55d8","type":"function","z":"12c49f15.e46c51","name":"enable","func":"var value = flow.get(\"value\");\n\nif(flow.get(\"conversion_write\"))\n    value = parseInt(value, 16);\nelse value = parseInt(value);\n\nmsg.payload = {'value': value, 'fc': flow.get(\"FC_WRITE\"), 'unitid': 1, 'address': flow.get(\"address_write\") , 'quantity': 1 };\n\nreturn msg;","outputs":1,"noerr":0,"x":1018.1429443359375,"y":862.8571310043335,"wires":[["f03adf15.38a45"]]},{"id":"c4b9ff8e.28728","type":"function","z":"12c49f15.e46c51","name":"save","func":"flow.set(\"address_write\", msg.payload);","outputs":"0","noerr":0,"x":1287.6429443359375,"y":977.8571310043335,"wires":[]},{"id":"6753927.dda176c","type":"function","z":"12c49f15.e46c51","name":"save","func":"flow.set(\"FC_WRITE\", msg.payload);","outputs":"0","noerr":0,"x":1288.6429443359375,"y":1018.8571310043335,"wires":[]},{"id":"1c517852.9c0e68","type":"inject","z":"12c49f15.e46c51","name":"init","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":883.6429443359375,"y":923.8571310043335,"wires":[["1551480b.bc8248"]]},{"id":"1551480b.bc8248","type":"function","z":"12c49f15.e46c51","name":"init","func":"flow.set(\"FC_WRITE\", 6);\nflow.set(\"address_write\", 1);\nflow.set(\"conversion_write\", 0);","outputs":"0","noerr":0,"x":1012.6429443359375,"y":923.8571310043335,"wires":[]},{"id":"6f3657fc.12cad8","type":"ui_switch","z":"12c49f15.e46c51","name":"","label":"Hex to Int","group":"77708401.e47e9c","order":4,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"","style":"","onvalue":"1","onvalueType":"num","onicon":"","oncolor":"","offvalue":"0","offvalueType":"num","officon":"","offcolor":"","x":1133.1429443359375,"y":1058.8571310043335,"wires":[["424619a4.71a418"]]},{"id":"424619a4.71a418","type":"function","z":"12c49f15.e46c51","name":"save","func":"flow.set(\"conversion_write\", msg.payload);","outputs":"0","noerr":0,"x":1289.6429443359375,"y":1058.8571310043335,"wires":[]},{"id":"e048d5f3.881ed8","type":"ui_dropdown","z":"12c49f15.e46c51","name":"","label":"FC","place":"FC","group":"77708401.e47e9c","order":3,"width":"0","height":"0","passthru":false,"options":[{"label":"Force Single Coil FC 5","value":"5","type":"str"},{"label":"Force Single Register FC 6","value":6,"type":"num"}],"payload":"","topic":"","x":1124.6429443359375,"y":1018.8571310043335,"wires":[["6753927.dda176c"]]},{"id":"9c08918f.e1d47","type":"inject","z":"12c49f15.e46c51","name":"","topic":"","payload":"address_write","payloadType":"flow","repeat":"","crontab":"","once":true,"x":924.6429443359375,"y":977.8571310043335,"wires":[["6de8e401.51c2fc"]]},{"id":"e280cb4e.d380b8","type":"inject","z":"12c49f15.e46c51","name":"","topic":"","payload":"FC_WRITE","payloadType":"flow","repeat":"","crontab":"","once":true,"x":915.6429443359375,"y":1018.8571310043335,"wires":[["e048d5f3.881ed8"]]},{"id":"dbdb78d6.ed7688","type":"inject","z":"12c49f15.e46c51","name":"","topic":"","payload":"conversion_write","payloadType":"flow","repeat":"0.1","crontab":"","once":true,"x":933.6429443359375,"y":1058.8571310043335,"wires":[["6f3657fc.12cad8"]]},{"id":"da212dbd.a20b9","type":"ui_text_input","z":"12c49f15.e46c51","name":"","label":"Value","group":"77708401.e47e9c","order":2,"width":"3","height":"1","passthru":false,"mode":"text","delay":"100","topic":"","x":1122.1429443359375,"y":1098.8571310043335,"wires":[["a3b3dc90.32a3a"]]},{"id":"a3b3dc90.32a3a","type":"function","z":"12c49f15.e46c51","name":"save","func":"flow.set(\"value\", msg.payload);","outputs":"0","noerr":0,"x":1288.6429443359375,"y":1098.8571310043335,"wires":[]},{"id":"bc32c656.63dd08","type":"comment","z":"12c49f15.e46c51","name":"READ","info":"","x":74.6429443359375,"y":809.8571310043335,"wires":[]},{"id":"86119923.529278","type":"comment","z":"12c49f15.e46c51","name":"WRITE","info":"","x":804.1429443359375,"y":810.8571310043335,"wires":[]},{"id":"557afeed.d87ea","type":"comment","z":"12c49f15.e46c51","name":"OUTPUT","info":"","x":86.1429443359375,"y":570.8571310043335,"wires":[]},{"id":"abef09c9.f5bdb8","type":"ui_switch","z":"12c49f15.e46c51","name":"","label":"Hex Values","group":"e7f8efcf.c9e3b","order":6,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"","style":"","onvalue":"1","onvalueType":"num","onicon":"","oncolor":"","offvalue":"0","offvalueType":"num","officon":"","offcolor":"","x":435.9085693359375,"y":1130.6071310043335,"wires":[["48fa09e6.b83238"]]},{"id":"48fa09e6.b83238","type":"function","z":"12c49f15.e46c51","name":"save","func":"flow.set(\"hex\", msg.payload);\n\nif(flow.get(\"hex\") && flow.get(\"conversion_float\"))\n flow.set(\"conversion_float\", 0);","outputs":"0","noerr":0,"x":589.4085693359375,"y":1130.6071310043335,"wires":[]},{"id":"a46efc10.9006a","type":"inject","z":"12c49f15.e46c51","name":"","topic":"","payload":"hex","payloadType":"flow","repeat":"0.1","crontab":"","once":true,"x":200.4085693359375,"y":1130.6071310043335,"wires":[["abef09c9.f5bdb8"]]},{"id":"2e9079c8.47be26","type":"switch","z":"12c49f15.e46c51","name":"","property":"hex","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","outputs":2,"x":878.9086074829102,"y":669.6071166992188,"wires":[["2b6c773c.2db548"],["48e673c5.d0dccc"]]},{"id":"2b6c773c.2db548","type":"function","z":"12c49f15.e46c51","name":"toHex","func":"for(var i=0;i<msg.payload.length;i++)\n   msg.payload[i] = '0x'+msg.payload[i].toString(16).toUpperCase();\n\nreturn msg;","outputs":1,"noerr":0,"x":1034.9085693359375,"y":662.6071166992188,"wires":[["48e673c5.d0dccc"]]},{"id":"7ffe0f09.7d994","type":"inject","z":"12c49f15.e46c51","name":"","topic":"","payload":"conversion_float","payloadType":"flow","repeat":"0.1","crontab":"","once":true,"x":221.1429443359375,"y":1176.8571310043335,"wires":[["5eb81fe2.00732"]]},{"id":"5eb81fe2.00732","type":"ui_switch","z":"12c49f15.e46c51","name":"","label":"Float","group":"e7f8efcf.c9e3b","order":5,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"","style":"","onvalue":"1","onvalueType":"num","onicon":"","oncolor":"","offvalue":"0","offvalueType":"num","officon":"","offcolor":"","x":410.6429443359375,"y":1176.8571310043335,"wires":[["6f42aed7.4e21e"]]},{"id":"6f42aed7.4e21e","type":"function","z":"12c49f15.e46c51","name":"save","func":"flow.set(\"conversion_float\", msg.payload);\nif(!flow.get(\"conversion\") && flow.get(\"conversion_float\"))\n flow.set(\"conversion\", 1);\n\nif(flow.get(\"conversion_float\"))\n    flow.set(\"hex\", 0);","outputs":"0","noerr":0,"x":587.1429443359375,"y":1176.8571310043335,"wires":[]},{"id":"140a01f5.6cb96e","type":"switch","z":"12c49f15.e46c51","name":"","property":"conversion_float","propertyType":"flow","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","outputs":2,"x":1031.1429443359375,"y":737.8571166992188,"wires":[["48e673c5.d0dccc"],["1de73100.a7a9af"]]},{"id":"974e10f2.a760c","type":"comment","z":"12c49f15.e46c51","name":"CONNECTION","info":"","x":118.46179962158203,"y":41.56597328186035,"wires":[]},{"id":"c3945a93.2c3b48","type":"ui_text_input","z":"12c49f15.e46c51","name":"","label":"Address","group":"1e8fcf9f.e3096","order":3,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"","x":546.4617919921875,"y":131.01041412353516,"wires":[["9908f867.6289e8"]]},{"id":"c4e491c3.c92d8","type":"modbus-flex-connector","z":"12c49f15.e46c51","name":"connection","maxReconnectsPerMinute":4,"emptyQueue":false,"showStatusActivities":false,"showErrors":false,"server":"f0111c9.90187e","x":450.46185302734375,"y":385.01045298576355,"wires":[]},{"id":"2f9c068f.99fefa","type":"ui_text_input","z":"12c49f15.e46c51","name":"","label":"Port","group":"1e8fcf9f.e3096","order":4,"width":"3","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":536.4791259765625,"y":175.01040649414062,"wires":[["bde4ca70.c2d3d8"]]},{"id":"9908f867.6289e8","type":"function","z":"12c49f15.e46c51","name":"save","func":"var options = flow.get(\"TCP_Connection\") || {};\n\noptions.tcpHost = msg.payload;\n\nflow.set(\"TCP_Connection\", options);","outputs":"0","noerr":0,"x":700.017333984375,"y":131.23263549804688,"wires":[]},{"id":"bde4ca70.c2d3d8","type":"function","z":"12c49f15.e46c51","name":"save","func":"var options = flow.get(\"TCP_Connection\") || {};\n\noptions.tcpPort = msg.payload;\n\nflow.set(\"TCP_Connection\", options);","outputs":"0","noerr":0,"x":698.017333984375,"y":175.23263549804688,"wires":[]},{"id":"83683954.71fed8","type":"ui_text_input","z":"12c49f15.e46c51","name":"","label":"Unit ID","group":"1e8fcf9f.e3096","order":5,"width":"3","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":535.4791412353516,"y":225.23263549804688,"wires":[["4c9b48f4.b89cf8"]]},{"id":"4c9b48f4.b89cf8","type":"function","z":"12c49f15.e46c51","name":"save","func":"var options = flow.get(\"TCP_Connection\") || {};\n\noptions.unitId = msg.payload;\n\nflow.set(\"TCP_Connection\", options);","outputs":"0","noerr":0,"x":697.0173492431641,"y":225.45486450195312,"wires":[]},{"id":"df896034.e0522","type":"inject","z":"12c49f15.e46c51","name":"","topic":"","payload":"TCP_Connection","payloadType":"flow","repeat":"","crontab":"","once":true,"x":136,"y":147.23263549804688,"wires":[["37c4b846.c34188","6ca02e22.ac401","bf1ec8e4.4f37a8","3f64d325.a9357c"]]},{"id":"37c4b846.c34188","type":"change","z":"12c49f15.e46c51","name":"set","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.tcpHost","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":385.0173645019531,"y":131.23263549804688,"wires":[["c3945a93.2c3b48"]]},{"id":"6ca02e22.ac401","type":"change","z":"12c49f15.e46c51","name":"set","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.tcpPort","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":383.0173645019531,"y":175.23263549804688,"wires":[["2f9c068f.99fefa"]]},{"id":"bf1ec8e4.4f37a8","type":"change","z":"12c49f15.e46c51","name":"set","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.unitId","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":380.0173645019531,"y":225.23263549804688,"wires":[["83683954.71fed8"]]},{"id":"ac9b284d.e8d508","type":"ui_button","z":"12c49f15.e46c51","name":"connectTCP","group":"1e8fcf9f.e3096","order":6,"width":0,"height":0,"passthru":false,"label":"Connect","color":"","bgcolor":"","icon":"compare_arrows","payload":"TCP_Connection","payloadType":"flow","topic":"","x":109.01741790771484,"y":357.2326593399048,"wires":[["ccf807ba.eaffc8"]]},{"id":"ccf807ba.eaffc8","type":"function","z":"12c49f15.e46c51","name":"connect","func":"var options = msg.payload;\nvar error = {topic: \"TCP Connect\"};\nvar configs = flow.get('configs_TCP') || [];\n\noptions.connectorType = \"TCP\";\n\nif(!options.name || options.name === \"\"){\n    options.name = \"No name\";\n}\n\nif(!options.tcpPort)\n    options.tcpPort = 502;\n\nif(!options.tcpHost){\n    error.payload = \"TCP Host address not Valid\";\n    node.error(\"Error\",error);\n    return;\n}\n\nvar index = configs.findIndex(function(conf) {\n    return conf.name == options.name;\n});\n\nif(index < 0)\n    configs.push(options);\nelse\n    configs[index] = options;\n    \nflow.set('configs_TCP', configs);\n\nnode.send([msg, {payload:configs, topic:\"init\"}]);","outputs":"2","noerr":0,"x":288.0174217224121,"y":357.23265838623047,"wires":[["c4e491c3.c92d8","4f86ecb.7b49914"],["fc746988.96f108"]]},{"id":"8016303f.19018","type":"ui_text_input","z":"12c49f15.e46c51","name":"custom port","label":"or choose a custom Port","group":"2daa58ed.8d8da8","order":4,"width":"6","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":1330.03466796875,"y":157.23262786865234,"wires":[["8a3de4bb.54d2c8"]]},{"id":"6fb48c83.cd92a4","type":"ui_text_input","z":"12c49f15.e46c51","name":"","label":"Unit ID","group":"2daa58ed.8d8da8","order":5,"width":"3","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":1308.034683227539,"y":200.4548568725586,"wires":[["5d077c2f.816184"]]},{"id":"cf9ecc46.26edb","type":"inject","z":"12c49f15.e46c51","name":"","topic":"","payload":"SERIAL_Connection","payloadType":"flow","repeat":"","crontab":"","once":true,"x":926.5555419921875,"y":152.4548568725586,"wires":[["b1f9e1ab.b81bd","e8db20b1.edd77","670c6760.b8df78","834156a0.940508","65e39185.5970c"]]},{"id":"b1f9e1ab.b81bd","type":"change","z":"12c49f15.e46c51","name":"set","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.serialPort","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1162.5729064941406,"y":157.4548568725586,"wires":[["8016303f.19018"]]},{"id":"e8db20b1.edd77","type":"change","z":"12c49f15.e46c51","name":"set","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.unitId","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1160.5729064941406,"y":200.4548568725586,"wires":[["6fb48c83.cd92a4"]]},{"id":"917084.c9c9cf8","type":"function","z":"12c49f15.e46c51","name":"save","func":"var options = flow.get(\"SERIAL_Connection\") || {};\n\nif(msg.payload)\n    options.serialPort = msg.payload;\n\nflow.set(\"SERIAL_Connection\", options);","outputs":"0","noerr":0,"x":1479.5728759765625,"y":111.4548568725586,"wires":[]},{"id":"670c6760.b8df78","type":"change","z":"12c49f15.e46c51","name":"set","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.serialPort","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1164.5729064941406,"y":111.4548568725586,"wires":[["1b0c61ab.bd4ede"]]},{"id":"1b0c61ab.bd4ede","type":"ui_dropdown","z":"12c49f15.e46c51","name":"port","label":"Port","place":"Choose a serial port","group":"2daa58ed.8d8da8","order":3,"width":"6","height":"1","passthru":true,"options":[{"label":"/dev/ttyUSB0","value":"/dev/ttyUSB0","type":"str"},{"label":"/dev/ttyUSB1","value":"/dev/ttyUSB1","type":"str"},{"label":"/dev/ttyAMA0","value":"/dev/ttyAMA0","type":"str"}],"payload":"","topic":"","x":1311.5729064941406,"y":111.78819942474365,"wires":[["917084.c9c9cf8"]]},{"id":"8a3de4bb.54d2c8","type":"function","z":"12c49f15.e46c51","name":"save","func":"var options = flow.get(\"SERIAL_Connection\") || {};\n\noptions.serialPort = msg.payload;\n\nflow.set(\"SERIAL_Connection\", options);","outputs":"0","noerr":0,"x":1480.5728759765625,"y":156.78819274902344,"wires":[]},{"id":"5d077c2f.816184","type":"function","z":"12c49f15.e46c51","name":"save","func":"var options = flow.get(\"SERIAL_Connection\") || {};\n\noptions.unitId = msg.payload;\n\nflow.set(\"SERIAL_Connection\", options);","outputs":"0","noerr":0,"x":1480.5728759765625,"y":199.78819274902344,"wires":[]},{"id":"834156a0.940508","type":"change","z":"12c49f15.e46c51","name":"set","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.serialBaudrate","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1161.111099243164,"y":245.78817749023438,"wires":[["d8cb24a9.6b74a8"]]},{"id":"d3e2fd5b.0450f","type":"function","z":"12c49f15.e46c51","name":"save","func":"var options = flow.get(\"SERIAL_Connection\") || {};\n\noptions.serialBaudrate = msg.payload;\n\nflow.set(\"SERIAL_Connection\", options);","outputs":"0","noerr":0,"x":1481.111068725586,"y":246.12151336669922,"wires":[]},{"id":"552fc152.b9b7f","type":"ui_button","z":"12c49f15.e46c51","name":"connectSERIAL","group":"2daa58ed.8d8da8","order":7,"width":0,"height":0,"passthru":false,"label":"Connect","color":"","bgcolor":"","icon":"compare_arrows","payload":"SERIAL_Connection","payloadType":"flow","topic":"","x":120.0173568725586,"y":409.7881774902344,"wires":[["b64a6bec.83dec8"]]},{"id":"d8cb24a9.6b74a8","type":"ui_dropdown","z":"12c49f15.e46c51","name":"BaudRate","label":"Baud Rate","place":"Select a Boud Rate","group":"2daa58ed.8d8da8","order":6,"width":0,"height":0,"passthru":true,"options":[{"label":"","value":115200,"type":"num"},{"label":"","value":57600,"type":"num"},{"label":"","value":38400,"type":"num"},{"label":"","value":19200,"type":"num"},{"label":"","value":9600,"type":"num"},{"label":"","value":4800,"type":"num"},{"label":"","value":2400,"type":"num"},{"label":"","value":1200,"type":"num"},{"label":"","value":300,"type":"num"},{"label":"","value":110,"type":"num"},{"label":"","value":75,"type":"num"}],"payload":"","topic":"","x":1315.239501953125,"y":245.78817749023438,"wires":[["d3e2fd5b.0450f"]]},{"id":"d93628a4.45c778","type":"ui_dropdown","z":"12c49f15.e46c51","name":"configurations","label":"Configurations","place":"Choose a conf...","group":"1e8fcf9f.e3096","order":1,"width":0,"height":0,"passthru":true,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","x":1119.731704711914,"y":334.5819034576416,"wires":[["36533ff8.402c"]]},{"id":"1bfa4b33.e63455","type":"inject","z":"12c49f15.e46c51","name":"","topic":"init","payload":"configs_TCP","payloadType":"flow","repeat":"","crontab":"","once":true,"x":749.0174331665039,"y":385.01042461395264,"wires":[["fc746988.96f108"]]},{"id":"fc746988.96f108","type":"function","z":"12c49f15.e46c51","name":"options","func":"var options = [];\n\n\n(msg.payload || []).forEach(function(opt) {\n    var tmp = {};\n    tmp[opt.name] = opt;\n    options.push(tmp);\n});\n\nmsg.options = options;\n\nreturn msg;","outputs":1,"noerr":0,"x":935.0173721313477,"y":364.01040267944336,"wires":[["d93628a4.45c778"]]},{"id":"37abf753.f84de8","type":"ui_text_input","z":"12c49f15.e46c51","name":"","label":"Name","group":"1e8fcf9f.e3096","order":2,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"","x":536.017333984375,"y":84.01041412353516,"wires":[["edaa1dae.06373"]]},{"id":"edaa1dae.06373","type":"function","z":"12c49f15.e46c51","name":"save","func":"var options = flow.get(\"TCP_Connection\") || {};\n\noptions.name = msg.payload;\n\nflow.set(\"TCP_Connection\", options);","outputs":"0","noerr":0,"x":699.5728759765625,"y":84.23263549804688,"wires":[]},{"id":"3f64d325.a9357c","type":"change","z":"12c49f15.e46c51","name":"set","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":384.5729064941406,"y":84.23263549804688,"wires":[["37abf753.f84de8"]]},{"id":"b510a529.8c8cc8","type":"ui_text_input","z":"12c49f15.e46c51","name":"","label":"Name","group":"2daa58ed.8d8da8","order":2,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"","x":1313.4617919921875,"y":67.01041412353516,"wires":[["dd5a974c.72d9f8"]]},{"id":"dd5a974c.72d9f8","type":"function","z":"12c49f15.e46c51","name":"save","func":"var options = flow.get(\"SERIAL_Connection\") || {};\n\noptions.name = msg.payload;\n\nflow.set(\"SERIAL_Connection\", options);","outputs":"0","noerr":0,"x":1481.017333984375,"y":67.23263549804688,"wires":[]},{"id":"65e39185.5970c","type":"change","z":"12c49f15.e46c51","name":"set","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1166.0173645019531,"y":67.23263549804688,"wires":[["b510a529.8c8cc8"]]},{"id":"93c341e2.870eb","type":"ui_dropdown","z":"12c49f15.e46c51","name":"configurations","label":"Configurations","place":"Choose a conf...","group":"2daa58ed.8d8da8","order":1,"width":0,"height":0,"passthru":true,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","x":1117.4460067749023,"y":464.5977191925049,"wires":[["9450c567.62ef58"]]},{"id":"25ebe5e8.65cc3a","type":"inject","z":"12c49f15.e46c51","name":"","topic":"init","payload":"configs_SERIAL","payloadType":"flow","repeat":"","crontab":"","once":true,"x":744.017391204834,"y":437.4548463821411,"wires":[["c474e32d.1e01a"]]},{"id":"c474e32d.1e01a","type":"function","z":"12c49f15.e46c51","name":"options","func":"var options = [];\n\n(msg.payload || []).forEach(function(opt) {\n    var tmp = {};\n    tmp[opt.name] = opt;\n    options.push(tmp);\n});\n\nmsg.options = options;\n\n\nreturn msg;","outputs":1,"noerr":0,"x":933.0174179077148,"y":416.4548511505127,"wires":[["93c341e2.870eb"]]},{"id":"b64a6bec.83dec8","type":"function","z":"12c49f15.e46c51","name":"connect","func":"var options = msg.payload;\nvar error = {topic: \"SERIAL Connect\"};\nvar configs = flow.get('configs_SERIAL') || [];\n\noptions.connectorType = \"SERIAL\";\n\nif(!options.name || options.name === \"\"){\n    options.name = \"No name\";\n}\n\nif(!options.serialPort){\n    error.payload = \"Serial port not valid\";\n    node.error(\"Error\",error);\n    return;\n}\n\nif(!options.serialBaudrate){\n    error.payload = \"Select a Baud Rate\";\n    node.error(\"Error\",error);\n    return;\n}\n\nif(!options.unitId){\n    error.payload = \"Unit ID not Valid\";\n    node.error(\"Error\",error);\n    return;\n}\n\nvar index = configs.findIndex(function(conf) {\n    return conf.name == options.name;\n});\n\nif(index < 0)\n    configs.push(options);\nelse\n    configs[index] = options;\n    \nflow.set('configs_SERIAL', configs);\n\nnode.send([msg, {payload:configs, topic:\"init\"}]);","outputs":"2","noerr":0,"x":290.0173645019531,"y":409.8992919921875,"wires":[["c4e491c3.c92d8","d062d084.d8a6"],["c474e32d.1e01a"]]},{"id":"ae9de9b2.e577c8","type":"change","z":"12c49f15.e46c51","name":"","rules":[{"t":"set","p":"TCP_Connection","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1458.0652198791504,"y":334.9152021408081,"wires":[["ff4cc150.15dfa"]]},{"id":"6981e2f4.d2d3bc","type":"change","z":"12c49f15.e46c51","name":"","rules":[{"t":"set","p":"SERIAL_Connection","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1467.9221725463867,"y":464.4865942001343,"wires":[["cb62e5cf.5edb48"]]},{"id":"cbc8f1bc.016df","type":"link in","z":"12c49f15.e46c51","name":"set_tcp","links":["ff4cc150.15dfa","4f86ecb.7b49914"],"x":220.46198081970215,"y":84.89933586120605,"wires":[["3f64d325.a9357c","37c4b846.c34188","6ca02e22.ac401","bf1ec8e4.4f37a8"]]},{"id":"ff4cc150.15dfa","type":"link out","z":"12c49f15.e46c51","name":"set_tcp","links":["cbc8f1bc.016df"],"x":1620.60462474823,"y":335.47075176239014,"wires":[]},{"id":"d5dde0bc.ef8e3","type":"link in","z":"12c49f15.e46c51","name":"set_serial","links":["cb62e5cf.5edb48","d062d084.d8a6"],"x":992.4618768692017,"y":66.89929580688477,"wires":[["65e39185.5970c","670c6760.b8df78","b1f9e1ab.b81bd","e8db20b1.edd77","834156a0.940508"]]},{"id":"cb62e5cf.5edb48","type":"link out","z":"12c49f15.e46c51","name":"set_serial","links":["d5dde0bc.ef8e3"],"x":1630.175989151001,"y":464.0420923233032,"wires":[]},{"id":"abb0739b.4b615","type":"inject","z":"12c49f15.e46c51","name":"init","topic":"","payload":"{\"options\":[]}","payloadType":"json","repeat":"","crontab":"","once":false,"x":728.9999771118164,"y":505.57143783569336,"wires":[["d626c5a4.aee378","d93628a4.45c778","93c341e2.870eb"]]},{"id":"d626c5a4.aee378","type":"function","z":"12c49f15.e46c51","name":"init confs","func":"flow.set(\"configs_TCP\", null);\nflow.set(\"configs_SERIAL\", null);","outputs":"0","noerr":0,"x":886.7143058776855,"y":506.00001430511475,"wires":[]},{"id":"36533ff8.402c","type":"switch","z":"12c49f15.e46c51","name":"check","property":"topic","propertyType":"msg","rules":[{"t":"neq","v":"init","vt":"str"}],"checkall":"true","outputs":1,"x":1277.8570747375488,"y":335.14288997650146,"wires":[["ae9de9b2.e577c8"]]},{"id":"9450c567.62ef58","type":"switch","z":"12c49f15.e46c51","name":"check","property":"topic","propertyType":"msg","rules":[{"t":"neq","v":"init","vt":"str"}],"checkall":"true","outputs":1,"x":1277.0000076293945,"y":464.42857837677,"wires":[["6981e2f4.d2d3bc"]]},{"id":"5229dc68.bfff44","type":"catch","z":"12c49f15.e46c51","name":"","scope":["b64a6bec.83dec8","ccf807ba.eaffc8"],"x":160.00000762939453,"y":496.42858505249023,"wires":[["f7e333d8.caafa"]]},{"id":"f7e333d8.caafa","type":"ui_toast","z":"12c49f15.e46c51","position":"top right","displayTime":"3","highlight":"","outputs":0,"ok":"OK","cancel":"","topic":"Error","name":"error","x":320,"y":496.4285774230957,"wires":[]},{"id":"4f86ecb.7b49914","type":"link out","z":"12c49f15.e46c51","name":"init_tcp","links":["cbc8f1bc.016df"],"x":431.42858600616455,"y":330.2857265472412,"wires":[]},{"id":"d062d084.d8a6","type":"link out","z":"12c49f15.e46c51","name":"init_serial","links":["d5dde0bc.ef8e3"],"x":426.42856788635254,"y":453.1428499221802,"wires":[]},{"id":"3fc345d2.a7405a","type":"ui_text_input","z":"12c49f15.e46c51","name":"","label":"Address","group":"e7f8efcf.c9e3b","order":1,"width":"3","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":438.2857360839844,"y":955.4285888671875,"wires":[["31d34423.322c1c"]]},{"id":"6de8e401.51c2fc","type":"ui_text_input","z":"12c49f15.e46c51","name":"","label":"Address","group":"77708401.e47e9c","order":1,"width":"2","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":1124.2857666015625,"y":977.7142944335938,"wires":[["c4b9ff8e.28728"]]},{"id":"ee944d7f.99dbd","type":"ui_text_input","z":"12c49f15.e46c51","name":"","label":"Length","group":"e7f8efcf.c9e3b","order":2,"width":"3","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":427.1428527832031,"y":1001.1428833007812,"wires":[["d058d019.d7af7"]]},{"id":"70ff7be1.8ed044","type":"inject","z":"12c49f15.e46c51","name":"","topic":"init","payload":"{\"payload\":null}","payloadType":"json","repeat":"1","crontab":"","once":false,"x":838.5714492797852,"y":307.1428499221802,"wires":[["d93628a4.45c778","93c341e2.870eb"]]},{"id":"1de73100.a7a9af","type":"toFloat","z":"12c49f15.e46c51","name":"","toFixed":"2","x":1159.6429443359375,"y":760.8571166992188,"wires":[["48e673c5.d0dccc"]]},{"id":"df2fbfd1.0fc09","type":"change","z":"12c49f15.e46c51","name":"data","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.data","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":602,"y":676,"wires":[["2497c0e5.9016f"]]},{"id":"e7f8efcf.c9e3b","type":"ui_group","z":"","name":"Read","tab":"5ffb059b.b4215c","order":3,"disp":true,"width":"6"},{"id":"f0111c9.90187e","type":"modbus-client","z":"","name":"MODSCAN","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB0","serialType":"RTU-BUFFERD","serialBaudrate":"57600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":1,"commandDelay":1,"clientTimeout":1000,"reconnectTimeout":2000},{"id":"85f4a53f.ba00c8","type":"ui_group","z":"","name":"Output","tab":"5ffb059b.b4215c","order":5,"disp":true,"width":"24"},{"id":"77708401.e47e9c","type":"ui_group","z":"","name":"Write","tab":"5ffb059b.b4215c","order":4,"disp":true,"width":"6"},{"id":"1e8fcf9f.e3096","type":"ui_group","z":"","name":"TCP","tab":"5ffb059b.b4215c","order":1,"disp":true,"width":"6"},{"id":"2daa58ed.8d8da8","type":"ui_group","z":"","name":"Serial","tab":"5ffb059b.b4215c","order":2,"disp":true,"width":"6"},{"id":"5ffb059b.b4215c","type":"ui_tab","z":"","name":"Modscan","icon":"dashboard","order":2}]
robertsLando

Flow Info

created 1 year, 1 month ago
updated 8 months ago

Node Types

Core
  • catch (x1)
  • change (x12)
  • comment (x4)
  • function (x32)
  • inject (x19)
  • switch (x5)
Other

Tags

  • modscan
  • modbus
  • node-red-contrib-modbus
  • testing
  • debug
  • node-red-ui
  • ui
  • robertsLando
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option