How you have created these strings in your second posting (4th post)?
What is the output when you use the standard settings:
How you have created these strings in your second posting (4th post)?
What is the output when you use the standard settings:
I tried your solution to re-arragent the buffer but there is something broken with the offset ... I do not understand this part good enough to fix it myself
Can you change the fist buffer maker as follows:
remove the link first to the first buffer parser - and post the debug of the buffer maker output
the result is a set of 5 messages with buffers of different lengths ... continously repaeted
That looks perfect . so the first string should be filtered out by the complete flow. - so in my opinion you can try the flow.
This looks to match the correct scheme.
sorry, no ... it is even more complicated:
the length of the answer-string is quite variable:
5, 15, 16, 76 and 77 characters .... sometimes (seldom) only 66
After the puffer parser node I get A LOT of messages containing the wanted pattern ... but not on the right position:
most of the time they are ignored:
OK - so in principle it is working but we need somehow splitting the stream at the correct positions.
could it be that /n is the wrong character to split the stream ?
these strings are FAR to short:
thats how the green ones start and they are MUCH longer ...
So I have now an idea how to get it probably correct - separated.
can you use your serial node in that way - that single bytes will be the output (no character specified)
or buffer = 0
So unfortunately is the split node not working as expected. In my opinion an issue should be raised.
Originally I expected that the split node would work to analyse the data stream:
However the split not works not properly - so the data stream is splitted each time a byte with value 36 is recognized - and not the whole buffer means 2 bytes with value 36.
So I wrote 2 function nodes - the first node splits a stream into parts splitted by 2 bytes - defined as header:
const header = Buffer.from([0x24,0x24]);
The second function node filters all messages in combination of header and command.
const filter = Buffer.from([0x24,0x24,0x56]);
So I hope the flow will work:
[
{
"id": "868aa4256ca689ac",
"type": "function",
"z": "78d94accf7f5ec3c",
"name": "Analyse stream",
"func": "if (msg.flush){\n msg.payload=context.get(\"buffer\");\n context.set(\"buffer\",undefined);\n return msg;\n}\n\n\nconst header = Buffer.from([0x24,0x24]);\nvar buffer = context.get(\"buffer\")||Buffer.alloc(0);\n\nvar arr = [buffer, msg.payload];\n\nmsg.payload = undefined;\nbuffer = Buffer.concat(arr);\n\n\nif (buffer.indexOf(header) >= 0 ) {\n var tmp = buffer.slice(2);\n var arrSliced =[]; \n \n var i = tmp.indexOf(header);\n\n if (tmp.indexOf(header) >= 0 ){ \n arrSliced[0] = buffer.slice(0, i + 2);\n buffer = buffer.slice(i + 2); \n if (arrSliced[0].indexOf(header) >= 0) msg.payload = arrSliced[0];\n if (msg.payload.equals(header)) msg.payload = \"\";\n }\n \n}\n\ncontext.set(\"buffer\",buffer);\nif (msg.payload) return msg;\n \n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 2120,
"y": 4160,
"wires": [
[
"4ba58e3fe27b80d3"
]
]
},
{
"id": "4ba58e3fe27b80d3",
"type": "function",
"z": "78d94accf7f5ec3c",
"name": "filter command",
"func": "const filter = Buffer.from([0x24,0x24,0x56]);\nif (Buffer.isBuffer(msg.payload)) {\n if (filter.equals(msg.payload.slice(0,3))) return msg;\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 2320,
"y": 4160,
"wires": [
[
"850b1c253ed01d58",
"623dcd793312299e"
]
]
},
{
"id": "57f673a1708bf489",
"type": "debug",
"z": "78d94accf7f5ec3c",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 2690,
"y": 4160,
"wires": []
},
{
"id": "850b1c253ed01d58",
"type": "buffer-parser",
"z": "78d94accf7f5ec3c",
"name": "",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [
{
"type": "byte",
"name": "Header",
"offset": 0,
"length": 2,
"offsetbit": 0,
"scale": "1",
"mask": ""
},
{
"type": "hex",
"name": "Command",
"offset": 2,
"length": 1,
"offsetbit": 0,
"scale": "1",
"mask": ""
},
{
"type": "uint8",
"name": "DataLength",
"offset": 3,
"length": 1,
"offsetbit": 0,
"scale": "1",
"mask": ""
},
{
"type": "uint16be",
"name": "Cell1",
"offset": 4,
"length": 1,
"offsetbit": 0,
"scale": "/1000",
"mask": ""
},
{
"type": "uint16be",
"name": "Cell2",
"offset": 6,
"length": 1,
"offsetbit": 0,
"scale": "/1000",
"mask": ""
},
{
"type": "uint16be",
"name": "Cell3",
"offset": 8,
"length": 1,
"offsetbit": 0,
"scale": "/1000",
"mask": ""
},
{
"type": "uint16be",
"name": "Cell4",
"offset": 10,
"length": 1,
"offsetbit": 0,
"scale": "/1000",
"mask": ""
},
{
"type": "uint16be",
"name": "Cell5",
"offset": 12,
"length": 1,
"offsetbit": 0,
"scale": "/1000",
"mask": ""
},
{
"type": "uint16be",
"name": "Cell6",
"offset": 14,
"length": 1,
"offsetbit": 0,
"scale": "/1000",
"mask": ""
},
{
"type": "uint16be",
"name": "Cell7",
"offset": 16,
"length": 1,
"offsetbit": 0,
"scale": "/1000",
"mask": ""
},
{
"type": "uint16be",
"name": "Cell8",
"offset": 18,
"length": 1,
"offsetbit": 0,
"scale": "/1000",
"mask": ""
},
{
"type": "uint16be",
"name": "Cell9",
"offset": 20,
"length": 1,
"offsetbit": 0,
"scale": "/1000",
"mask": ""
},
{
"type": "uint16be",
"name": "Cell10",
"offset": 22,
"length": 1,
"offsetbit": 0,
"scale": "/1000",
"mask": ""
},
{
"type": "uint16be",
"name": "Cell11",
"offset": 24,
"length": 1,
"offsetbit": 0,
"scale": "/1000",
"mask": ""
},
{
"type": "uint16be",
"name": "Cell12",
"offset": 26,
"length": 1,
"offsetbit": 0,
"scale": "/1000",
"mask": ""
},
{
"type": "uint16be",
"name": "Cell13",
"offset": 28,
"length": 1,
"offsetbit": 0,
"scale": "/1000",
"mask": ""
},
{
"type": "uint16be",
"name": "Cell14",
"offset": 30,
"length": 1,
"offsetbit": 0,
"scale": "/1000",
"mask": ""
},
{
"type": "uint16be",
"name": "Cell15",
"offset": 32,
"length": 1,
"offsetbit": 0,
"scale": "/1000",
"mask": ""
},
{
"type": "uint16be",
"name": "Cell16",
"offset": 34,
"length": 1,
"offsetbit": 0,
"scale": "/1000",
"mask": ""
},
{
"type": "uint32le",
"name": "Wh",
"offset": 36,
"length": 1,
"offsetbit": 0,
"scale": "/1000",
"mask": ""
},
{
"type": "uint32le",
"name": "Ah",
"offset": 40,
"length": 1,
"offsetbit": 0,
"scale": "/1000",
"mask": ""
},
{
"type": "uint8",
"name": "CheckSum",
"offset": 44,
"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": 2510,
"y": 4160,
"wires": [
[
"57f673a1708bf489"
]
]
},
{
"id": "4ccf16891a5588e8",
"type": "inject",
"z": "78d94accf7f5ec3c",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "[36,36,86,45,12,253,13,4,13,4,13,2,13,3,13,4,13,6,13,1,13,8,13,2,13,5,12,254,13,6,12,251,13,15,12,252,118,254,213,2,99,20,14,0,149]",
"payloadType": "bin",
"x": 2130,
"y": 4200,
"wires": [
[
"4ba58e3fe27b80d3"
]
]
},
{
"id": "c4f48b5d708eb501",
"type": "inject",
"z": "78d94accf7f5ec3c",
"name": "",
"props": [
{
"p": "flush",
"v": "true",
"vt": "bool"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 1900,
"y": 4200,
"wires": [
[
"868aa4256ca689ac"
]
]
},
{
"id": "623dcd793312299e",
"type": "debug",
"z": "78d94accf7f5ec3c",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 2530,
"y": 4120,
"wires": []
}
]
One supplement:
As the buffers of the analyse node are sent only when the next header is detected - the last buffer remains in the context. To flush this buffer a msg.flush with a boolean true has to be sent to empty the node. So an additional trigger node is recommended, when the stream of bytes stopped.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.