Skip to content

Instantly share code, notes, and snippets.

@leedrch
Created January 5, 2019 17:23
Show Gist options
  • Save leedrch/4a60e796275e389a8435c086042d93f5 to your computer and use it in GitHub Desktop.
Save leedrch/4a60e796275e389a8435c086042d93f5 to your computer and use it in GitHub Desktop.
Node-Red Flow example : Buffer & Serial Connection
[{"id":"ef756f0b.6bb44","type":"comment","z":"df898261.0c874","name":"Buffer RS232 Example","info":"Example - buffer rs232\nhttps://nodejs.org/api/buffer.html\n\nInject node (buffer editor)\n[1,2,3,10,11,12]\n\nFunction node (encoding : hex,utf8,base64,utf16le,ucs2)\nmsg.payload = new Buffer(\"01020a0b\", \"hex\");\nmsg.payload = new Buffer([0x01,0x02,0x03]);\nmsg.payload = Buffer.from([0x01,0x02,0x03,0x0d,0x0a]);\n\nBuffer slice\nvar buffer = new Buffer([0x01,0x02,0x03,0x0d,0x0a]);\nmsg.payload = buffer.slice(2,4);\n\nBuffer copy\nvar buf1 = new Buffer([0x0a,0x0b,0x0c,0x0d,0x0f]);\nvar buf2 = new Buffer(\"010203040506070809\",\"hex\");\nbuf1.copy(buf2,3,1,4);\nmsg.payload = buf2;\n\nBuffer concat\nvar buf1 = new Buffer(\"010203\",\"hex\");\nvar buf2 = new Buffer([0x04,0x05,0x06]);\nmsg.payload = Buffer.concat([buf1,buf2]).toString();\n\nPayload Output\nmsg.payload = new Buffer(\"010203\",\"hex\");\nmsg.payload = new Buffer(\"040506\",\"hex\");\nvar buf1 = new Buffer(\"0a0b0c\",\"hex\");\nvar buf2 = msg.payload;\nmsg.payload = Buffer.concat([buf1,buf2]).toString();\n","x":143.5,"y":34,"wires":[]},{"id":"60301371.384804","type":"serial in","z":"df898261.0c874","name":"","serial":"bb41ba26.cc13a","x":338,"y":36,"wires":[["348a566a.1a0a92"]]},{"id":"348a566a.1a0a92","type":"debug","z":"df898261.0c874","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":485,"y":36,"wires":[]},{"id":"a936fb91.520d38","type":"inject","z":"df898261.0c874","name":"[1,2,3,10,11,12]","topic":"","payload":"[1,2,3,10,11,12]","payloadType":"bin","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":193,"y":98,"wires":[["2873f328.07a314"]]},{"id":"2873f328.07a314","type":"serial out","z":"df898261.0c874","name":"","serial":"ac94254a.4b61b","x":473,"y":98,"wires":[]},{"id":"96091779.61933","type":"serial out","z":"df898261.0c874","name":"","serial":"ac94254a.4b61b","x":482.5,"y":166,"wires":[]},{"id":"5d305dc8.efc104","type":"function","z":"df898261.0c874","name":"hex","func":"msg.payload = Buffer.from(\"01020a0b\", \"hex\");\nreturn msg;","outputs":1,"noerr":0,"x":328.5,"y":166,"wires":[["96091779.61933"]]},{"id":"fc1bc01d.0a8fd8","type":"inject","z":"df898261.0c874","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":174.5,"y":166,"wires":[["5d305dc8.efc104"]]},{"id":"94f22f1e.fbc4","type":"serial out","z":"df898261.0c874","name":"","serial":"ac94254a.4b61b","x":482,"y":226,"wires":[]},{"id":"4a3a333a.95d8bc","type":"function","z":"df898261.0c874","name":"0x01","func":"msg.payload = Buffer.from([0x01,0x02,0x03]);\nreturn msg;","outputs":1,"noerr":0,"x":328,"y":226,"wires":[["94f22f1e.fbc4"]]},{"id":"43bac896.8f2cf8","type":"inject","z":"df898261.0c874","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":174,"y":226,"wires":[["4a3a333a.95d8bc"]]},{"id":"dd56e89a.294d28","type":"serial out","z":"df898261.0c874","name":"","serial":"ac94254a.4b61b","x":482,"y":286,"wires":[]},{"id":"d8019613.986c6","type":"function","z":"df898261.0c874","name":"crlf","func":"msg.payload = new Buffer([0x01,0x02,0x03,0x0d,0x0a]);\n\nreturn msg;","outputs":1,"noerr":0,"x":328,"y":286,"wires":[["dd56e89a.294d28"]]},{"id":"afcb385e.af32c","type":"inject","z":"df898261.0c874","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":174,"y":286,"wires":[["d8019613.986c6"]]},{"id":"aaafd225.9daae","type":"serial out","z":"df898261.0c874","name":"","serial":"ac94254a.4b61b","x":481,"y":339,"wires":[]},{"id":"52dcfb2d.0e50f4","type":"function","z":"df898261.0c874","name":"slice","func":"var buffer = new Buffer([0x01,0x02,0x03,0x0d,0x0a]);\nmsg.payload = buffer.slice(2,4);\n\nreturn msg;","outputs":1,"noerr":0,"x":327,"y":339,"wires":[["aaafd225.9daae"]]},{"id":"fcb46701.1150b","type":"inject","z":"df898261.0c874","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":173,"y":339,"wires":[["52dcfb2d.0e50f4"]]},{"id":"24879f3c.f3825","type":"serial out","z":"df898261.0c874","name":"","serial":"ac94254a.4b61b","x":484,"y":392,"wires":[]},{"id":"531af2cf.289634","type":"function","z":"df898261.0c874","name":"copy","func":"var buf1 = new Buffer([0x0a,0x0b,0x0c,0x0d,0x0f]);\nvar buf2 = new Buffer(\"010203040506070809\",\"hex\");\nbuf1.copy(buf2,3,1,4);\nmsg.payload = buf2;\n\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":392,"wires":[["24879f3c.f3825"]]},{"id":"90476fe8.430f","type":"inject","z":"df898261.0c874","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":176,"y":392,"wires":[["531af2cf.289634"]]},{"id":"ac7af238.d3fbc8","type":"serial out","z":"df898261.0c874","name":"","serial":"ac94254a.4b61b","x":483,"y":444,"wires":[]},{"id":"2fa08fe.f08fef","type":"function","z":"df898261.0c874","name":"concat","func":"var buf1 = new Buffer(\"010203\",\"hex\");\nvar buf2 = new Buffer([0x04,0x05,0x06]);\nmsg.payload = Buffer.concat([buf1,buf2]).toString();\n\nreturn msg;","outputs":1,"noerr":0,"x":329,"y":444,"wires":[["ac7af238.d3fbc8"]]},{"id":"35324182.342c9e","type":"inject","z":"df898261.0c874","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":175,"y":444,"wires":[["2fa08fe.f08fef"]]},{"id":"46c077d6.4c2f88","type":"serial out","z":"df898261.0c874","name":"","serial":"ac94254a.4b61b","x":632,"y":506,"wires":[]},{"id":"ba36d427.81372","type":"function","z":"df898261.0c874","name":"abc","func":"var buf1 = new Buffer(\"0a0b0c\",\"hex\");\nvar buf2 = msg.payload;\nmsg.payload = Buffer.concat([buf1,buf2]).toString();\n\nreturn msg;","outputs":1,"noerr":0,"x":483,"y":506,"wires":[["46c077d6.4c2f88"]]},{"id":"5fba404c.fc88f","type":"inject","z":"df898261.0c874","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":174,"y":510,"wires":[["50ca6da9.5277cc"]]},{"id":"50ca6da9.5277cc","type":"function","z":"df898261.0c874","name":"123","func":"msg.payload = new Buffer(\"010203\",\"hex\");\nreturn msg;","outputs":1,"noerr":0,"x":334,"y":509,"wires":[["ba36d427.81372"]]},{"id":"ac685636.d3b8a8","type":"inject","z":"df898261.0c874","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":174,"y":562,"wires":[["3199a3b0.cc3534"]]},{"id":"3199a3b0.cc3534","type":"function","z":"df898261.0c874","name":"456","func":"msg.payload = new Buffer(\"040506\",\"hex\");\nreturn msg;","outputs":1,"noerr":0,"x":332,"y":561,"wires":[["ba36d427.81372"]]},{"id":"bb41ba26.cc13a","type":"serial-port","z":"","serialport":"COM15","serialbaud":"38400","databits":"8","parity":"none","stopbits":"1","newline":"3","bin":"bin","out":"time","addchar":false},{"id":"ac94254a.4b61b","type":"serial-port","z":"","serialport":"COM13","serialbaud":"38400","databits":"8","parity":"none","stopbits":"2","newline":"3","bin":"bin","out":"time","addchar":false}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment