LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

TCP Connection as Global Variable

I am having problems with using the same TCP connection among different programs.  Essentially I have a main program that opens the connection and I share the connection ID as a global variable.  This is to facilitate various sub-procedures that will need to send data over this connection (one at a time).  To help illustrate this, the main program is the top layer (layer one), and the sub-program (layer two) which uses the connection to communicate with the final simulation layer (layer three).

The problem is that it appears to matter where this connection is initialized.  That is, if I do it in the main program, and call the global variable from the sub-program, then it doesn't work (properly). However, if the same code is moved in the sub-program, and the global variable is called within the same sub-program, then all works wonderfully. 

This leads me to believe that it is not a matter of the global variable.  I'll post the connection code.  Any advice/ideas would be appreciated.
0 Kudos
Message 1 of 3
(2,696 Views)
Hi Pjama:

Why don't you use TCP connection as a normal i/o variable and add TCP conn input and TCP conn output to SubVIs?

If Global variable is completely necesary, then try to delete output indicator (so that TCP Connect's output ends only in the global variable)

May be, your SubVI takes global variable's value before TCP Connect updates it.

If you have TCP close, make sure it doesn't close connection while you need the value

Hope it helps,
Aitortxo.
0 Kudos
Message 2 of 3
(2,687 Views)
Yes, connecting a connection ID wire to the sub-VI was one of the options I thought about earlier.  I had merely forgot about it amidst my frustration.

This does appear to work, however it should work exactly the same with global variables (?). 

I don't think it's a timing matter because it would generate an error if the sub-VI was trying to send to a non-existent connection.  What it does is sends one message, but I am trying to run a loop of communications between the VI's (levels two and three).

It's not critical for this to work since the third-level VI is just simulating another program.  But I am curious about this problem because it leads me to somewhat doubt global variables.

Thanks for your help.

-Philip
0 Kudos
Message 3 of 3
(2,676 Views)