Simple Modscan like UI for Modbus testing

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

  • 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":"b288bfb0.d6e09","type":"tab","label":"MODSCAN"},{"id":"bfa3e323.9a57e","type":"inject","z":"b288bfb0.d6e09","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"x":120,"y":142,"wires":[["625cb4d3.bd871c"]]},{"id":"625cb4d3.bd871c","type":"function","z":"b288bfb0.d6e09","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(\"conversion\") ? 2*flow.get(\"length\") : flow.get(\"length\") };\n}else\n    msg = null;\nreturn msg;","outputs":1,"noerr":0,"x":302,"y":142,"wires":[["559a3a06.692ae4"]]},{"id":"bd54ea51.020358","type":"ui_button","z":"b288bfb0.d6e09","name":"","group":"9a7dbe19.5632c","order":7,"width":"3","height":"1","passthru":false,"label":"Start","color":"","bgcolor":"","icon":"","payload":"1","payloadType":"num","topic":"","x":422.5,"y":272,"wires":[["768b3bc6.41e844"]]},{"id":"768b3bc6.41e844","type":"function","z":"b288bfb0.d6e09","name":"enable","func":"flow.set(\"enabled\", true);\nflow.set(\"count\", 0);","outputs":"0","noerr":0,"x":591,"y":272,"wires":[]},{"id":"d67ce1bc.9aac7","type":"ui_button","z":"b288bfb0.d6e09","name":"","group":"9a7dbe19.5632c","order":8,"width":"3","height":"1","passthru":false,"label":"Stop","color":"","bgcolor":"","icon":"","payload":"1","payloadType":"num","topic":"","x":422,"y":323,"wires":[["22c944.30eff6bc"]]},{"id":"22c944.30eff6bc","type":"function","z":"b288bfb0.d6e09","name":"disable","func":"flow.set(\"enabled\", false);","outputs":"0","noerr":0,"x":598.5,"y":323,"wires":[]},{"id":"da9ca2b.cd52c6","type":"function","z":"b288bfb0.d6e09","name":"save","func":"flow.set(\"address\", msg.payload);","outputs":"0","noerr":0,"x":588,"y":366,"wires":[]},{"id":"55fa1b6d.815c74","type":"function","z":"b288bfb0.d6e09","name":"save","func":"flow.set(\"length\", msg.payload);","outputs":"0","noerr":0,"x":589,"y":411,"wires":[]},{"id":"651850c0.8bf51","type":"ui_numeric","z":"b288bfb0.d6e09","name":"","label":"Length","group":"9a7dbe19.5632c","order":2,"width":0,"height":0,"passthru":false,"topic":"","format":"{{value}}","min":0,"max":"300","step":1,"x":432,"y":411,"wires":[["55fa1b6d.815c74"]]},{"id":"33d65a57.d12826","type":"ui_numeric","z":"b288bfb0.d6e09","name":"","label":"Address","group":"9a7dbe19.5632c","order":3,"width":0,"height":0,"passthru":false,"topic":"","format":"{{value}}","min":0,"max":"10000","step":1,"x":429,"y":366,"wires":[["da9ca2b.cd52c6"]]},{"id":"aff88443.cca0a8","type":"function","z":"b288bfb0.d6e09","name":"save","func":"flow.set(\"FC\", msg.payload);","outputs":"0","noerr":0,"x":586,"y":454,"wires":[]},{"id":"559a3a06.692ae4","type":"modbus-flex-getter","z":"b288bfb0.d6e09","name":"read","showStatusActivities":false,"showErrors":false,"server":"ab1b6187.a368f","x":453,"y":141,"wires":[["8eddd859.d99958"],[]]},{"id":"af871a21.4a9c38","type":"ui_template","z":"b288bfb0.d6e09","group":"a695d6ef.309968","name":"","order":2,"width":"12","height":"9","format":"<div style=\"width:100%;\">\n    <div style=\"display:inline-block; width:25%;\" ng-repeat=\"x in msg.payload track by $index\">\n        {{$index + msg.input.payload.address}} : {{ x }}\n    </div>\n</div>","storeOutMessages":true,"fwdInMessages":true,"x":1136.0001220703125,"y":162,"wires":[[]]},{"id":"66cd8266.b68b0c","type":"inject","z":"b288bfb0.d6e09","name":"init","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":153,"y":277,"wires":[["4396e92e.e121f8"]]},{"id":"4396e92e.e121f8","type":"function","z":"b288bfb0.d6e09","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":282,"y":277,"wires":[]},{"id":"9c2f5f7f.a3c4","type":"inject","z":"b288bfb0.d6e09","name":"init","topic":"","payload":"count","payloadType":"flow","repeat":"1","crontab":"","once":false,"x":475,"y":82,"wires":[["cb0fe0df.e7e2e"]]},{"id":"cb0fe0df.e7e2e","type":"ui_text","z":"b288bfb0.d6e09","group":"a695d6ef.309968","order":1,"width":"5","height":"1","name":"read count","label":"Total read: ","format":"{{msg.payload}}","layout":"row-spread","x":630.5000305175781,"y":82.00000190734863,"wires":[]},{"id":"18f458.fade5ba8","type":"status","z":"b288bfb0.d6e09","name":"","scope":["559a3a06.692ae4"],"x":106.5,"y":82,"wires":[["843a1154.1d38e"]]},{"id":"843a1154.1d38e","type":"ui_text","z":"b288bfb0.d6e09","group":"a695d6ef.309968","order":1,"width":"5","height":"1","name":"Modbus status","label":"Status:","format":"{{msg.status.text}}","layout":"row-spread","x":287,"y":82,"wires":[]},{"id":"3966e96e.81dde6","type":"function","z":"b288bfb0.d6e09","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    var tmp1 = msg.payload[++i].toString(2);\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;\nmsg.input = {};\nmsg.input.payload = {};\nmsg.input.payload.address = flow.get(\"address\");\n\nreturn msg;","outputs":1,"noerr":0,"x":725.0000534057617,"y":167.00001335144043,"wires":[["faae72aa.2e993"]]},{"id":"8eddd859.d99958","type":"switch","z":"b288bfb0.d6e09","name":"","property":"conversion","propertyType":"flow","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","outputs":2,"x":585.5,"y":135,"wires":[["4feb0629.a62638"],["3966e96e.81dde6"]]},{"id":"fe3a1e66.51cd","type":"ui_switch","z":"b288bfb0.d6e09","name":"","label":"32 bit","group":"9a7dbe19.5632c","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":422.5,"y":494,"wires":[["a054359c.137bd8"]]},{"id":"a054359c.137bd8","type":"function","z":"b288bfb0.d6e09","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":585,"y":494,"wires":[]},{"id":"4fdf601c.0681b","type":"ui_dropdown","z":"b288bfb0.d6e09","name":"","label":"FC","place":"FC","group":"9a7dbe19.5632c","order":1,"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":422,"y":454,"wires":[["aff88443.cca0a8"]]},{"id":"20d5a6ce.3a9fda","type":"inject","z":"b288bfb0.d6e09","name":"","topic":"","payload":"address","payloadType":"flow","repeat":"","crontab":"","once":true,"x":207,"y":366,"wires":[["33d65a57.d12826"]]},{"id":"8f542566.beb1b8","type":"inject","z":"b288bfb0.d6e09","name":"","topic":"","payload":"length","payloadType":"flow","repeat":"","crontab":"","once":true,"x":206,"y":411,"wires":[["651850c0.8bf51"]]},{"id":"6f8051ee.8dc4b","type":"inject","z":"b288bfb0.d6e09","name":"","topic":"","payload":"FC","payloadType":"flow","repeat":"","crontab":"","once":true,"x":195,"y":454,"wires":[["4fdf601c.0681b"]]},{"id":"527d50d4.702e7","type":"inject","z":"b288bfb0.d6e09","name":"","topic":"","payload":"conversion","payloadType":"flow","repeat":"0.1","crontab":"","once":true,"x":223,"y":494,"wires":[["fe3a1e66.51cd"]]},{"id":"c0b5bbab.50eb98","type":"modbus-flex-write","z":"b288bfb0.d6e09","name":"write","showStatusActivities":false,"showErrors":false,"server":"ab1b6187.a368f","x":1166,"y":321,"wires":[["3441dbcd.47ca34"],[]]},{"id":"4243634e.1c48cc","type":"ui_button","z":"b288bfb0.d6e09","name":"write","group":"c704cb95.d22fd8","order":5,"width":"6","height":"1","passthru":false,"label":"WRITE","color":"","bgcolor":"","icon":"","payload":"true","payloadType":"bool","topic":"","x":861,"y":321,"wires":[["2c25a39f.dc28ac"]]},{"id":"2c25a39f.dc28ac","type":"function","z":"b288bfb0.d6e09","name":"enable","func":"var value = flow.get(\"value\");\n\nif(flow.get(\"conversion_write\"))\n    value = parseInt(value, 16);\nelse value = parseInt(value);\n\nif(flow.get(\"FC_WRITE\") == 5)\n    value = value ? true : false;\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":1011,"y":321,"wires":[["c0b5bbab.50eb98","b6167a92.509788"]]},{"id":"56330f68.6b133","type":"function","z":"b288bfb0.d6e09","name":"save","func":"flow.set(\"address_write\", msg.payload);","outputs":"0","noerr":0,"x":1280.5,"y":436,"wires":[]},{"id":"ddec06b2.5de198","type":"ui_numeric","z":"b288bfb0.d6e09","name":"","label":"Address","group":"c704cb95.d22fd8","order":2,"width":0,"height":0,"passthru":false,"topic":"","format":"{{value}}","min":0,"max":"10000","step":1,"x":1127.5,"y":436,"wires":[["56330f68.6b133"]]},{"id":"6888c5c6.58ac7c","type":"function","z":"b288bfb0.d6e09","name":"save","func":"flow.set(\"FC_WRITE\", msg.payload);","outputs":"0","noerr":0,"x":1281.5,"y":477,"wires":[]},{"id":"8cc43402.6dd3b8","type":"inject","z":"b288bfb0.d6e09","name":"init","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":876.5,"y":382,"wires":[["5b24bbb7.88f7c4"]]},{"id":"5b24bbb7.88f7c4","type":"function","z":"b288bfb0.d6e09","name":"init","func":"flow.set(\"FC_WRITE\", 6);\nflow.set(\"address_write\", 1);\nflow.set(\"conversion_write\", 0);","outputs":"0","noerr":0,"x":1005.5,"y":382,"wires":[]},{"id":"32c05ccb.b0cde4","type":"ui_switch","z":"b288bfb0.d6e09","name":"","label":"Hex to Int","group":"c704cb95.d22fd8","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":1126,"y":517,"wires":[["f8ac3fc5.65194"]]},{"id":"f8ac3fc5.65194","type":"function","z":"b288bfb0.d6e09","name":"save","func":"flow.set(\"conversion_write\", msg.payload);","outputs":"0","noerr":0,"x":1282.5,"y":517,"wires":[]},{"id":"89b1be79.58eb4","type":"ui_dropdown","z":"b288bfb0.d6e09","name":"","label":"FC","place":"FC","group":"c704cb95.d22fd8","order":1,"width":0,"height":0,"passthru":false,"options":[{"label":"Force Single Coil FC 5","value":5,"type":"num"},{"label":"Force Single Register FC 6","value":6,"type":"num"}],"payload":"","topic":"","x":1117.5,"y":477,"wires":[["6888c5c6.58ac7c"]]},{"id":"9b33bb90.50afa8","type":"inject","z":"b288bfb0.d6e09","name":"","topic":"","payload":"address_write","payloadType":"flow","repeat":"","crontab":"","once":true,"x":917.5,"y":436,"wires":[["ddec06b2.5de198"]]},{"id":"5ebece6c.03e68","type":"inject","z":"b288bfb0.d6e09","name":"","topic":"","payload":"FC_WRITE","payloadType":"flow","repeat":"","crontab":"","once":true,"x":908.5,"y":477,"wires":[["89b1be79.58eb4"]]},{"id":"b5f4eba3.de7cd8","type":"inject","z":"b288bfb0.d6e09","name":"","topic":"","payload":"conversion_write","payloadType":"flow","repeat":"0.1","crontab":"","once":true,"x":926.5,"y":517,"wires":[["32c05ccb.b0cde4"]]},{"id":"12609374.6accad","type":"ui_text_input","z":"b288bfb0.d6e09","name":"","label":"Value","group":"c704cb95.d22fd8","order":3,"width":0,"height":0,"passthru":false,"mode":"text","delay":"100","topic":"","x":1115,"y":557,"wires":[["f9016ac0.326db8"]]},{"id":"f9016ac0.326db8","type":"function","z":"b288bfb0.d6e09","name":"save","func":"flow.set(\"value\", msg.payload);","outputs":"0","noerr":0,"x":1281.5,"y":557,"wires":[]},{"id":"f08cda05.7f3378","type":"comment","z":"b288bfb0.d6e09","name":"READ","info":"","x":67.5,"y":220,"wires":[]},{"id":"7ef35327.3d9adc","type":"comment","z":"b288bfb0.d6e09","name":"WRITE","info":"","x":797,"y":269,"wires":[]},{"id":"5d07bc56.051f34","type":"comment","z":"b288bfb0.d6e09","name":"OUTPUT","info":"","x":79,"y":29,"wires":[]},{"id":"6a7d00ee.6f2c4","type":"ui_switch","z":"b288bfb0.d6e09","name":"","label":"Hex Values","group":"9a7dbe19.5632c","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":428.765625,"y":540.75,"wires":[["6bd702c4.9a703c"]]},{"id":"6bd702c4.9a703c","type":"function","z":"b288bfb0.d6e09","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":579.265625,"y":540.75,"wires":[]},{"id":"8cb6ae59.e510e","type":"inject","z":"b288bfb0.d6e09","name":"","topic":"","payload":"hex","payloadType":"flow","repeat":"0.1","crontab":"","once":true,"x":197.265625,"y":540.75,"wires":[["6a7d00ee.6f2c4"]]},{"id":"4feb0629.a62638","type":"switch","z":"b288bfb0.d6e09","name":"","property":"hex","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","outputs":2,"x":718.7656631469727,"y":128.75,"wires":[["2fef0ce5.90fd34"],["af871a21.4a9c38"]]},{"id":"2fef0ce5.90fd34","type":"function","z":"b288bfb0.d6e09","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":946.765625,"y":122.75,"wires":[["af871a21.4a9c38"]]},{"id":"9013bf63.a4239","type":"inject","z":"b288bfb0.d6e09","name":"","topic":"","payload":"conversion_float","payloadType":"flow","repeat":"0.1","crontab":"","once":true,"x":214,"y":596,"wires":[["300077a3.d6b298"]]},{"id":"300077a3.d6b298","type":"ui_switch","z":"b288bfb0.d6e09","name":"","label":"Float IEEE-754","group":"9a7dbe19.5632c","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":433.5,"y":596,"wires":[["7b103d40.5468a4"]]},{"id":"7b103d40.5468a4","type":"function","z":"b288bfb0.d6e09","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":592,"y":596,"wires":[]},{"id":"faae72aa.2e993","type":"switch","z":"b288bfb0.d6e09","name":"","property":"conversion_float","propertyType":"flow","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","outputs":2,"x":858,"y":167,"wires":[["af871a21.4a9c38"],["f20fd4f4.eac6e8"]]},{"id":"f20fd4f4.eac6e8","type":"toFloat","z":"b288bfb0.d6e09","name":"","toFixed":"2","x":995.5,"y":190,"wires":[["af871a21.4a9c38"]]},{"id":"b6167a92.509788","type":"debug","z":"b288bfb0.d6e09","name":"","active":true,"console":"false","complete":"false","x":1170,"y":240,"wires":[]},{"id":"3441dbcd.47ca34","type":"debug","z":"b288bfb0.d6e09","name":"","active":true,"console":"false","complete":"false","x":1330,"y":320,"wires":[]},{"id":"9a7dbe19.5632c","type":"ui_group","z":"","name":"Read","tab":"fa44ba74.fc7d48","order":1,"disp":true,"width":"6"},{"id":"ab1b6187.a368f","type":"modbus-client","z":"","name":"localhost","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":1,"commandDelay":1,"clientTimeout":1000,"reconnectTimeout":2000},{"id":"a695d6ef.309968","type":"ui_group","z":"","name":"Output","tab":"fa44ba74.fc7d48","order":3,"disp":true,"width":"12"},{"id":"c704cb95.d22fd8","type":"ui_group","z":"","name":"Write","tab":"fa44ba74.fc7d48","order":2,"disp":true,"width":"6"},{"id":"fa44ba74.fc7d48","type":"ui_tab","z":"","name":"Modscan","icon":"dashboard"}]
robertsLando

Flow Info

created 1 month ago
updated 2 weeks, 1 day ago

Node Types

Core
  • comment (x3)
  • debug (x2)
  • function (x18)
  • inject (x13)
  • switch (x3)
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