Of course, carriage return at the beginning is unlogical, but I couldn't find any buffered commands or reset the controller.
This is just an easy way, thanks. I also used Colin's solution and wrote a function.
If you're still interested, here's the final flow (most of the work was done by Steve-Mcl, thanks a lot)
[
{
"id": "25115a9205cb179b",
"type": "tab",
"label": "Flow 7",
"disabled": false,
"info": "",
"env": []
},
{
"id": "a2fcda1461c0ad20",
"type": "inject",
"z": "25115a9205cb179b",
"name": "A buffer of [13,83,86,78,63]",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "[13,83,86,78,63]",
"payloadType": "bin",
"x": 230,
"y": 160,
"wires": [
[
"f50d9ff85ac5d511"
]
]
},
{
"id": "09937bc74c86f7c8",
"type": "debug",
"z": "25115a9205cb179b",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1550,
"y": 160,
"wires": []
},
{
"id": "5bc716610671b119",
"type": "serial request",
"z": "25115a9205cb179b",
"name": "",
"serial": "652032530abaf805",
"x": 1290,
"y": 160,
"wires": [
[
"09937bc74c86f7c8"
]
]
},
{
"id": "733f6e9d3f88c634",
"type": "inject",
"z": "25115a9205cb179b",
"name": "3 arrays",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "[[13,83,86,78,63],[13,83,86,78,63],[13,83,86,78,63]]",
"payloadType": "json",
"x": 180,
"y": 240,
"wires": [
[
"deee9cf29dfdfe1c"
]
]
},
{
"id": "deee9cf29dfdfe1c",
"type": "split",
"z": "25115a9205cb179b",
"name": "split arrays into single array messages",
"splt": "\\n",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "",
"x": 490,
"y": 240,
"wires": [
[
"f50d9ff85ac5d511"
]
]
},
{
"id": "c41ce46861fb7c84",
"type": "link call",
"z": "25115a9205cb179b",
"name": "",
"links": [
"84f9092da9772487"
],
"timeout": "30",
"x": 770,
"y": 820,
"wires": [
[
"8b4e254311072f42"
]
]
},
{
"id": "84f9092da9772487",
"type": "link in",
"z": "25115a9205cb179b",
"name": "split and space out",
"links": [],
"x": 135,
"y": 560,
"wires": [
[
"7fc26a18c529e88b"
]
]
},
{
"id": "a4c453a8cff80cad",
"type": "link out",
"z": "25115a9205cb179b",
"name": "link out 17",
"mode": "return",
"links": [],
"x": 1005,
"y": 560,
"wires": []
},
{
"id": "1e8f0f0fd4875a8b",
"type": "split",
"z": "25115a9205cb179b",
"name": "",
"splt": "\\n",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "",
"x": 600,
"y": 560,
"wires": [
[
"a4c453a8cff80cad"
]
]
},
{
"id": "a9bc3f158bdcdc06",
"type": "inject",
"z": "25115a9205cb179b",
"name": "A buffer of [13,83,86,78,63]",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "[13,83,86,78,63]",
"payloadType": "bin",
"x": 250,
"y": 820,
"wires": [
[
"c41ce46861fb7c84"
]
]
},
{
"id": "8b4e254311072f42",
"type": "debug",
"z": "25115a9205cb179b",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1110,
"y": 820,
"wires": []
},
{
"id": "fcd1829681bd95f7",
"type": "delay",
"z": "25115a9205cb179b",
"name": "rate limit 1 msg per 0.004s",
"pauseType": "rate",
"timeout": "4",
"timeoutUnits": "milliseconds",
"rate": "1",
"nbRateUnits": "0.004",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": true,
"outputs": 1,
"x": 800,
"y": 560,
"wires": [
[
"b523fae2cd9c4e91"
]
]
},
{
"id": "7fc26a18c529e88b",
"type": "buffer-parser",
"z": "25115a9205cb179b",
"name": "To byte array",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [
{
"type": "byte",
"name": "bytes",
"offset": 0,
"length": -1,
"offsetbit": 0,
"scale": "1",
"mask": ""
}
],
"swap1": "",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "payload",
"msgPropertyType": "str",
"resultType": "keyvalue",
"resultTypeType": "return",
"multipleResult": false,
"fanOutMultipleResult": false,
"setTopic": true,
"outputs": 1,
"x": 250,
"y": 560,
"wires": [
[
"f95f91d71154f654"
]
]
},
{
"id": "f95f91d71154f654",
"type": "change",
"z": "25115a9205cb179b",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.bytes",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 440,
"y": 560,
"wires": [
[
"1e8f0f0fd4875a8b"
]
]
},
{
"id": "d3fd829d2904048b",
"type": "comment",
"z": "25115a9205cb179b",
"name": "DEBUGGING: Testing the subroutines",
"info": "",
"x": 270,
"y": 720,
"wires": []
},
{
"id": "72bfa7b0f43569d9",
"type": "comment",
"z": "25115a9205cb179b",
"name": "SUBROUTINE: Split and space out ...................................................................................................................................................",
"info": "",
"x": 550,
"y": 520,
"wires": []
},
{
"id": "f50d9ff85ac5d511",
"type": "link call",
"z": "25115a9205cb179b",
"name": "",
"links": [
"84f9092da9772487"
],
"timeout": "30",
"x": 830,
"y": 160,
"wires": [
[
"267f4aca46af114a"
]
]
},
{
"id": "03ef5035195d70f0",
"type": "inject",
"z": "25115a9205cb179b",
"name": "3 arrays",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "[[13,83,86,78,63],[13,83,86,78,63],[13,83,86,78,63]]",
"payloadType": "json",
"x": 200,
"y": 880,
"wires": [
[
"97ef1658b96594c5"
]
]
},
{
"id": "97ef1658b96594c5",
"type": "split",
"z": "25115a9205cb179b",
"name": "",
"splt": "\\n",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "",
"x": 330,
"y": 880,
"wires": [
[
"87f5b04016e6be78"
]
]
},
{
"id": "21405ae10235d5b8",
"type": "inject",
"z": "25115a9205cb179b",
"name": "Command to controller?",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "SVP?",
"payloadType": "str",
"x": 220,
"y": 80,
"wires": [
[
"ea0bf94fa636f7cb"
]
]
},
{
"id": "e91c4873fcb1e11e",
"type": "inject",
"z": "25115a9205cb179b",
"name": "SVN?",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "SVN?",
"payloadType": "str",
"x": 190,
"y": 760,
"wires": [
[
"4b89d347dcc0ebad"
]
]
},
{
"id": "cfe5b00d586ef486",
"type": "link in",
"z": "25115a9205cb179b",
"name": "String-to-Buffer",
"links": [],
"x": 135,
"y": 480,
"wires": [
[
"1803bfb110594b07"
]
]
},
{
"id": "5ae1560a0296c2a2",
"type": "link out",
"z": "25115a9205cb179b",
"name": "link out 18",
"mode": "return",
"links": [],
"x": 555,
"y": 480,
"wires": []
},
{
"id": "98d3b2b76df98a5b",
"type": "comment",
"z": "25115a9205cb179b",
"name": "SUBROUTINE: String to Buffer + newline ..................................",
"info": "",
"x": 350,
"y": 440,
"wires": []
},
{
"id": "1803bfb110594b07",
"type": "buffer-maker",
"z": "25115a9205cb179b",
"name": "String to Buffer + lineFeed (ASCII 10)",
"specification": "spec",
"specificationType": "ui",
"items": [
{
"name": "stringData",
"type": "ascii",
"length": -1,
"dataType": "msg",
"data": "payload"
},
{
"name": "lineFeed",
"type": "byte",
"length": 1,
"dataType": "num",
"data": "10"
}
],
"swap1": "",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "payload",
"msgPropertyType": "str",
"x": 350,
"y": 480,
"wires": [
[
"5ae1560a0296c2a2",
"8dd46387e75bea4b"
]
]
},
{
"id": "4b89d347dcc0ebad",
"type": "link call",
"z": "25115a9205cb179b",
"name": "",
"links": [
"cfe5b00d586ef486"
],
"timeout": "30",
"x": 360,
"y": 760,
"wires": [
[
"c41ce46861fb7c84"
]
]
},
{
"id": "ea0bf94fa636f7cb",
"type": "link call",
"z": "25115a9205cb179b",
"name": "",
"links": [
"cfe5b00d586ef486"
],
"timeout": "30",
"x": 420,
"y": 80,
"wires": [
[
"03d52a67d5ef29d0",
"be5f056df2ad6e6a"
]
]
},
{
"id": "87f5b04016e6be78",
"type": "delay",
"z": "25115a9205cb179b",
"name": "",
"pauseType": "rate",
"timeout": "4",
"timeoutUnits": "milliseconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 520,
"y": 880,
"wires": [
[
"c41ce46861fb7c84"
]
]
},
{
"id": "03d52a67d5ef29d0",
"type": "debug",
"z": "25115a9205cb179b",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 670,
"y": 40,
"wires": []
},
{
"id": "b523fae2cd9c4e91",
"type": "debug",
"z": "25115a9205cb179b",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1050,
"y": 640,
"wires": []
},
{
"id": "267f4aca46af114a",
"type": "function",
"z": "25115a9205cb179b",
"name": "buffer to string",
"func": "msg.payload = Buffer.from([msg.payload]);\nmsg.payload = msg.payload.toString();\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1060,
"y": 160,
"wires": [
[
"5bc716610671b119",
"62b4fa5b208435f3"
]
]
},
{
"id": "291530279ba143fc",
"type": "debug",
"z": "25115a9205cb179b",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1150,
"y": 80,
"wires": []
},
{
"id": "be5f056df2ad6e6a",
"type": "function",
"z": "25115a9205cb179b",
"name": "set \"Carriage Return\" (\"13\") to first position of each buffer",
"func": "const nl = Buffer.from([13])\nmsg.payload = Buffer.concat( [nl, msg.payload] )\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 810,
"y": 80,
"wires": [
[
"f50d9ff85ac5d511",
"291530279ba143fc"
]
]
},
{
"id": "62b4fa5b208435f3",
"type": "debug",
"z": "25115a9205cb179b",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1330,
"y": 100,
"wires": []
},
{
"id": "8dd46387e75bea4b",
"type": "debug",
"z": "25115a9205cb179b",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 670,
"y": 380,
"wires": []
},
{
"id": "652032530abaf805",
"type": "serial-port",
"serialport": "COM5",
"serialbaud": "19200",
"databits": "8",
"parity": "none",
"stopbits": "1",
"waitfor": "",
"dtr": "none",
"rts": "none",
"cts": "none",
"dsr": "none",
"newline": "\\n",
"bin": "false",
"out": "char",
"addchar": "",
"responsetimeout": "4"
}
]