LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

global variables help

Hi, I have a few problems with globals. Basically i need my program below, to take values from sub vi(within sub vi) on first program diagram and supply these values to first diagram to be displayed as a graph. The reason for the sub vi is that it needs to be independent of the first program due to it starting when i tell it to. I am using globals for this and if u have a look at the program u will see what i am trying to do with the globals. Currently the data the globals supply is not reaching my graph. Any help much appreciated. Also it uses field point and the program first u look at is loop 1.

Thanks Stuart
0 Kudos
Message 1 of 8
(3,332 Views)
Hi Stuart,
I had a couple of problems opening your .llb - looks like there's a couple of sub .vi's missing, but I think I got the point - you're using loop1withsubvi.vi to fire off the sub.vi - loop222.vi, but although this is updating the global variables, the graph in the main.vi is being fed the information once only, with no control (determinism) on when this will happen.
I'd make four suggestions.
1. you can have one global.vi with multiple controls on it, rather than multiple global.vi's with one control on each - this makes managing files a lot easier.
2. put the graphing information into the program flow so it occurs after the sub.vi has run (i.e. in the same case statement, possibly needing to use a sequence frame to make sure that the graph is upda
ted after the data is updated.
3. Try playing around with control references so you can remove the need for the globals. You can create a control reference to the graph, and pass this to the sub.vi (that way the sub.vi can still be generic and launched to run simultaneously with the top level .vi) The sub.vi can then pass data to the main.vi.
4. Simply pass the data directly back to the graph from the sub.vi - looking at what you seem to be trying to acheive, you can call the sub.vi in the case statement as you are doing now, and the sub.vi has to complete anyway before updating the graph, so you can put the graph FPTerm in the case statement anyway - you're not passing anything additional to the graph from the looks of things.

Hope that helps and I got the right file!

S.
// it takes almost no time to rate an answer Smiley Wink
Message 2 of 8
(3,332 Views)
Stuart,

Instead of using global variables or control references (which have the same problems as globals, primarily race conditions), I strongly suggest that you use a data storage VI (which I now believe is equivalent to (don't be scared now...) an Object (as in object oriented programming.)

This is the same scope as a global variable, but as it is by default, non reentrant, you can have better control of the data.

Here is a link to a thread containing (last entry as of this moment) a template for a data storage VI. Interestingly enough, as I hear, this was how global variables were implemented as of LabVIEW 2.x.

Take a look and see what you think. I almost never use Globals anymore. In the case of configuration values (the only real need
I ever saw for globals), the first example in the thread is a solution for this. Data is stored in a file (ini file), and then retrieved and stored by this VI. Retrieval of the data is simple, and modification can be done with this VI as well.
Message 3 of 8
(3,332 Views)
Hope this helps

tc phan
0 Kudos
Message 4 of 8
(3,332 Views)
the following works better

tc phan
0 Kudos
Message 5 of 8
(3,332 Views)
Hi, thanks for your answer. You did say there would be a link to a thread, be much apprecated if u sent it to me.

Thanks stuart
0 Kudos
Message 6 of 8
(3,332 Views)
Thanks for your help, but i should have said" I'm only using labview 6.02 at the moment. But thanks anyway.
0 Kudos
Message 7 of 8
(3,332 Views)
http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=206&HUSERSHADE=0&HOID=50650000001100000030020000&HCHOSEN=506500000012000000BB040000&HTHREAD=000001211&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0

Sorry about that, I thought I added it in a comment, guess it didn't show up for some reason, such as I forgot to hit the right button for example...
0 Kudos
Message 8 of 8
(3,332 Views)