I have a question about buffers

flows (8).json (41.2 KB)

I have a question about buffers.
Flow has been uploaded.
The sequence is as follows.

  1. A random buffer was injected into the injection.


  1. Create the first buf1 rule in the function.

var buf1=Buffer.alloc(msg.payload[5]*2+3);

  1. Create a second buf1 in the function.

var buf2=Buffer.alloc(320);

  1. In the rule of buf1, the data of buffer 2 is inserted from the point payload[3].


  1. At this length, the length refers to buf1[2] of buf1.

  2. The generated payload looks like this:


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:

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 .

Buffer Parser was made for this type of task for converting bytes into nicely named values (int, INT32, UINT32, float, string, big endian, little endian, etc).

I tried, but it doesn't come out.
buffer [1,3,0,101,0,5]


Can the data come out?

  1. Show me (in a screenshot) the value coming out of the modbus node

  2. put a debug on the output of modbus node (set debug node to show complete message) then use the copy value button that appears under your mouse pointer when you hover over the message

  3. Explain what the bytes mean e.g.

    • bytes 0+1 are a UINT16 (voltage)
    • bytes 2+3 are a UINT16 (current)
    • byte 4 is 8 boolean flags
    • byte 5 is an 8bit int (status code)
    • etc
    • etc

PS, if you dont reply directly to my message I wont get a notification (use the reply button on my message not the reply button at the bottom of the page)

I solved the problem. I made a code fix in the function node. Thank you.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.