LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do i send an array of clusters with variable size over TCP/IP?

Hi,

        I'm trying to send an array of clusters with varible size over TCP/IP,. But I'm facing the following problems:

 

1) I need to accept the size of array data from the user and increase the size dynamically.

I'm doing this using the property node but how do I convey the new size to my TCP read?

2) I need to wire an input to my 'bytes to read' of the TCP read.

But the number of bytes to read changes dynamically

How do I ensure  the correct number of bytes are read and reflected on the client side?

3) Is there anyway I can use global varibles over a network such that their values are updated just as if they would on one computer?

 Will be a great help if someone posts a solution!

Thank you...

0 Kudos
Message 1 of 10
(6,486 Views)
I'm not sure if I understand exactly what you are trying to do, but have you looked into LabVIEW's "network enabled" shared variable? These only became available in the 8.x versions and newer.
Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 2 of 10
(6,476 Views)

twilightfan wrote: 

2) I need to wire an input to my 'bytes to read' of the TCP read.

But the number of bytes to read changes dynamically

How do I ensure  the correct number of bytes are read and reflected on the client side?


 

 

 

It's exactly the same as we discussed earlier: Simply prepend the data size as descibed in the link to make the actual size part of the message.

 

In this case you would flatten from (and then unflatten to) an array of clusters. Everything remains the same, except the data type.

 


twilightfan wrote:

I'm doing this using the property node but how do I convey the new size to my TCP read?


 

 

I don't understand why you use a property node. Makes no sense. If the user is allowed to select an array size, wouldn't it be a control instead?

You also cannot increase an array size with a property node, you would use plain array data operations instead. (You could use a property node to increase the size of the array container for example, but that does not change the array size). 😉

 

 

(It really depends on what you are trying to do. As Putnam mentioned, a network shared variable for the array of clusters might be an alternative to the entire thing.) 

 

 

 

0 Kudos
Message 3 of 10
(6,468 Views)

Hi,

      Using shared variables is the first thing I tried after trying to use global variables. But I could not figure out how to connect the variables in my program  to the ones on the other computer. I did select the network published option and added their libraries to my projects. Is there any other configuration I have to make in order to  ensure that my shared variables reflect the data correctly? I'm using 1 instance of a shared variable in the server to read the number of bytes and another instance of it to write it to TCP read in the client.I have similarly employed a second shared variable to send the bytes to read on the server side. Also, I have a third shared variable that reads the input from the user and gives the data to the property node "number of columns" of the array of clusters on both the input and the output side so that the array size changes accordingly.

How do I configure the shared variables to respond to certain IP addresses i.e. those of the client? 

Thanks..

0 Kudos
Message 4 of 10
(6,454 Views)

Altenbach,

               The first thing I tried was the solution you had earlier given me. But I recieve error 74 when I try using it

with unflatten from string and error 1105 when I try to use unflatten from xml string. Also, the type constant

I need to wire to the type input of both these nodes is creating a problem as it is no longer a constant.i.e. since i'm accepting user input for my array size [esp. number of columns that I'm varying using property node so as to

dynamically create more elements in the array] is variable. But I solved these problems by using a local variable as the type input and an error handler for the unflatten from string/ xml string nodes. Still, conveying the size info to TCP read is creating a problem.

In the VI you had attached earlier, when I use TCP read twice, the second TCP read gets truncated data because

its no longer just the first four bytes that specify the length of the data, it could be more as my array of cluster

can be pretty huge. I'm kind of stuck at this..unable to figure out a few details about shared variable nodes as well!

 (as mentioned above) would be a great help if you could attach an example for either solution. I'm using the

same io clusters as before but now they are present in an array each.

Thanks..

0 Kudos
Message 5 of 10
(6,450 Views)

twilightfan wrote:

Altenbach,

 ... xml string. ...number of columns that I'm varying using property node s... I solved these problems by using a local variable as the type input ...o TCP read is creating a problem.... second TCP read gets truncated data because

its no longer just the first four bytes that specify the length of the data, it could be more as my array of cluster can be pretty huge.


 

 
Instead of writing long and complicated sentences that make little sense, why don't you simply show us your code? 
 
What does any of this have to do with xml strings???? I don't see how using a local variable as type input changes anything. The user cannot interact with "property nodes", just with controls. Please clarify. Once the array of clusters is flattened to a string you only have one size that describes the size of the data, no matter how huge it is (as long as it is within the limits of I32). Similarly, you read the string of that same defined length and form the array of clusters from it. How big are the strings? What is your definition of "huge"?
 
Here's is my earlier code, but now dealing with an array of clusters. Not much of a change. Since you have columns, you want 2D. Add as many diensions you want, but make sure that the control, diagram constant, and indicator all match.
 
The snipped shows for a 1D array, while the attached VI shows the same for a 2D array. Same difference. 😉 
 
 
Message Edited by altenbach on 01-31-2010 01:13 AM
Download All
0 Kudos
Message 6 of 10
(6,431 Views)
here's the same VI with better defaults.
0 Kudos
Message 7 of 10
(6,427 Views)

Altenbach,

 I have attached a sample VI. As you can see in this VI, there are 3 variables I need to share in a TCP/IP connection
1) The 'number of columns' variable (same for both input and output side)
2) The size of string sent from server to notify TCP read on client side
3) The size of the string sent from client to notify the TCP read on the server side.

 

Do try flattening/unflattening the string using actual TCP read and write nodes for the localhost, you will recieve error 74.

Thanks ..

0 Kudos
Message 8 of 10
(6,419 Views)

As to your question regarding how big the strings are, as you will clearly see in my VI,

I have no clue until the user types in the input!

0 Kudos
Message 9 of 10
(6,418 Views)

The "numcols" property has nothing to do with the size of the 2D array, it simply defines how many columns are visible on the front panel at the same time. It does not change the data size!

 

If you always want to show all columns, just get the dimension from the array size after unflattening, no need to send the information. If you want to display a different number of columns compared to the actual number of columns in the 2D array, you could prepend that number similar to what we currently do with the size. On the receiving side you would first read the size, read the remaining string, then split the remaining string at byte 4 into the substring for numcols and the cluster before unflattening each.

 

If you get TCP errors, please attach your actual TCP code so we can see what you are doing.

 

The attached modification shows how to always display all columns contained in the data. Of course don't overdo this, e.g. don't try to display millions of columns. 😉

 

 

0 Kudos
Message 10 of 10
(6,402 Views)