How to concatenate arrays

#1

Hi,
How i can to concatenate 2 or 3 output(array 1D) of Modbus TCP client node in one array(1D) ?
example : Modbus1 => msg.payload => [ 0, 0, 76, 71, 13 ] and
Modbus2 => msg.payload => [ 5, 2, 5, 54, 21 ]
Modbus3 => msg.payload => [ 9, 9, 9, 9, 9 ]
i want to find in ouput msg.modbus [ 0, 0, 76, 71, 13, 5, 2, 5, 54, 21,9, 9, 9, 9, 9].

And how i can to change the output name of my modbustcpip, instead of having msg.payload i search to have msg.(Mytitle).

Thank you for your help.

0 Likes

#2

Googling for
javascript concatenate arrays
gives
https://www.w3schools.com/jsref/jsref_concat_array.asp

Sorry, I don’t understand your second question

0 Likes

#3

Thank you for your answer, but how can do it in my function if i have two output of my ModbusTcpip1 and ModbusTcpip1 than who have the same name(msg.payload)?
This is my secend question.

0 Likes

#4

Do you mean the arrays are coming in on separate messages? If so then you can use the Join node in Manual mode to combine the two message payloads into a single message containing a key/value object and then you can combine the arrays.

0 Likes

#5

Sans%20titre
that's what I want do
I'm sorry, I can't explain well because I'm a beginner on node-red
thank you Colin for your help (y) (y)

0 Likes

#6

Most nodes will expect the “valuable” data to be in msg.payload so changing it to msg.somethingelse may cause you problems.

But you can use a change node to move data from one place to another.

If your work is Urgent, as per the title, its probably not the best time to use a tool you are a beginner with.

0 Likes

#7

Thank you ukmoose for your answer
Sans%20titre
but the only way to concatenate the two arrays, it to change the name of the output of each mosbus to integrate them into function (how can I distinguish between the two output in function, they have the same name "msg.payload"?)
I hope you have understood my problem.
thank you

0 Likes

#8

You could try the suggestion @Colin suggested above Urgent : Modbus tcp/ip array!

0 Likes

#9

You can add a change node between the Mod bus to node and the array function node
and set e.g. msg.topic=1, the same for the ReadModBUSLabview > msg.topic=2

In your array function first check the msg.topic:

If (msg.topic === 1) {
  // ...
} else if (msg.topic === 2) {
  // ...
}
0 Likes

#10

Are all these messages coming from one node or from different nodes?
Also do they have different topics?

0 Likes

#11

This is exactly what I was looking for, I did not make the difference between the topic and the playload for each node , I think with this method I can do what I want

0 Likes

#12

messages coming from different nodes in array forms and they have different topics.

Thank youu

0 Likes

#13

In that case you can do what I originally suggested, using a Join node to give you a key/value object with all the payloads with individual keys.

0 Likes

#14

Perfect my problem is solved, Thank you Colin,

0 Likes