LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

TCP network connection refnum

Is it possible to pass a TCP refnum by means of a global.
I have a "open vi" and a "write vi". In "open vi" I do a TCP open connection and put the refnum in a global.
I use this global in "write vi" for the refnum input of the TCP write.
This gives me an error 1. Why isn't this possible?
Please help me.Smiley Sad
0 Kudos
Message 1 of 2
(2,800 Views)

It is possible, it's just not a smart thing to do, because a refnum will only be valid from the time you open it to the time you close it (or stop the top level VI).
If the Write TCP VI runs before the Open does, the refnum does not have any value and is meaningless. That is known as a race condition and is very easy to get to if you're using globals.
If you call the Open VI to get the refnum and then seperately call the Write VI, the refnum will again be meaningless even though you have a number because when the VI calling the Open VI stopped the connection was dropped.

There are 2 ways to do this:

  1. The safe way - use a wire to pass the refnum between the functions. Open at the beginning and close at the end. Makes it easier to read, but forces you to have the wire.
  2. The harder way. You can use what's known as a functional global (or LV2 style global) to manage your connection. This method is more complex and will require you to handle different kinds of cases, so I wouldn't recommend it unless you know what you're doing. You can search this site for these terms to find more information.

You should think about whether you really need the refnum in a global. I find it best to place all my TCP communication in a single place and to bring the necessary data to that location. Then, you get less surprises.

To learn more about LabVIEW, I suggest you try searching this site and google for LabVIEW tutorials. Here and here are a couple you can start with. You can also contact your local NI office and join one of their courses.
In addition, I suggest you read the LabVIEW style guide and the LabVIEW user manual (Help>>Search the LabVIEW Bookshelf).

 

___________________
Try to take over the world!
Message 2 of 2
(2,793 Views)