flows (8).json (41.2 KB)
I have a question about buffers.
Flow has been uploaded.
The sequence is as follows.
- A random buffer was injected into the injection.
[1,3,0,101,0,5]
- Create the first buf1 rule in the function.
var buf1=Buffer.alloc(msg.payload[5]*2+3);
buf1[0]=msg.payload[0];
buf1[1]=msg.payload[1];
buf1[2]=msg.payload[5]*2;
- Create a second buf1 in the function.
var buf2=Buffer.alloc(320);
buf2[100]=1;
buf2[103]=2;
buf2[113]=12;
buf2[115]=14;
buf2[117]=16;
buf2[118]=17;
- In the rule of buf1, the data of buffer 2 is inserted from the point payload[3].
buf2.copy(buf1,3,100,139);
-
At this length, the length refers to buf1[2] of buf1.
-
The generated payload looks like this:
[1,3,10,1,0,0,2,0,0,0,0,0,0]
01 03 0A 01 00 00 02 00 00 00 00 00 00
But this buffer is not what I want.
The buffer I want is:
[1,3,10,0,1,0,0,0,0,0,2,0,0]
01 03 0A 00 01 00 00 00 00 00 02 00 00
That is, it seems to split 01 from payload[3] into 00 01 form.
May I know how to do this?
For reference, this is a Modbus RTU serial method.
It must be expressed as Uint16 .