node-red-wisebox

This node is designed to control and retrieve machine or process information via a USB port with the Wisebox SE-214 module. This node allows us to obtain or expand the digital input and output ports via USB.

[{"id":"326b7469.5761bc","type":"subflow","name":"Wisebox","info":"","category":"","in":[{"x":160,"y":180,"wires":[{"id":"ce0bd7e0.02a848"}]}],"out":[{"x":1460,"y":400,"wires":[{"id":"7a4c29e.9749ad8","port":0},{"id":"afaf5db9.46ab3","port":0},{"id":"2d723b6e.8c28d4","port":0}]}],"env":[]},{"id":"fe12a3ef.a3b3c","type":"serial in","z":"326b7469.5761bc","name":"Serial Out","serial":"78e3a0fa.0ca47","x":200,"y":420,"wires":[["d2a4a9c2.0767c8"]]},{"id":"c6404839.cfd7e8","type":"change","z":"326b7469.5761bc","name":"Read","rules":[{"t":"set","p":"input1","pt":"flow","to":"$boolean($number($substring(payload, 14,1)))","tot":"jsonata"},{"t":"set","p":"input2","pt":"flow","to":"$boolean($number($substring(payload, 13,1)))","tot":"jsonata"},{"t":"set","p":"input3","pt":"flow","to":"$boolean($number($substring(payload, 12,1)))","tot":"jsonata"},{"t":"set","p":"input4","pt":"flow","to":"$boolean($number($substring(payload, 11,1)))","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"$flowContext(\"input1\") & \";\" & $flowContext(\"input2\") & \";\" & $flowContext(\"input3\") & \";\" & $flowContext(\"input4\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1110,"y":340,"wires":[["afaf5db9.46ab3"]]},{"id":"633cadf0.ce2af4","type":"switch","z":"326b7469.5761bc","name":"Verify command","property":"comando","propertyType":"msg","rules":[{"t":"eq","v":"DI","vt":"str"},{"t":"eq","v":"SO","vt":"str"},{"t":"eq","v":"ER","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":920,"y":380,"wires":[["c6404839.cfd7e8"],["7a4c29e.9749ad8"],["5a076f7c.6717a"]]},{"id":"ce0bd7e0.02a848","type":"switch","z":"326b7469.5761bc","name":"","property":"command","propertyType":"msg","rules":[{"t":"eq","v":"write","vt":"str"},{"t":"eq","v":"read","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":290,"y":180,"wires":[["53a03aba.2b0944"],["5c0022e1.c31b5c"],["e6608a07.09cec8"]]},{"id":"53a03aba.2b0944","type":"change","z":"326b7469.5761bc","name":"String Write","rules":[{"t":"set","p":"string","pt":"msg","to":"\"9901SO0\" & msg.topic","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":140,"wires":[["154cf06d.b134a"]]},{"id":"7f2f83c5.89113c","type":"serial out","z":"326b7469.5761bc","name":"Serial In","serial":"78e3a0fa.0ca47","x":880,"y":160,"wires":[]},{"id":"5c0022e1.c31b5c","type":"change","z":"326b7469.5761bc","name":"String Read","rules":[{"t":"set","p":"payload","pt":"msg","to":"9901DI","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":180,"wires":[["154cf06d.b134a"]]},{"id":"154cf06d.b134a","type":"function","z":"326b7469.5761bc","name":"Checksum","func":"  if(msg.command == \"write\"){\n      var result = msg.string + Number(msg.payload);\n  }\n  if(msg.command == \"read\"){\n      var result = msg.payload;\n  }\n  var checksum = 0;\n  for(var i = 0; i < result.length; i++) {\n    checksum = checksum ^ result.charCodeAt(i); //checksum XOR ASCII Decimal\n  }\n\n  //The number will show as an hexadecimal value and UpperCase\n  var hexsum = checksum.toString(16).toUpperCase(); \n  if (hexsum.length < 2) {\n    hexsum = \"0\" + hexsum;\n  }\n\n  msg.payload = \"[\" + result + hexsum + \"]\"\n\nreturn msg;","outputs":1,"noerr":0,"x":690,"y":160,"wires":[["7f2f83c5.89113c"]]},{"id":"1fd2e4c7.66abeb","type":"change","z":"326b7469.5761bc","name":"String Fields","rules":[{"t":"set","p":"origem","pt":"msg","to":"$substring(payload, 1,2)","tot":"jsonata"},{"t":"set","p":"destino","pt":"msg","to":"$substring(payload, 3,2)","tot":"jsonata"},{"t":"set","p":"comando","pt":"msg","to":"$substring(payload, 5,2)","tot":"jsonata"},{"t":"set","p":"dado","pt":"msg","to":"$substring(payload, 7,2)","tot":"jsonata"},{"t":"delete","p":"calcChecksum","pt":"msg"},{"t":"delete","p":"receivedChecksum","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":380,"wires":[["633cadf0.ce2af4"]]},{"id":"d2a4a9c2.0767c8","type":"function","z":"326b7469.5761bc","name":"Checksum","func":"  var checksum = 0;\n  var length = msg.payload.length;\n  var string = msg.payload.substr(1, length-4);\n\n  for(var i = 0; i < string.length; i++) {\n    checksum = checksum ^ string.charCodeAt(i); //checksum XOR ASCII Decimal\n  }\n\n  //The number will show as an hexadecimal value and UpperCase\n  var hexsum = checksum.toString(16).toUpperCase(); \n  if (hexsum.length < 2) {\n    hexsum = \"0\" + hexsum;\n  }\n\n  msg.calcChecksum = hexsum;\n  msg.receivedChecksum = msg.payload.substr(length-3,2);\n\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":420,"wires":[["7ff5d03f.ba733"]]},{"id":"7ff5d03f.ba733","type":"switch","z":"326b7469.5761bc","name":"","property":"calcChecksum","propertyType":"msg","rules":[{"t":"eq","v":"receivedChecksum","vt":"msg"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":530,"y":420,"wires":[["1fd2e4c7.66abeb"],["66732741.5dc9a8"]]},{"id":"7a4c29e.9749ad8","type":"change","z":"326b7469.5761bc","name":"Write","rules":[{"t":"set","p":"payload","pt":"msg","to":"Command Success","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1270,"y":380,"wires":[[]]},{"id":"66732741.5dc9a8","type":"change","z":"326b7469.5761bc","name":"Error Checksum","rules":[{"t":"set","p":"Error","pt":"msg","to":"Checksum Failure","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":460,"wires":[["8ac34dbd.5a609"]]},{"id":"afaf5db9.46ab3","type":"csv","z":"326b7469.5761bc","name":"","sep":";","hdrin":"","hdrout":"","multi":"one","ret":"\\n","temp":"input1, input2, input3, input4","skip":"0","x":1270,"y":340,"wires":[[]]},{"id":"932d1e45.3aeab","type":"switch","z":"326b7469.5761bc","name":"","property":"dado","propertyType":"msg","rules":[{"t":"eq","v":"01","vt":"str"},{"t":"eq","v":"02","vt":"str"},{"t":"eq","v":"03","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":1010,"y":660,"wires":[["81381baf.c98768"],["f778abca.e3d568"],["109f38ce.aec827"]]},{"id":"81381baf.c98768","type":"change","z":"326b7469.5761bc","name":"Sitaxe","rules":[{"t":"set","p":"Error","pt":"msg","to":"Erro de sintaxe (ER01)","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1230,"y":620,"wires":[["15a3a61e.663a5a"]]},{"id":"f778abca.e3d568","type":"change","z":"326b7469.5761bc","name":"Checksum","rules":[{"t":"set","p":"Error","pt":"msg","to":"Erro de Checksum (ER02)","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1220,"y":660,"wires":[["15a3a61e.663a5a"]]},{"id":"109f38ce.aec827","type":"change","z":"326b7469.5761bc","name":"Comando Inválido","rules":[{"t":"set","p":"Error","pt":"msg","to":"Comando Inválido (ER03)","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1210,"y":700,"wires":[["15a3a61e.663a5a"]]},{"id":"5a076f7c.6717a","type":"link out","z":"326b7469.5761bc","name":"Verify command Out","links":["4cfe580d.7f5768"],"x":1075,"y":420,"wires":[]},{"id":"4cfe580d.7f5768","type":"link in","z":"326b7469.5761bc","name":"Exception In","links":["5a076f7c.6717a"],"x":895,"y":660,"wires":[["932d1e45.3aeab"]]},{"id":"2d723b6e.8c28d4","type":"link in","z":"326b7469.5761bc","name":"Subflow Out","links":["15a3a61e.663a5a","c463504d.042f8"],"x":1295,"y":460,"wires":[[]]},{"id":"195d683f.5b6028","type":"comment","z":"326b7469.5761bc","name":"Exception","info":"","x":940,"y":580,"wires":[]},{"id":"8ac34dbd.5a609","type":"link out","z":"326b7469.5761bc","name":"Error Checksum Out","links":["2d723b6e.8c28d4"],"x":1075,"y":460,"wires":[]},{"id":"7026ff34.7c68","type":"comment","z":"326b7469.5761bc","name":"Send Command to Serial Port","info":"","x":250,"y":100,"wires":[]},{"id":"ca6fa2eb.dd19","type":"comment","z":"326b7469.5761bc","name":"Send Command to Serial Port","info":"","x":260,"y":360,"wires":[]},{"id":"15a3a61e.663a5a","type":"link out","z":"326b7469.5761bc","name":"Exception Out","links":["2d723b6e.8c28d4"],"x":1415,"y":660,"wires":[]},{"id":"c463504d.042f8","type":"link out","z":"326b7469.5761bc","name":"Command Error Out","links":[],"x":655,"y":220,"wires":[]},{"id":"e6608a07.09cec8","type":"change","z":"326b7469.5761bc","name":"Command Error","rules":[{"t":"set","p":"origem","pt":"msg","to":"99","tot":"str"},{"t":"set","p":"destino","pt":"msg","to":"01","tot":"str"},{"t":"set","p":"comando","pt":"msg","to":"ER","tot":"str"},{"t":"set","p":"Error","pt":"msg","to":"'msg.command' is INVALID","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":220,"wires":[["c463504d.042f8"]]},{"id":"78e3a0fa.0ca47","type":"serial-port","z":"","serialport":"/dev/ttyAMA0","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","waitfor":"","newline":"1000","bin":"bin","out":"interbyte","addchar":"","responsetimeout":"10000"},{"id":"86075115.57cf6","type":"subflow:326b7469.5761bc","z":"285d294d.2cbdb6","name":"","env":[],"x":880,"y":360,"wires":[["786315b0.3f130c"]],"info":"msg.topic = Input number (1-4); (Type String)\r\n\r\nmsg.command = \"write\"/\"read\"; (Type String)\r\n\r\nmsg.payload = value to write in an output (true/false); (Type Boolean)\r\n\r\nExamples:\r\n\r\n    To WRITE the value true, in the output 3, set:\r\n        msg.topic = 3;\r\n        msg.command = write;\r\n        msg.payload = true.\r\n        \r\n    To READ all input values, set:\r\n        msg.command = read."},{"id":"786315b0.3f130c","type":"debug","z":"285d294d.2cbdb6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1030,"y":360,"wires":[]},{"id":"f7896ff7.ccae3","type":"inject","z":"285d294d.2cbdb6","name":"Write","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":530,"y":320,"wires":[["c365e777.6e93d8"]]},{"id":"c365e777.6e93d8","type":"change","z":"285d294d.2cbdb6","name":"Command Write","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"command","pt":"msg","to":"write","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"4","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":320,"wires":[["86075115.57cf6"]]},{"id":"a7209919.224d18","type":"inject","z":"285d294d.2cbdb6","name":"Read","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":530,"y":400,"wires":[["9214d6dc.739d18"]]},{"id":"9214d6dc.739d18","type":"change","z":"285d294d.2cbdb6","name":"Command Read","rules":[{"t":"set","p":"command","pt":"msg","to":"read","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":400,"wires":[["86075115.57cf6"]]}]

Flow Info

Created 6 years, 1 month ago
Rating: not yet rated

Actions

Rate:

Node Types

Core
  • change (x12)
  • comment (x3)
  • csv (x1)
  • debug (x1)
  • function (x2)
  • inject (x2)
  • link in (x2)
  • link out (x4)
  • switch (x4)
Other
  • serial in (x1)
  • serial out (x1)
  • serial-port (x1)
  • subflow (x1)
  • subflow:326b7469.5761bc (x1)

Tags

Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option