LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I'm using a 1D Arrary with 27 different elements and would like to send those data over UDP Write and UDP Read functions.

I'm using a 1D array with 27 different elements. I would like to transfer that data over a UDP connection, and read it back by using UDP connections.
But I would like to read 3 elements at a time (On read side) and send those to 9 different ports.

Note: the data will go to only one PC with one Network Address)

* 1st elements (0,1,2) and send to port #XXX to see those 1st 3 elements.
* continue until the elements reaches up to 27

This is what I have done but I'm finding myself in pitfalls...

Send side:
I'm using a UDP Open connection on send side to send my data. So with selected a Source Port, I have created a UDP Op
en connection. I�m using only one source port to send all the data across the channel. I would like to read 1st 3 elements and send those data across with an assigned Destination port. I would like to do that for 9 times b/c there are 27 elements in the array. So I�m using a For Loop and setting N count to 9. So I�m not getting any errors when I execute and no answer on the other side at all.

Read side:

I�m using a UDP Open connection to read in the data with port #. I�m using while loop to with Boolean inside by making a true all the time. Inside that While loop, I�m using For Loop to read the 3 elements data a time and send to a right port address. (As start out I was just trying to see if it works for only one port).
Download All
0 Kudos
Message 1 of 10
(3,506 Views)
You are not getting any errors because UDP is a connectionless protocol. It does not care if anyone receives it. Your example will work fine with the following considerations.

(1) Don't use the generic broadcast address (255.255.255.255).

(2) You are listening on port 30000. So why are you sending to port 1502, nobody will receive anything there.
The destination port of the outgoing connection must match the server port of the listener. (The source port is irrelevant, set ot to zero and the system will use a free ephemeral port).

(3) On the receiving side, you are not indexing on the received string, thus you only retain the last received element. Then you place the indicator outside the while loop where it never gets updated. 😞


(4) Do yourself a favor and don't micromanage how the data is sent across. Just take the entire array, flatten it to string, send it across, receive it, unflatten back to array, and get on with the task.
(You can do the same with any kind of data).

I have modified your VI with some reasonable default values (destination IP = 127.0.0.1 (localhost)), thus you can run both on the same PC for testing "as is". Just run the "read" first, then every time you run "send", new data will be received.
Download All
Message 2 of 10
(3,506 Views)
Thanks,
I do not understand the Type under Unflatten From String? Can u explain this?

Thanks
0 Kudos
Message 3 of 10
(3,506 Views)
For "type", you need to wire the same data type that you used for "flatten to string", in this case an array of strings. If you had flattened a string of DBL numbers, you would wire an empty DBL array, etc. Since flatten turns everything into a string, you need to tell LabVIEW what kind of data it was so it can be converted back to the correct data type.

Some possibilities are shown in the attached image that I posted a while ago in a different context. Let me know of this helps.
0 Kudos
Message 4 of 10
(3,506 Views)
Yes, it is now more clear. Thanks...
Also, how would I extract the elements out of the arrary? I would like to extract 3 elements out at each time until they finished and send to a different arrary that display 3 elements at a time?

So far, I have been playing around with Spliting the arrarys but its not getting anywhere.

Any idea?

Thanks for your time,
0 Kudos
Message 5 of 10
(3,506 Views)
Sorry, your description is not clear to me. Could you clarify a little bit what you want to do?

What is the meaning of "each time"? Do you want to extract only 3 elements out of the 27? Do you want to display 3 at a time, first #0-2, then #3-5, and so on? What determines the timing between updates in this case? Should the new triplet overwrite the previously displayed three elements? Do you want to generate a 2D array (size 3x9)? Something else?

Thanks.
0 Kudos
Message 6 of 10
(3,506 Views)
Ohh ok. That is not a problem. I tend to have tunnel vision and can not describe my description correctly.

Ok, I have a 1D-Arrary with 27 elements and would like to extract 3 elements at each time. By means, 1st time= 0-2 elements, 2nd time = 3-5 and soo on up to end of the array (27). Now as for timing. I am not sure. If I can do it all at sametime than its fine or I can just add a timier and wait few some time.

Thanks,
0 Kudos
Message 7 of 10
(3,506 Views)
I mean that each 3 elements will go to a different array for display purpose. 9 different array would display the 3 elements each.
0 Kudos
Message 8 of 10
(3,506 Views)
Here is an example to get three elements at a time from a 27 element array. You simply reshape it into a 3x9 array and use autoindexing to get a slice with three at each loop iteration.
0 Kudos
Message 9 of 10
(3,506 Views)
Yes, this helps a lot.
Thanks,
0 Kudos
Message 10 of 10
(3,506 Views)