PLC やシリアル機器から届くデータは、たいてい数値の並びである。1つの温度を読むだけでも、どの位置から何バイトを取り出し、どの型として解釈し、何倍すれば実際の値になるのかを決めなければならない。バイト列そのものの成り立ちは変数ガイド Part 1 のバイナリデータとBufferで扱っている。
この変換は Function ノードでも書ける。ただし取り出す項目が増えるほどコードは長くなり、型やバイト順の取り違えを見つけにくくなる。buffer-parser は、同じ変換を表形式の設定に置き換える。
// Function ノードで書いた場合(3項目を取り出す)
const buf = Buffer.from(msg.payload);
msg.payload = {
temperature: buf.readInt16BE(0) * 0.1,
pressure: buf.readInt16BE(2) * 0.01,
running: (buf[4] & 0x01) === 1
};
return msg;
ややこしいのは、バイト順とワード順が別々に入れ替わることである。32 ビットの値は2つのワードに跨るため、バイト順が合っていてもワードの順番が逆なら、値は意味をなさない。
buffer-parser の「Byte swap」は、この入れ替えを設定で吸収するためにある。swap16 は2バイトごと、swap32 は4バイトごと、swap64 は8バイトごとに並びを反転する。
読めた値が意味をなさないときは、型の le と be を入れ替える前に Byte swap を試す。前述のとおりスワップは型変換より先に適用されるため、le と be の切り替えだけでは直らないズレがある。
📋 公式サンプルフロー(クリックで展開)
[
{
"id": "tab_bufparser_examples",
"type": "tab",
"label": "buffer-parser 公式サンプル",
"disabled": false,
"info": "",
"env": []
},
{
"id": "1a961982.6e0c66",
"type": "inject",
"z": "tab_bufparser_examples",
"name": "Trigger",
"topic": "",
"payload": "true",
"payloadType": "bool",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 220,
"y": 280,
"wires": [
[
"429874da.f0bfcc"
]
]
},
{
"id": "a03288ed.d73cf8",
"type": "buffer-parser",
"z": "tab_bufparser_examples",
"name": "",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [
{
"type": "16bitbe",
"name": "3 lots of 16 bits",
"offset": "0",
"length": "3",
"offsetbit": "0",
"mask": ""
},
{
"type": "bool",
"name": "32 bools offest by 8 bits",
"offset": "0",
"length": "32",
"offsetbit": "8",
"mask": ""
}
],
"swap1": "",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "payload",
"msgPropertyType": "str",
"resultType": "value",
"resultTypeType": "return",
"multipleResult": true,
"setTopic": true,
"x": 560,
"y": 280,
"wires": [
[
"af863e2a.965e3"
]
]
},
{
"id": "af863e2a.965e3",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 740,
"y": 280,
"wires": []
},
{
"id": "709dd163.59831",
"type": "comment",
"z": "tab_bufparser_examples",
"name": "Working with bits and bools",
"info": "",
"x": 260,
"y": 240,
"wires": []
},
{
"id": "429874da.f0bfcc",
"type": "function",
"z": "tab_bufparser_examples",
"name": "Array of WORDs",
"func": "msg.payload = [\n 0xffff,\n 0x000f,\n 0x00f0,\n 0x0f00,\n 0xf000,\n 0x0000,\n 0x0001,\n 0x1111,\n ]\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 380,
"y": 280,
"wires": [
[
"a03288ed.d73cf8"
]
]
},
{
"id": "51b464c8.11fc6c",
"type": "inject",
"z": "tab_bufparser_examples",
"name": "a buffer",
"topic": "",
"payload": "[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]",
"payloadType": "bin",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 220,
"y": 1120,
"wires": [
[
"5ff0a2f.c0b505c",
"19d8cbd0.a50204",
"768d5cd5.de98e4",
"517a8685.5bc3a8",
"24e73864.d37938"
]
]
},
{
"id": "517a8685.5bc3a8",
"type": "buffer-parser",
"z": "tab_bufparser_examples",
"name": "swap 16",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [],
"swap1": "swap16",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "booboo.poopoo",
"msgPropertyType": "",
"resultType": "buffer",
"resultTypeType": "return",
"multipleResult": false,
"setTopic": true,
"x": 490,
"y": 1040,
"wires": [
[
"d7ed39ae.6fc9f8"
]
]
},
{
"id": "d7ed39ae.6fc9f8",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "16",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 720,
"y": 1040,
"wires": []
},
{
"id": "e9648adf.fd8888",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "32",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 720,
"y": 1100,
"wires": []
},
{
"id": "fbf8d38a.e7063",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "64",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 720,
"y": 1160,
"wires": []
},
{
"id": "5ff0a2f.c0b505c",
"type": "buffer-parser",
"z": "tab_bufparser_examples",
"name": "swap 32",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [],
"swap1": "swap32",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "booboo.poopoo",
"msgPropertyType": "",
"resultType": "buffer",
"resultTypeType": "return",
"multipleResult": false,
"setTopic": true,
"x": 490,
"y": 1100,
"wires": [
[
"e9648adf.fd8888"
]
]
},
{
"id": "19d8cbd0.a50204",
"type": "buffer-parser",
"z": "tab_bufparser_examples",
"name": "swap 64",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [],
"swap1": "swap64",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "booboo.poopoo",
"msgPropertyType": "",
"resultType": "buffer",
"resultTypeType": "return",
"multipleResult": false,
"setTopic": true,
"x": 490,
"y": 1160,
"wires": [
[
"fbf8d38a.e7063"
]
]
},
{
"id": "768d5cd5.de98e4",
"type": "buffer-parser",
"z": "tab_bufparser_examples",
"name": "swap 64 32 16",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [],
"swap1": "swap64",
"swap2": "swap32",
"swap3": "swap16",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "booboo.poopoo",
"msgPropertyType": "",
"resultType": "buffer",
"resultTypeType": "output",
"multipleResult": false,
"setTopic": true,
"x": 510,
"y": 1220,
"wires": [
[
"63965e1a.2467"
]
]
},
{
"id": "63965e1a.2467",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "64 32 16",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 730,
"y": 1220,
"wires": []
},
{
"id": "24e73864.d37938",
"type": "buffer-parser",
"z": "tab_bufparser_examples",
"name": "none",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [],
"swap1": "",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "booboo.poopoo",
"msgPropertyType": "",
"resultType": "buffer",
"resultTypeType": "return",
"multipleResult": false,
"setTopic": true,
"x": 480,
"y": 980,
"wires": [
[
"1f005eb1.c33691"
]
]
},
{
"id": "1f005eb1.c33691",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "none",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 720,
"y": 980,
"wires": []
},
{
"id": "f06126a.b3cc7d8",
"type": "inject",
"z": "tab_bufparser_examples",
"name": "an array",
"topic": "",
"payload": "[258,772,1286,1800,2314,2828,3342,3856]",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 230,
"y": 1060,
"wires": [
[
"24e73864.d37938",
"517a8685.5bc3a8",
"5ff0a2f.c0b505c",
"19d8cbd0.a50204",
"768d5cd5.de98e4"
]
]
},
{
"id": "78cb82d2.22c08c",
"type": "buffer-parser",
"z": "tab_bufparser_examples",
"name": "",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "msg",
"items": [],
"swap1": "",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "",
"msgPropertyType": "",
"resultType": "value",
"resultTypeType": "output",
"multipleResult": false,
"setTopic": false,
"x": 720,
"y": 120,
"wires": [
[
"4e362474.a8e83c"
]
]
},
{
"id": "4e362474.a8e83c",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 740,
"y": 180,
"wires": []
},
{
"id": "ec2a43b5.c3d2b",
"type": "inject",
"z": "tab_bufparser_examples",
"name": "Pass data in as buffer",
"topic": "",
"payload": "[97,98,99,100,101,102,103,104,105,106,107,108,109,109,111,112,113,114,115,116,117,118,119,120,121,122]",
"payloadType": "bin",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 270,
"y": 120,
"wires": [
[
"db40592a.547028"
]
]
},
{
"id": "2d2fb31f.39dc1c",
"type": "function",
"z": "tab_bufparser_examples",
"name": "dynamically set data",
"func": "msg.payload = [0x6162, 0x6364, 0x6566, 0x6768, 0x696A, 0x6B6C, 0x6D6D, 0x6F70, 0x7172, 0x7374, 0x7576, 0x7778, 0x797A]\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 430,
"y": 180,
"wires": [
[
"db40592a.547028"
]
]
},
{
"id": "63781545.9792ac",
"type": "inject",
"z": "tab_bufparser_examples",
"name": "just a trigger",
"topic": "",
"payload": "true",
"payloadType": "bool",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 240,
"y": 180,
"wires": [
[
"2d2fb31f.39dc1c"
]
]
},
{
"id": "db40592a.547028",
"type": "function",
"z": "tab_bufparser_examples",
"name": "dynamically set spec",
"func": "msg.spec = {\n \"options\":\n {\n \"byteSwap\":true,\n \"resultType\":\"object\",\n \"singleResult\": true\n },\n \"items\":[\n {\"name\":\"myInt\",\"type\":\"int\",\"offset\":4},{\"name\":\"uint32s\",\"type\":\"uint32\",\"offset\":0,\"length\":4},{\"name\":\"floats\",\"type\":\"float\",\"offset\":0,\"length\":4},{\"name\":\"doubles\",\"type\":\"double\",\"offset\":0,\"length\":2},{\"name\":\"myString\",\"type\":\"string\",\"offset\":0,\"length\":5}\n ]\n}\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 530,
"y": 120,
"wires": [
[
"78cb82d2.22c08c"
]
]
},
{
"id": "1b83d748.5c0a29",
"type": "buffer-parser",
"z": "tab_bufparser_examples",
"name": "",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [
{
"type": "string",
"name": "plc1/production/alphabet",
"offset": "0",
"length": "26",
"offsetbit": "0",
"mask": ""
},
{
"type": "uint8",
"name": "plc1/production/status/count",
"offset": "25",
"length": "1",
"offsetbit": "0",
"mask": ""
},
{
"type": "uint8",
"name": "plc1/production/status/sequence",
"offset": "4",
"length": "1",
"offsetbit": "0",
"mask": ""
},
{
"type": "int16le",
"name": "plc1/machine/status/runner/temperature",
"offset": "26",
"length": "1",
"offsetbit": "0",
"mask": ""
},
{
"type": "int16be",
"name": "plc1/machine/status/runner/speed",
"offset": "26",
"length": "1",
"offsetbit": "0",
"mask": ""
},
{
"type": "bool",
"name": "plc1/machine/status/running",
"offset": "0",
"length": "1",
"offsetbit": "0",
"mask": ""
},
{
"type": "bool",
"name": "plc1/machine/status/warning",
"offset": "0",
"length": "1",
"offsetbit": "1",
"mask": ""
},
{
"type": "bool",
"name": "plc1/machine/status/fault",
"offset": "0",
"length": "1",
"offsetbit": "2",
"mask": ""
}
],
"swap1": "swap16",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "payload",
"msgPropertyType": "",
"resultType": "value",
"resultTypeType": "output",
"multipleResult": true,
"setTopic": true,
"x": 500,
"y": 380,
"wires": [
[
"58018932.2ccce8"
]
]
},
{
"id": "58018932.2ccce8",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 740,
"y": 380,
"wires": []
},
{
"id": "25ba06cd.4b38ca",
"type": "buffer-parser",
"z": "tab_bufparser_examples",
"name": "",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [
{
"type": "string",
"name": "alphabet",
"offset": "0",
"length": "26",
"offsetbit": "0",
"mask": ""
},
{
"type": "byte",
"name": "single byte pos 4",
"offset": "4",
"length": "1",
"offsetbit": "0",
"mask": ""
},
{
"type": "bcdbe",
"name": "3bcd",
"offset": "4",
"length": "5",
"offsetbit": "0",
"mask": "0x0FFF"
},
{
"type": "int16le",
"name": "Array[6] of int16le",
"offset": "26",
"length": "6",
"offsetbit": "0",
"mask": ""
},
{
"type": "int16be",
"name": "Array[6] of int16be",
"offset": "26",
"length": "6",
"offsetbit": "0",
"mask": ""
},
{
"type": "bool",
"name": "32 bools",
"offset": "0",
"length": "32",
"offsetbit": "0",
"mask": ""
},
{
"type": "16bitbe",
"name": "Array[4] of 16bits",
"offset": "0",
"length": "4",
"offsetbit": "0",
"mask": ""
}
],
"swap1": "swap16",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "data",
"msgPropertyType": "",
"resultType": "object",
"resultTypeType": "output",
"multipleResult": false,
"setTopic": true,
"x": 500,
"y": 460,
"wires": [
[
"86a325f6.aa8688"
]
]
},
{
"id": "86a325f6.aa8688",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "data",
"targetType": "msg",
"x": 730,
"y": 460,
"wires": []
},
{
"id": "84bede4f.ca9ad",
"type": "inject",
"z": "tab_bufparser_examples",
"name": "Fake PLC data 16bit Array",
"topic": "",
"payload": "[25185,25699,26213,26727,27241,27755,28013,28783,29297,29811,30325,30839,31353,256,512,768,1024,1280,1536,1792,2048,2304,2560,2816,3072,3597]",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 280,
"y": 380,
"wires": [
[
"1b83d748.5c0a29"
]
]
},
{
"id": "7b98fcf3.8e73c4",
"type": "inject",
"z": "tab_bufparser_examples",
"name": "Fake PLC data 16bit Array",
"topic": "",
"payload": "[25185,25699,26213,26727,27241,27755,28013,28783,29297,29811,30325,30839,31353,256,512,768,1024,1280,1536,1792,2048,2304,2560,2816,3072,3597]",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 280,
"y": 460,
"wires": [
[
"25ba06cd.4b38ca"
]
]
},
{
"id": "c7b2a471.623fd8",
"type": "comment",
"z": "tab_bufparser_examples",
"name": "take an array of 16bit values, byte reverse, split out several values and transmit individual messages with topic + payload",
"info": "",
"x": 550,
"y": 340,
"wires": []
},
{
"id": "e35f44bf.0724e8",
"type": "comment",
"z": "tab_bufparser_examples",
"name": "take an array of 16bit values, byte reverse, split out several values and transmit one message with named objects in msg.data",
"info": "",
"x": 570,
"y": 420,
"wires": []
},
{
"id": "be080136.0ddf6",
"type": "buffer-parser",
"z": "tab_bufparser_examples",
"name": "",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [
{
"type": "string",
"name": "alphabet",
"offset": "0",
"length": "26",
"offsetbit": "0",
"mask": ""
},
{
"type": "floatbe",
"name": "float BE from byte4",
"offset": "4",
"length": "1",
"offsetbit": "0",
"mask": ""
},
{
"type": "floatle",
"name": "float LE from byte4",
"offset": "4",
"length": "1",
"offsetbit": "0",
"mask": ""
},
{
"type": "bool",
"name": "32 bools",
"offset": "0",
"length": "32",
"offsetbit": "0",
"mask": ""
},
{
"type": "16bitbe",
"name": "Array[4] of 16bits",
"offset": "0",
"length": "4",
"offsetbit": "0",
"mask": ""
}
],
"swap1": "swap16",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "payload",
"msgPropertyType": "",
"resultType": "array",
"resultTypeType": "output",
"multipleResult": false,
"setTopic": true,
"x": 500,
"y": 560,
"wires": [
[
"fd5c5940.190838"
]
]
},
{
"id": "fd5c5940.190838",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 740,
"y": 560,
"wires": []
},
{
"id": "cc51cb1e.3f1428",
"type": "inject",
"z": "tab_bufparser_examples",
"name": "Fake PLC data buffer",
"topic": "",
"payload": "[98,97,100,99,102,101,104,103,106,105,108,107,110,109,112,111,114,113,116,115,118,117,120,119,122,121]",
"payloadType": "bin",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 270,
"y": 560,
"wires": [
[
"be080136.0ddf6"
]
]
},
{
"id": "d45509ca.dcb138",
"type": "comment",
"z": "tab_bufparser_examples",
"name": "take a buffer, byte reverse, split out several values and transmit one message as array of objects in msg.payload",
"info": "",
"x": 530,
"y": 520,
"wires": []
},
{
"id": "63a1e6f7.e6ae38",
"type": "buffer-parser",
"z": "tab_bufparser_examples",
"name": "",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [
{
"type": "string",
"name": "alphabet",
"offset": "0",
"length": "26",
"offsetbit": "0",
"mask": ""
},
{
"type": "floatbe",
"name": "float BE from byte4",
"offset": "4",
"length": "1",
"offsetbit": "0",
"mask": ""
},
{
"type": "floatle",
"name": "float LE from byte4",
"offset": "4",
"length": "1",
"offsetbit": "0",
"mask": ""
},
{
"type": "bool",
"name": "32 bools",
"offset": "0",
"length": "32",
"offsetbit": "0",
"mask": ""
},
{
"type": "16bitbe",
"name": "Array[4] of 16bits",
"offset": "0",
"length": "4",
"offsetbit": "0",
"mask": ""
}
],
"swap1": "swap16",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "result",
"msgPropertyType": "",
"resultType": "value",
"resultTypeType": "output",
"multipleResult": false,
"setTopic": true,
"x": 500,
"y": 660,
"wires": [
[
"c4f314e6.4a4d58"
]
]
},
{
"id": "c4f314e6.4a4d58",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "result",
"targetType": "msg",
"x": 740,
"y": 660,
"wires": []
},
{
"id": "1e66e973.4a2b07",
"type": "inject",
"z": "tab_bufparser_examples",
"name": "Fake PLC data buffer",
"topic": "",
"payload": "[98,97,100,99,102,101,104,103,106,105,108,107,110,109,112,111,114,113,116,115,118,117,120,119,122,121]",
"payloadType": "bin",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 270,
"y": 660,
"wires": [
[
"63a1e6f7.e6ae38"
]
]
},
{
"id": "66eb1379.961c2c",
"type": "comment",
"z": "tab_bufparser_examples",
"name": "take a buffer, split out several values and transmit one message as values in msg.result",
"info": "",
"x": 450,
"y": 620,
"wires": []
},
{
"id": "712e7a13.d64a04",
"type": "comment",
"z": "tab_bufparser_examples",
"name": "Dynamically set data and spec",
"info": "",
"x": 270,
"y": 80,
"wires": []
},
{
"id": "a7e43760.9ac7a8",
"type": "inject",
"z": "tab_bufparser_examples",
"name": "an array",
"topic": "",
"payload": "[258,772,1286,1800,2314,2828,3342,3856]",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 230,
"y": 860,
"wires": [
[
"9b05469c.03bbf8"
]
]
},
{
"id": "9b05469c.03bbf8",
"type": "buffer-parser",
"z": "tab_bufparser_examples",
"name": "",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [],
"swap1": "",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "payload",
"msgPropertyType": "",
"resultType": "buffer",
"resultTypeType": "output",
"multipleResult": false,
"setTopic": true,
"x": 500,
"y": 860,
"wires": [
[
"9e69d945.7303f8"
]
]
},
{
"id": "9e69d945.7303f8",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "buffer",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 720,
"y": 860,
"wires": []
},
{
"id": "fb9ae3fd.f1628",
"type": "comment",
"z": "tab_bufparser_examples",
"name": "Convert [258,772,1286,1800,2314,2828,3342,3856] to a buffer only",
"info": "",
"x": 390,
"y": 820,
"wires": []
},
{
"id": "bb0683be.3011",
"type": "comment",
"z": "tab_bufparser_examples",
"name": "Convert an array or buffer to a buffer, do various swaps (sometimes multiple swaps), output only the buffer",
"info": "",
"x": 510,
"y": 940,
"wires": []
},
{
"id": "cf9b6d1e.3ebf",
"type": "inject",
"z": "tab_bufparser_examples",
"name": "an array",
"topic": "",
"payload": "[258,772,1286,1800,2314,2828,3342,3856]",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 250,
"y": 1360,
"wires": [
[
"d6bfcb3c.eedd08"
]
]
},
{
"id": "6978e83c.6100d8",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 740,
"y": 1360,
"wires": []
},
{
"id": "21a5c90f.6a98b6",
"type": "comment",
"z": "tab_bufparser_examples",
"name": "Dealing with BigInt. NOTE: At the time of writing, node-red debug node cannot handle BigInt.",
"info": "",
"x": 490,
"y": 1320,
"wires": []
},
{
"id": "d6bfcb3c.eedd08",
"type": "buffer-parser",
"z": "tab_bufparser_examples",
"name": "",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [
{
"type": "bigint64le",
"name": "bigint64le",
"offset": "0",
"length": "1",
"offsetbit": "0",
"mask": ""
},
{
"type": "bigint64be",
"name": "bigint64be",
"offset": "0",
"length": "1",
"offsetbit": "0",
"mask": ""
}
],
"swap1": "swap16",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "bigValues",
"msgPropertyType": "",
"resultType": "object",
"resultTypeType": "output",
"multipleResult": false,
"setTopic": true,
"x": 400,
"y": 1360,
"wires": [
[
"4d237375.24f27c"
]
]
},
{
"id": "4d237375.24f27c",
"type": "function",
"z": "tab_bufparser_examples",
"name": "Parse BigInts",
"func": "msg.payload = {\n bigint64le_string : msg.bigValues.bigint64le.value.toString(),\n bigint64le_number : Number(msg.bigValues.bigint64le.value),\n bigint64le_parseInt : parseInt(msg.bigValues.bigint64le.value),\n bigint64be_string : msg.bigValues.bigint64be.value.toString(),\n bigint64be_number : Number(msg.bigValues.bigint64be.value),\n bigint64be_parseInt : parseInt(msg.bigValues.bigint64be.value),\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 560,
"y": 1360,
"wires": [
[
"6978e83c.6100d8",
"9e4aba0c.0e5478"
]
]
},
{
"id": "9e4aba0c.0e5478",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "full object (this might throw error)",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 670,
"y": 1420,
"wires": []
},
{
"id": "459c1701.897c58",
"type": "inject",
"z": "tab_bufparser_examples",
"name": "Fake PLC data 16bit Array",
"topic": "1234 4321 9999",
"payload": "[4660,17185,39321]",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 280,
"y": 760,
"wires": [
[
"b9ebe3b6.8486e"
]
]
},
{
"id": "b9ebe3b6.8486e",
"type": "buffer-parser",
"z": "tab_bufparser_examples",
"name": "",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [
{
"type": "bcdbe",
"name": "bcdle",
"offset": "0",
"length": "3",
"offsetbit": "2",
"mask": ""
},
{
"type": "bcdle",
"name": "bcdbe",
"offset": "0",
"length": "3",
"offsetbit": "0",
"mask": ""
},
{
"type": "bcdbe",
"name": "3bcd",
"offset": "0",
"length": "3",
"offsetbit": "0",
"mask": "0x0FFF"
}
],
"swap1": "",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "payload",
"msgPropertyType": "",
"resultType": "value",
"resultTypeType": "output",
"multipleResult": true,
"setTopic": true,
"x": 500,
"y": 760,
"wires": [
[
"511aab5b.892944"
]
]
},
{
"id": "511aab5b.892944",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 740,
"y": 760,
"wires": []
},
{
"id": "576ed17f.e86d2",
"type": "comment",
"z": "tab_bufparser_examples",
"name": "BCD values [4660,17185,39321] (0x1234 0x4321 0x9999) to decimal equivelant (1234 4321 9999)",
"info": "",
"x": 490,
"y": 720,
"wires": []
},
{
"id": "791a95ae.26555c",
"type": "buffer-maker",
"z": "tab_bufparser_examples",
"name": "",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [
{
"name": "item1",
"type": "ascii",
"length": 8,
"dataType": "str",
"data": "abcdefgh"
},
{
"name": "item2",
"type": "uint16le",
"length": 1,
"dataType": "msg",
"data": "payload.anumber"
},
{
"name": "item3",
"type": "uint16le",
"length": 1,
"dataType": "msg",
"data": "payload.anarray"
},
{
"name": "item4",
"type": "biguint64le",
"length": 1,
"dataType": "str",
"data": "123456"
},
{
"name": "item5",
"type": "8bit",
"length": 1,
"dataType": "msg",
"data": "payload.a8bit"
},
{
"name": "item6",
"type": "16bitle",
"length": 1,
"dataType": "msg",
"data": "payload.a16bit"
},
{
"name": "item7",
"type": "bool",
"length": 1,
"dataType": "msg",
"data": "payload.bools"
},
{
"name": "bcd1",
"type": "bcdle",
"length": 2,
"dataType": "jsonata",
"data": "[1234,2345]"
},
{
"name": "bcd2",
"type": "bcdbe",
"length": 1,
"dataType": "num",
"data": "5678"
},
{
"name": "item8",
"type": "hex",
"length": -1,
"dataType": "msg",
"data": "payload.hexstring"
}
],
"swap1": "swap16",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "payload",
"msgPropertyType": "str",
"x": 280,
"y": 2500,
"wires": [
[
"fe3067d4.300288",
"a08cf05c.aea2"
]
]
},
{
"id": "ca252362.2b25d",
"type": "inject",
"z": "tab_bufparser_examples",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
},
{
"p": "spec",
"v": "{\"options\":{\"byteSwap\":[\"swap16\"],\"msgProperty\":\"payload\"},\"items\":[{\"name\":\"item1\",\"type\":\"ascii\",\"length\":8,\"dataType\":\"str\",\"data\":\"abcdefgh\",\"value\":\"abcdefgh\"},{\"name\":\"item2\",\"type\":\"uint16le\",\"length\":1,\"dataType\":\"msg\",\"data\":\"payload.anumber\",\"value\":123},{\"name\":\"item3\",\"type\":\"uint16le\",\"length\":1,\"dataType\":\"msg\",\"data\":\"payload.anarray\"},{\"name\":\"item4\",\"type\":\"biguint64le\",\"length\":1,\"dataType\":\"str\",\"data\":\"123456\"},{\"name\":\"item5\",\"type\":\"8bit\",\"length\":1,\"dataType\":\"msg\",\"data\":\"payload.a8bit\"},{\"name\":\"item6\",\"type\":\"16bitle\",\"length\":1,\"dataType\":\"msg\",\"data\":\"payload.a16bit\"},{\"name\":\"item7\",\"type\":\"bool\",\"length\":1,\"dataType\":\"msg\",\"data\":\"payload.bools\"},{\"name\":\"item8\",\"type\":\"hex\",\"length\":-1,\"dataType\":\"msg\",\"data\":\"payload.hexstring\"}]}",
"vt": "json"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"astring\":\"hello\",\"anumber\":123,\"anarray\":[1,2,3,4,5,6,7,8,9,10],\"a8bit\":[[1,1,1,0,0,0,1,0]],\"a16bit\":[[true,true,true,0,0,0,1,0,0,0,0,1,1,1,0,1]],\"bools\":[1,0,0,1,false,false,true,true],\"hexstring\":\"0102030405060708\"}",
"payloadType": "json",
"x": 100,
"y": 2500,
"wires": [
[
"791a95ae.26555c",
"bd497a1e.4aff58"
]
]
},
{
"id": "fe3067d4.300288",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 380,
"y": 2560,
"wires": []
},
{
"id": "a08cf05c.aea2",
"type": "buffer-parser",
"z": "tab_bufparser_examples",
"name": "",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [
{
"type": "string",
"name": "item1",
"offset": 0,
"length": 8,
"offsetbit": 0,
"scale": 1,
"mask": ""
},
{
"type": "int16le",
"name": "item2",
"offset": 8,
"length": 1,
"offsetbit": 0,
"scale": 1,
"mask": ""
},
{
"type": "int16le",
"name": "item3",
"offset": 10,
"length": 1,
"offsetbit": 0,
"scale": 1,
"mask": ""
},
{
"type": "biguint64le",
"name": "item4",
"offset": 12,
"length": 1,
"offsetbit": 0,
"scale": 1,
"mask": ""
},
{
"type": "8bit",
"name": "item5",
"offset": 20,
"length": 1,
"offsetbit": 0,
"scale": 1,
"mask": ""
},
{
"type": "16bitle",
"name": "item6",
"offset": 21,
"length": 1,
"offsetbit": 0,
"scale": 1,
"mask": ""
},
{
"type": "bool",
"name": "item7",
"offset": 23,
"length": 8,
"offsetbit": 0,
"scale": 1,
"mask": ""
},
{
"type": "bcdle",
"name": "bcd1",
"offset": 24,
"length": 2,
"offsetbit": 8,
"scale": 1,
"mask": ""
},
{
"type": "bcdbe",
"name": "bcd2",
"offset": 28,
"length": 1,
"offsetbit": 8,
"scale": 1,
"mask": ""
},
{
"type": "hex",
"name": "item8",
"offset": 29,
"length": -1,
"offsetbit": 8,
"scale": 1,
"mask": ""
}
],
"swap1": "swap16",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "payload",
"msgPropertyType": "str",
"resultType": "keyvalue",
"resultTypeType": "output",
"multipleResult": false,
"setTopic": true,
"x": 520,
"y": 2500,
"wires": [
[
"64289929.b60d78"
]
]
},
{
"id": "64289929.b60d78",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 640,
"y": 2560,
"wires": []
},
{
"id": "bd497a1e.4aff58",
"type": "buffer-maker",
"z": "tab_bufparser_examples",
"name": "",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "msg",
"items": [
{
"name": "item1",
"type": "ascii",
"length": 8,
"dataType": "str",
"data": "abcdefgh"
},
{
"name": "item2",
"type": "uint16le",
"length": 1,
"dataType": "msg",
"data": "payload.anumber"
},
{
"name": "item3",
"type": "uint16le",
"length": 1,
"dataType": "msg",
"data": "payload.anarray"
},
{
"name": "item4",
"type": "biguint64le",
"length": 1,
"dataType": "str",
"data": "123456"
},
{
"name": "item5",
"type": "8bit",
"length": 1,
"dataType": "msg",
"data": "payload.a8bit"
},
{
"name": "item6",
"type": "16bitle",
"length": 1,
"dataType": "msg",
"data": "payload.a16bit"
},
{
"name": "item7",
"type": "bool",
"length": 1,
"dataType": "msg",
"data": "payload.bools"
}
],
"swap1": "swap16",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "payload",
"msgPropertyType": "str",
"x": 280,
"y": 2660,
"wires": [
[
"fd9977f7.520068",
"f32e8db7.9554a"
]
]
},
{
"id": "fd9977f7.520068",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 350,
"y": 2720,
"wires": []
},
{
"id": "f32e8db7.9554a",
"type": "buffer-parser",
"z": "tab_bufparser_examples",
"name": "",
"data": "payload",
"dataType": "msg",
"specification": "spec",
"specificationType": "ui",
"items": [
{
"type": "string",
"name": "item1",
"offset": 0,
"length": 8,
"offsetbit": 0,
"scale": 1,
"mask": ""
},
{
"type": "int16le",
"name": "item2",
"offset": 8,
"length": 1,
"offsetbit": 0,
"scale": 1,
"mask": ""
},
{
"type": "int16le",
"name": "item3",
"offset": 10,
"length": 1,
"offsetbit": 0,
"scale": 1,
"mask": ""
},
{
"type": "biguint64le",
"name": "item4",
"offset": 12,
"length": 1,
"offsetbit": 0,
"scale": 1,
"mask": ""
},
{
"type": "8bit",
"name": "item5",
"offset": 20,
"length": 1,
"offsetbit": 0,
"scale": 1,
"mask": ""
},
{
"type": "16bitle",
"name": "item6",
"offset": 21,
"length": 1,
"offsetbit": 0,
"scale": 1,
"mask": ""
},
{
"type": "bool",
"name": "item7",
"offset": 23,
"length": 8,
"offsetbit": 0,
"scale": 1,
"mask": ""
},
{
"type": "hex",
"name": "item8",
"offset": 24,
"length": -1,
"offsetbit": 8,
"scale": 1,
"mask": ""
}
],
"swap1": "swap16",
"swap2": "",
"swap3": "",
"swap1Type": "swap",
"swap2Type": "swap",
"swap3Type": "swap",
"msgProperty": "payload",
"msgPropertyType": "str",
"resultType": "keyvalue",
"resultTypeType": "output",
"multipleResult": false,
"setTopic": true,
"x": 520,
"y": 2660,
"wires": [
[
"d1a9924.18b1e7"
]
]
},
{
"id": "d1a9924.18b1e7",
"type": "debug",
"z": "tab_bufparser_examples",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 650,
"y": 2720,
"wires": []
},
{
"id": "89881af3.d907c8",
"type": "comment",
"z": "tab_bufparser_examples",
"name": "Convert values to a buffer then back again (UI Spec)",
"info": "",
"x": 400,
"y": 2460,
"wires": []
},
{
"id": "213d42e.e087cbe",
"type": "comment",
"z": "tab_bufparser_examples",
"name": "Convert values to a buffer then back again (msg.spec)",
"info": "",
"x": 410,
"y": 2620,
"wires": []
}
]