LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Concatenate inputs into array and send by UDP

Hi all,

 

This is the description of the problem I am trying to solve:

  • My model has several inputs, and each of them is a byte (signed int8).
  • I need to concatenate them into a string and send it by UDP.
  • Since the number of inputs is around 2,000, building the array by connecting inputs "one by one" seems not the right approach (first .jpg).

Could the "Cluster to Array" block do the job (second .jpg)?

 

Is there a better way?

 

Thanks in advance

One_by_oneOne_by_oneCluster_To_ArrayCluster_To_Array

0 Kudos
Message 1 of 10
(5,690 Views)

Hi milliken,

 

This is the description of the problem I am trying to solve:

My model has several inputs, and each of them is a byte (signed int8).

In your image you use orange wires, denoting float values, but in your description you are talking about I8 values. What exactly do you use?

 

Could the "Cluster to Array" block do the job (second .jpg)?

Well, yes.

Do you really have 2000 scalar values inside this cluster? (Is there no way to organize your data in arrays or subclusters?)

 

Btw. there often is a size limit for UDP messages, LabVIEW uses 548 bytes by default. Such a message could contain ~512 bytes of "payload data" (I tend to include some additional header/checksum data in such messages). Or you could transport 128 SGL or 64 DBL values in an UDP message of the same size…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 10
(5,686 Views)

Thanks GerdW for the quick response (and sorry for my late reply).

 

Since I am only receiving this data via UDP, I will contact the guy responsible for sending it, in order to explore the option of a more efficient way of transmission.

 

Following your advice, I changed the representation of the data in the cluster from double (orange) to int8 (blue).

 

I will keep everyone posted if we manage to find a solution that works and looks clean.

 

Cheers

0 Kudos
Message 3 of 10
(5,628 Views)

If you were truly sending integers as doubles, sending them as I8 would shrink your data size by what, 8x?  (Assuming your values fit into an I8.)

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 10
(5,603 Views)

I have made use of the UDP sender example from LabView, trying to replicate the same behaviour as in Simulink (which works).

Basically, concatenating 3x unit32 and 6x double into a boolean array and sending it via UDP.

In Simulink, I use the "Byte packing" block (which transforms from either uint32 or double into boolean), use a "Mux" block to concatenate the booleans, and send it via UDP.

In Labview, I try to convert each "Number to boolean array", feed them into a cluster, flatten it into a string and send it via UDP.

 

Any ideas?

 

PS. The fact that the 3x unit32 are fed with the same number (same as the 6x double) is to save wiring time 🙂

 

 

0 Kudos
Message 5 of 10
(5,561 Views)

Hi Miiliken,

 

Basically, concatenating 3x unit32 and 6x double into a boolean array and sending it via UDP.

Why do you want to convert typecast into a boolean array? Why not typecast into byte array or string?

 

In Labview, I try to convert each "Number to boolean array", feed them into a cluster, flatten it into a string and send it via UDP.

This conversion is bu**sh** nonsense… 😄

Try this:

check.png

Adapt as needed…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 10
(5,551 Views)

Personally, I would just put the numbers themselves into a cluster, flatten that, and send.

 

And if Matlab is involved, I am pretty sure you need to set to Little Endian.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 10
(5,540 Views)

I managed to make use of the example template provided by LabView for UDP (Sender, Receiver) to make it work.

 

I think the main difference between LabView and Simulink is (please correct me if I am wrong):

- Labview sends a STRING via UDP

- Simulink sends an ARRAY OF BYTES via UDP

This actually now puts the focus on the other piece of software which receives the UDP and must interpret what is beind sent.

 

I will try to make use of Wireshark today and show that in fact the UDP contents are not the same in Labview and Simulink cases. I will keep you posted.

0 Kudos
Message 8 of 10
(5,514 Views)

Hi Milliken,

 

Labview sends a STRING via UDP

Simulink sends an ARRAY OF BYTES via UDP

And what is the difference between a string and an array uf U8 - in LabVIEW terms?

(Please keep in mind the two functions StringToByteArray and ByteArrayToString…)

 

You can create the same byte array in LabVIEW as you do in Simulink. When they are not the same (although you use the same source data) then YOU made something wrong…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 10
(5,510 Views)

Milliken wrote:

I think the main difference between LabView and Simulink is (please correct me if I am wrong):

- Labview sends a STRING via UDP

- Simulink sends an ARRAY OF BYTES via UDP


Array of U8 and a string actually have the exact same structure.  So that should not be an issue.  The issues I have ran into are with the Endianness of the data.  LabVIEW defaults to Big Endian while Matlab uses Little Endian.  You can set that with the Flatten To String.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 10
(5,501 Views)