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)

Modscan

[{"id":"3494f41c.8eac2c","type":"tab","label":"MODSCAN","disabled":false,"info":""},{"id":"f539b45c.0ab8b8","type":"inject","z":"3494f41c.8eac2c","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"x":127.1429443359375,"y":683.8571310043335,"wires":[["5194c28b.8c6edc"]]},{"id":"5194c28b.8c6edc","type":"function","z":"3494f41c.8eac2c","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;\nreturn msg;","outputs":1,"noerr":0,"x":309.1429443359375,"y":683.8571310043335,"wires":[["e0fb5046.fbb"]]},{"id":"8decc26d.6c621","type":"ui_button","z":"3494f41c.8eac2c","name":"","group":"2cd75637.47f5ca","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":[["65aa9c3d.96add4"]]},{"id":"65aa9c3d.96add4","type":"function","z":"3494f41c.8eac2c","name":"enable","func":"flow.set(\"enabled\", true);\nflow.set(\"count\", 0);","outputs":"0","noerr":0,"x":598.1429443359375,"y":861.8571310043335,"wires":[]},{"id":"8c402773.430c38","type":"ui_button","z":"3494f41c.8eac2c","name":"","group":"2cd75637.47f5ca","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":[["bc37728a.cbc5e"]]},{"id":"bc37728a.cbc5e","type":"function","z":"3494f41c.8eac2c","name":"disable","func":"flow.set(\"enabled\", false);","outputs":"0","noerr":0,"x":605.6429443359375,"y":912.8571310043335,"wires":[]},{"id":"c9f5a8bd.d6eb88","type":"function","z":"3494f41c.8eac2c","name":"save","func":"flow.set(\"address\", msg.payload);","outputs":"0","noerr":0,"x":595.1429443359375,"y":955.8571310043335,"wires":[]},{"id":"4adc9c85.e6af34","type":"function","z":"3494f41c.8eac2c","name":"save","func":"flow.set(\"length\", msg.payload);","outputs":"0","noerr":0,"x":596.1429443359375,"y":1000.8571310043335,"wires":[]},{"id":"dd0312b.71aa0f","type":"function","z":"3494f41c.8eac2c","name":"save","func":"flow.set(\"FC\", msg.payload);","outputs":"0","noerr":0,"x":593.1429443359375,"y":1043.8571310043335,"wires":[]},{"id":"e0fb5046.fbb","type":"modbus-flex-getter","z":"3494f41c.8eac2c","name":"read","showStatusActivities":false,"showErrors":false,"server":"c3746bcd.b56d18","x":460.1429443359375,"y":682.8571310043335,"wires":[["7292a22.5fbf65c"],[]]},{"id":"367888b6.d2ff18","type":"ui_template","z":"3494f41c.8eac2c","group":"1ec37518.e8af8b","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":1143.14306640625,"y":703.8571310043335,"wires":[[]]},{"id":"f4fd4345.8d8bc","type":"inject","z":"3494f41c.8eac2c","name":"init","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":160.1429443359375,"y":862.8571310043335,"wires":[["231a7ec0.d0f332"]]},{"id":"231a7ec0.d0f332","type":"function","z":"3494f41c.8eac2c","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":"3709f3de.86d1cc","type":"inject","z":"3494f41c.8eac2c","name":"init","topic":"","payload":"count","payloadType":"flow","repeat":"1","crontab":"","once":false,"x":482.1429443359375,"y":623.8571310043335,"wires":[["69df4e73.18b4e"]]},{"id":"69df4e73.18b4e","type":"ui_text","z":"3494f41c.8eac2c","group":"1ec37518.e8af8b","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":"85a905a7.179e18","type":"status","z":"3494f41c.8eac2c","name":"","scope":["e0fb5046.fbb"],"x":113.6429443359375,"y":623.8571310043335,"wires":[["b0893ab5.222c38"]]},{"id":"b0893ab5.222c38","type":"ui_text","z":"3494f41c.8eac2c","group":"1ec37518.e8af8b","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":"ea3e3781.f3d438","type":"function","z":"3494f41c.8eac2c","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":732.1429977416992,"y":708.8571443557739,"wires":[["50c95d6.3758da4"]]},{"id":"7292a22.5fbf65c","type":"switch","z":"3494f41c.8eac2c","name":"","property":"conversion","propertyType":"flow","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","outputs":2,"x":592.6429443359375,"y":676.8571310043335,"wires":[["9ae4f832.284d78"],["ea3e3781.f3d438"]]},{"id":"8318cecd.86d64","type":"ui_switch","z":"3494f41c.8eac2c","name":"","label":"32 bit","group":"2cd75637.47f5ca","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":[["ec3160e2.d18a6"]]},{"id":"ec3160e2.d18a6","type":"function","z":"3494f41c.8eac2c","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":"5e770816.dc3e88","type":"ui_dropdown","z":"3494f41c.8eac2c","name":"","label":"FC","place":"FC","group":"2cd75637.47f5ca","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":[["dd0312b.71aa0f"]]},{"id":"149ff4b4.c76b2b","type":"inject","z":"3494f41c.8eac2c","name":"","topic":"","payload":"address","payloadType":"flow","repeat":"","crontab":"","once":true,"x":214.1429443359375,"y":955.8571310043335,"wires":[["70c36c79.bfb6d4"]]},{"id":"73530c26.75bff4","type":"inject","z":"3494f41c.8eac2c","name":"","topic":"","payload":"length","payloadType":"flow","repeat":"","crontab":"","once":true,"x":213.1429443359375,"y":1000.8571310043335,"wires":[["d745b428.764c38"]]},{"id":"a8dc672c.c8d168","type":"inject","z":"3494f41c.8eac2c","name":"","topic":"","payload":"FC","payloadType":"flow","repeat":"","crontab":"","once":true,"x":202.1429443359375,"y":1043.8571310043335,"wires":[["5e770816.dc3e88"]]},{"id":"b06390ef.dae56","type":"inject","z":"3494f41c.8eac2c","name":"","topic":"","payload":"conversion","payloadType":"flow","repeat":"0.1","crontab":"","once":true,"x":230.1429443359375,"y":1083.8571310043335,"wires":[["8318cecd.86d64"]]},{"id":"6c75f9c2.b38398","type":"modbus-flex-write","z":"3494f41c.8eac2c","name":"write","showStatusActivities":false,"showErrors":false,"server":"c3746bcd.b56d18","x":1173.1429443359375,"y":862.8571310043335,"wires":[[],[]]},{"id":"ec7f4a60.d23ee8","type":"ui_button","z":"3494f41c.8eac2c","name":"write","group":"6032c07a.692b5","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":[["43ef0976.f81c48"]]},{"id":"43ef0976.f81c48","type":"function","z":"3494f41c.8eac2c","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":[["6c75f9c2.b38398"]]},{"id":"3e449b2b.31ccb4","type":"function","z":"3494f41c.8eac2c","name":"save","func":"flow.set(\"address_write\", msg.payload);","outputs":"0","noerr":0,"x":1287.6429443359375,"y":977.8571310043335,"wires":[]},{"id":"87bf94ee.a12c48","type":"function","z":"3494f41c.8eac2c","name":"save","func":"flow.set(\"FC_WRITE\", msg.payload);","outputs":"0","noerr":0,"x":1288.6429443359375,"y":1018.8571310043335,"wires":[]},{"id":"28ff063f.85bc6a","type":"inject","z":"3494f41c.8eac2c","name":"init","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":883.6429443359375,"y":923.8571310043335,"wires":[["487db348.f5b74c"]]},{"id":"487db348.f5b74c","type":"function","z":"3494f41c.8eac2c","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":"73aae4d.d86901c","type":"ui_switch","z":"3494f41c.8eac2c","name":"","label":"Hex to Int","group":"6032c07a.692b5","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":[["74120c6f.3e8d94"]]},{"id":"74120c6f.3e8d94","type":"function","z":"3494f41c.8eac2c","name":"save","func":"flow.set(\"conversion_write\", msg.payload);","outputs":"0","noerr":0,"x":1289.6429443359375,"y":1058.8571310043335,"wires":[]},{"id":"b7a1c744.bc8288","type":"ui_dropdown","z":"3494f41c.8eac2c","name":"","label":"FC","place":"FC","group":"6032c07a.692b5","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":[["87bf94ee.a12c48"]]},{"id":"62b53cbb.1d1634","type":"inject","z":"3494f41c.8eac2c","name":"","topic":"","payload":"address_write","payloadType":"flow","repeat":"","crontab":"","once":true,"x":924.6429443359375,"y":977.8571310043335,"wires":[["23a76f17.05ec6"]]},{"id":"eaa5857b.f33fb8","type":"inject","z":"3494f41c.8eac2c","name":"","topic":"","payload":"FC_WRITE","payloadType":"flow","repeat":"","crontab":"","once":true,"x":915.6429443359375,"y":1018.8571310043335,"wires":[["b7a1c744.bc8288"]]},{"id":"4bd6727f.97e6ac","type":"inject","z":"3494f41c.8eac2c","name":"","topic":"","payload":"conversion_write","payloadType":"flow","repeat":"0.1","crontab":"","once":true,"x":933.6429443359375,"y":1058.8571310043335,"wires":[["73aae4d.d86901c"]]},{"id":"f74201ed.bb715","type":"ui_text_input","z":"3494f41c.8eac2c","name":"","label":"Value","group":"6032c07a.692b5","order":2,"width":"3","height":"1","passthru":false,"mode":"text","delay":"100","topic":"","x":1122.1429443359375,"y":1098.8571310043335,"wires":[["a3337067.0b29"]]},{"id":"a3337067.0b29","type":"function","z":"3494f41c.8eac2c","name":"save","func":"flow.set(\"value\", msg.payload);","outputs":"0","noerr":0,"x":1288.6429443359375,"y":1098.8571310043335,"wires":[]},{"id":"da19884c.7886c8","type":"comment","z":"3494f41c.8eac2c","name":"READ","info":"","x":74.6429443359375,"y":809.8571310043335,"wires":[]},{"id":"1919804b.54ae6","type":"comment","z":"3494f41c.8eac2c","name":"WRITE","info":"","x":804.1429443359375,"y":810.8571310043335,"wires":[]},{"id":"6602b7ce.8e4d78","type":"comment","z":"3494f41c.8eac2c","name":"OUTPUT","info":"","x":86.1429443359375,"y":570.8571310043335,"wires":[]},{"id":"9356ed87.57","type":"ui_switch","z":"3494f41c.8eac2c","name":"","label":"Hex Values","group":"2cd75637.47f5ca","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":[["62bf1a51.ae72b4"]]},{"id":"62bf1a51.ae72b4","type":"function","z":"3494f41c.8eac2c","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":"65ceea55.518544","type":"inject","z":"3494f41c.8eac2c","name":"","topic":"","payload":"hex","payloadType":"flow","repeat":"0.1","crontab":"","once":true,"x":200.4085693359375,"y":1130.6071310043335,"wires":[["9356ed87.57"]]},{"id":"9ae4f832.284d78","type":"switch","z":"3494f41c.8eac2c","name":"","property":"hex","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","outputs":2,"x":725.9086074829102,"y":670.6071310043335,"wires":[["e0bd891f.c26a58"],["367888b6.d2ff18"]]},{"id":"e0bd891f.c26a58","type":"function","z":"3494f41c.8eac2c","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":881.9085693359375,"y":663.6071310043335,"wires":[["367888b6.d2ff18"]]},{"id":"249675cd.2cdaca","type":"inject","z":"3494f41c.8eac2c","name":"","topic":"","payload":"conversion_float","payloadType":"flow","repeat":"0.1","crontab":"","once":true,"x":221.1429443359375,"y":1176.8571310043335,"wires":[["b59f10fe.40b89"]]},{"id":"b59f10fe.40b89","type":"ui_switch","z":"3494f41c.8eac2c","name":"","label":"Float","group":"2cd75637.47f5ca","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":[["cbe86282.df885"]]},{"id":"cbe86282.df885","type":"function","z":"3494f41c.8eac2c","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":"50c95d6.3758da4","type":"switch","z":"3494f41c.8eac2c","name":"","property":"conversion_float","propertyType":"flow","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","outputs":2,"x":878.1429443359375,"y":738.8571310043335,"wires":[["367888b6.d2ff18"],["8bf38727.8a09f8"]]},{"id":"8bf38727.8a09f8","type":"toFloat","z":"3494f41c.8eac2c","name":"","toFixed":"2","x":1006.6429443359375,"y":761.8571310043335,"wires":[["367888b6.d2ff18"]]},{"id":"8e2411f5.223d5","type":"comment","z":"3494f41c.8eac2c","name":"CONNECTION","info":"","x":118.46179962158203,"y":41.56597328186035,"wires":[]},{"id":"4f97c3a7.cbfe2c","type":"ui_text_input","z":"3494f41c.8eac2c","name":"","label":"Address","group":"4da1b46c.a5f1ac","order":3,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"","x":546.4617919921875,"y":131.01041412353516,"wires":[["b0ff80d5.9d224"]]},{"id":"4cbbf31e.30ca9c","type":"modbus-flex-connector","z":"3494f41c.8eac2c","name":"connection","maxReconnectsPerMinute":4,"emptyQueue":false,"showStatusActivities":false,"showErrors":false,"server":"c3746bcd.b56d18","x":450.46185302734375,"y":385.01045298576355,"wires":[]},{"id":"53679090.4e344","type":"ui_text_input","z":"3494f41c.8eac2c","name":"","label":"Port","group":"4da1b46c.a5f1ac","order":4,"width":"3","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":536.4791259765625,"y":175.01040649414062,"wires":[["fdfc6240.801c2"]]},{"id":"b0ff80d5.9d224","type":"function","z":"3494f41c.8eac2c","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":"fdfc6240.801c2","type":"function","z":"3494f41c.8eac2c","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":"6accdfbd.57c73","type":"ui_text_input","z":"3494f41c.8eac2c","name":"","label":"Unit ID","group":"4da1b46c.a5f1ac","order":5,"width":"3","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":535.4791412353516,"y":225.23263549804688,"wires":[["fe93df23.c304e"]]},{"id":"fe93df23.c304e","type":"function","z":"3494f41c.8eac2c","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":"c56a1fa5.78e3b","type":"inject","z":"3494f41c.8eac2c","name":"","topic":"","payload":"TCP_Connection","payloadType":"flow","repeat":"","crontab":"","once":true,"x":136,"y":147.23263549804688,"wires":[["66e838c9.790768","6ec2f76d.4265c8","8cbf36f9.a5efa8","a7648ea2.91f87"]]},{"id":"66e838c9.790768","type":"change","z":"3494f41c.8eac2c","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":[["4f97c3a7.cbfe2c"]]},{"id":"6ec2f76d.4265c8","type":"change","z":"3494f41c.8eac2c","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":[["53679090.4e344"]]},{"id":"8cbf36f9.a5efa8","type":"change","z":"3494f41c.8eac2c","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":[["6accdfbd.57c73"]]},{"id":"b7a17712.96fbc8","type":"ui_button","z":"3494f41c.8eac2c","name":"connectTCP","group":"4da1b46c.a5f1ac","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":[["abca0103.aca78"]]},{"id":"abca0103.aca78","type":"function","z":"3494f41c.8eac2c","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":[["4cbbf31e.30ca9c","ad1dc410.d4bb28"],["ab4515b6.d70f48"]]},{"id":"2ecb7e8a.582102","type":"ui_text_input","z":"3494f41c.8eac2c","name":"custom port","label":"or choose a custom Port","group":"86934b0f.fab418","order":4,"width":"6","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":1330.03466796875,"y":157.23262786865234,"wires":[["e6cc1a82.91c2b8"]]},{"id":"fa51cf50.a38a8","type":"ui_text_input","z":"3494f41c.8eac2c","name":"","label":"Unit ID","group":"86934b0f.fab418","order":5,"width":"3","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":1308.034683227539,"y":200.4548568725586,"wires":[["106effa1.1db5f"]]},{"id":"9a9eae5a.2a8e5","type":"inject","z":"3494f41c.8eac2c","name":"","topic":"","payload":"SERIAL_Connection","payloadType":"flow","repeat":"","crontab":"","once":true,"x":926.5555419921875,"y":152.4548568725586,"wires":[["88473c35.bae1a","30bd3494.4571cc","6011dae9.a995c4","f8e6e69c.42d3b8","b4575fe7.dc67b"]]},{"id":"88473c35.bae1a","type":"change","z":"3494f41c.8eac2c","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":[["2ecb7e8a.582102"]]},{"id":"30bd3494.4571cc","type":"change","z":"3494f41c.8eac2c","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":[["fa51cf50.a38a8"]]},{"id":"f9b43551.1cae18","type":"function","z":"3494f41c.8eac2c","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":"6011dae9.a995c4","type":"change","z":"3494f41c.8eac2c","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":[["88b1423a.4042a"]]},{"id":"88b1423a.4042a","type":"ui_dropdown","z":"3494f41c.8eac2c","name":"port","label":"Port","place":"Choose a serial port","group":"86934b0f.fab418","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":[["f9b43551.1cae18"]]},{"id":"e6cc1a82.91c2b8","type":"function","z":"3494f41c.8eac2c","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":"106effa1.1db5f","type":"function","z":"3494f41c.8eac2c","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":"f8e6e69c.42d3b8","type":"change","z":"3494f41c.8eac2c","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":[["e263ce14.512eb"]]},{"id":"9909949a.2f9d38","type":"function","z":"3494f41c.8eac2c","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":"d3ed8478.2e1848","type":"ui_button","z":"3494f41c.8eac2c","name":"connectSERIAL","group":"86934b0f.fab418","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":[["baab85c4.bec788"]]},{"id":"e263ce14.512eb","type":"ui_dropdown","z":"3494f41c.8eac2c","name":"BaudRate","label":"Baud Rate","place":"Select a Boud Rate","group":"86934b0f.fab418","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":[["9909949a.2f9d38"]]},{"id":"88d9fec.dda94","type":"ui_dropdown","z":"3494f41c.8eac2c","name":"configurations","label":"Configurations","place":"Choose a conf...","group":"4da1b46c.a5f1ac","order":1,"width":0,"height":0,"passthru":true,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","x":1119.731704711914,"y":334.5819034576416,"wires":[["2da49e26.b25962"]]},{"id":"d8b99e67.137c","type":"inject","z":"3494f41c.8eac2c","name":"","topic":"init","payload":"configs_TCP","payloadType":"flow","repeat":"","crontab":"","once":true,"x":749.0174331665039,"y":385.01042461395264,"wires":[["ab4515b6.d70f48"]]},{"id":"ab4515b6.d70f48","type":"function","z":"3494f41c.8eac2c","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":[["88d9fec.dda94"]]},{"id":"98807f41.46091","type":"ui_text_input","z":"3494f41c.8eac2c","name":"","label":"Name","group":"4da1b46c.a5f1ac","order":2,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"","x":536.017333984375,"y":84.01041412353516,"wires":[["839f6689.e91028"]]},{"id":"839f6689.e91028","type":"function","z":"3494f41c.8eac2c","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":"a7648ea2.91f87","type":"change","z":"3494f41c.8eac2c","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":[["98807f41.46091"]]},{"id":"271f9404.f1d3fc","type":"ui_text_input","z":"3494f41c.8eac2c","name":"","label":"Name","group":"86934b0f.fab418","order":2,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"","x":1313.4617919921875,"y":67.01041412353516,"wires":[["c77ffe8d.e285"]]},{"id":"c77ffe8d.e285","type":"function","z":"3494f41c.8eac2c","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":"b4575fe7.dc67b","type":"change","z":"3494f41c.8eac2c","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":[["271f9404.f1d3fc"]]},{"id":"9835be5e.daa64","type":"ui_dropdown","z":"3494f41c.8eac2c","name":"configurations","label":"Configurations","place":"Choose a conf...","group":"86934b0f.fab418","order":1,"width":0,"height":0,"passthru":true,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"","x":1117.4460067749023,"y":464.5977191925049,"wires":[["9edbfd36.fa2ff"]]},{"id":"d3ded498.eb0e78","type":"inject","z":"3494f41c.8eac2c","name":"","topic":"init","payload":"configs_SERIAL","payloadType":"flow","repeat":"","crontab":"","once":true,"x":744.017391204834,"y":437.4548463821411,"wires":[["2efcb5a6.248e7a"]]},{"id":"2efcb5a6.248e7a","type":"function","z":"3494f41c.8eac2c","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":[["9835be5e.daa64"]]},{"id":"baab85c4.bec788","type":"function","z":"3494f41c.8eac2c","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":[["4cbbf31e.30ca9c","e6a693d9.8ae3d"],["2efcb5a6.248e7a"]]},{"id":"c6aa8f77.c175","type":"change","z":"3494f41c.8eac2c","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":[["2de79a12.79adf6"]]},{"id":"2ba991c1.996c6e","type":"change","z":"3494f41c.8eac2c","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":[["4224063d.625198"]]},{"id":"6072cf59.05d86","type":"link in","z":"3494f41c.8eac2c","name":"set_tcp","links":["2de79a12.79adf6","ad1dc410.d4bb28"],"x":220.46198081970215,"y":84.89933586120605,"wires":[["a7648ea2.91f87","66e838c9.790768","6ec2f76d.4265c8","8cbf36f9.a5efa8"]]},{"id":"2de79a12.79adf6","type":"link out","z":"3494f41c.8eac2c","name":"set_tcp","links":["6072cf59.05d86"],"x":1620.60462474823,"y":335.47075176239014,"wires":[]},{"id":"81bb1c78.02c1","type":"link in","z":"3494f41c.8eac2c","name":"set_serial","links":["4224063d.625198","e6a693d9.8ae3d"],"x":992.4618768692017,"y":66.89929580688477,"wires":[["b4575fe7.dc67b","6011dae9.a995c4","88473c35.bae1a","30bd3494.4571cc","f8e6e69c.42d3b8"]]},{"id":"4224063d.625198","type":"link out","z":"3494f41c.8eac2c","name":"set_serial","links":["81bb1c78.02c1"],"x":1630.175989151001,"y":464.0420923233032,"wires":[]},{"id":"1eecc659.c7645a","type":"inject","z":"3494f41c.8eac2c","name":"init","topic":"","payload":"{\"options\":[]}","payloadType":"json","repeat":"","crontab":"","once":false,"x":728.9999771118164,"y":505.57143783569336,"wires":[["7a9a0243.28cafc","88d9fec.dda94","9835be5e.daa64"]]},{"id":"7a9a0243.28cafc","type":"function","z":"3494f41c.8eac2c","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":"2da49e26.b25962","type":"switch","z":"3494f41c.8eac2c","name":"check","property":"topic","propertyType":"msg","rules":[{"t":"neq","v":"init","vt":"str"}],"checkall":"true","outputs":1,"x":1277.8570747375488,"y":335.14288997650146,"wires":[["c6aa8f77.c175"]]},{"id":"9edbfd36.fa2ff","type":"switch","z":"3494f41c.8eac2c","name":"check","property":"topic","propertyType":"msg","rules":[{"t":"neq","v":"init","vt":"str"}],"checkall":"true","outputs":1,"x":1277.0000076293945,"y":464.42857837677,"wires":[["2ba991c1.996c6e"]]},{"id":"87afc149.b6bf1","type":"catch","z":"3494f41c.8eac2c","name":"","scope":["baab85c4.bec788","abca0103.aca78"],"x":160.00000762939453,"y":496.42858505249023,"wires":[["bb8cb022.4ffaa"]]},{"id":"bb8cb022.4ffaa","type":"ui_toast","z":"3494f41c.8eac2c","position":"top right","displayTime":"3","highlight":"","outputs":0,"ok":"OK","cancel":"","topic":"Error","name":"error","x":320,"y":496.4285774230957,"wires":[]},{"id":"ad1dc410.d4bb28","type":"link out","z":"3494f41c.8eac2c","name":"init_tcp","links":["6072cf59.05d86"],"x":431.42858600616455,"y":330.2857265472412,"wires":[]},{"id":"e6a693d9.8ae3d","type":"link out","z":"3494f41c.8eac2c","name":"init_serial","links":["81bb1c78.02c1"],"x":426.42856788635254,"y":453.1428499221802,"wires":[]},{"id":"70c36c79.bfb6d4","type":"ui_text_input","z":"3494f41c.8eac2c","name":"","label":"Address","group":"2cd75637.47f5ca","order":1,"width":"3","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":438.2857360839844,"y":955.4285888671875,"wires":[["c9f5a8bd.d6eb88"]]},{"id":"23a76f17.05ec6","type":"ui_text_input","z":"3494f41c.8eac2c","name":"","label":"Address","group":"6032c07a.692b5","order":1,"width":"2","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":1124.2857666015625,"y":977.7142944335938,"wires":[["3e449b2b.31ccb4"]]},{"id":"d745b428.764c38","type":"ui_text_input","z":"3494f41c.8eac2c","name":"","label":"Length","group":"2cd75637.47f5ca","order":2,"width":"3","height":"1","passthru":true,"mode":"text","delay":300,"topic":"","x":427.1428527832031,"y":1001.1428833007812,"wires":[["4adc9c85.e6af34"]]},{"id":"1608c739.59f6d9","type":"inject","z":"3494f41c.8eac2c","name":"","topic":"init","payload":"{\"payload\":null}","payloadType":"json","repeat":"1","crontab":"","once":false,"x":838.5714492797852,"y":307.1428499221802,"wires":[["88d9fec.dda94","9835be5e.daa64"]]},{"id":"2cd75637.47f5ca","type":"ui_group","z":"","name":"Read","tab":"61bb378f.726c58","order":3,"disp":true,"width":"6"},{"id":"c3746bcd.b56d18","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":"1ec37518.e8af8b","type":"ui_group","z":"","name":"Output","tab":"61bb378f.726c58","order":5,"disp":true,"width":"24"},{"id":"6032c07a.692b5","type":"ui_group","z":"","name":"Write","tab":"61bb378f.726c58","order":4,"disp":true,"width":"6"},{"id":"4da1b46c.a5f1ac","type":"ui_group","z":"","name":"TCP","tab":"61bb378f.726c58","order":1,"disp":true,"width":"6"},{"id":"86934b0f.fab418","type":"ui_group","z":"","name":"Serial","tab":"61bb378f.726c58","order":2,"disp":true,"width":"6"},{"id":"61bb378f.726c58","type":"ui_tab","z":"","name":"Modscan","icon":"dashboard","order":2}]
robertsLando

Flow Info

created 5 months, 1 week ago
updated 2 weeks, 3 days ago

Node Types

Core
  • catch (x1)
  • change (x11)
  • 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