07-27-2011 04:35 PM
I am trying to run two VIs under the same block diagram. How do I connect the two while loops so I can create a global variable?
Thanks.
-Sicelo
07-27-2011 04:37 PM
@Sicelo wrote:
I am trying to run two VIs under the same block diagram. How do I connect the two while loops so I can create a global variable?
Your question makes no sense. What do while loops and global variable have to do with running two VIs?
Show us some code to aid our imagination. Thanks!
07-27-2011 05:07 PM
If I understand you correctly you have two subvis which each have a loop. You want to send data between them. Is that correct?
If so you can use a FGV which is a type of Action Engine. Or just a global variable but that is the lazy way and can lead to issues in all but the simplest uses. Queues and notifiers also work for communicating between loops.
07-27-2011 05:18 PM
Steve, you are correct.
I have just started using labview. How do I create the global variable in the first place. I thought the two while loops have to be connected before I can use a global variable or am I wrong?
Thanks.
-Sicelo
07-27-2011 05:32 PM
No, the while loops can run independently of one another. As Steve stated, use caution when using global variables. What are you trying to accomplish? What are your requirements? Post your code. There is probably a better and simpler solution than using global variables.
07-27-2011 07:15 PM
If there is an output from one while loop to another while loop, the second loop will not even begin executing until the first loop exits.
To create a global variable you create a global vi. Just do File/New/Other Files/Global Variable. This is a special vi that has a front panel but no block diagram. You can place as many controls on it as you want. When you drag the file to the block diagram of a "normal" vi you will be able to select any of the controls on the global vi. You right click and set to read or write mode.
You put an instance of the global vi in each loop. In one loop you set the global to write and in the second loop you set it to read.
These have their place but they can easily lead to hard to find bugs if you are not careful. As long as you only write to the global in one place you should be fine.
07-27-2011 09:25 PM
OK, so you have two loops operating in seperate threads (But, you want to stop them both with one click!)
So a Global variable (call it "stop" [bool]) it just what your need right?---- wrong! in LabVIEW bools have 4 states: True, False, True but last read as False, and False, last read as True- The last two CAUSE a state change in the bool control if the "mechanical action" is "latching"
Globals will do the trick for the first read- and if its a "latcher"- reset the variable ---- so only one loop stops
Locals will do the trick for the first read- and if its a "latcher"- reset the variable ---- so only one loop stops
LV2 globals or FGVs will do it better but-- at some overhead. The call to the FGV will cost a few machine cycles (at a Ghz clock this won't hurt a "bit")
On the other hand a "non-latching" boolean a few read "stop" local variables, some merge error primitaves and a write property node to "reset" the "stop" boolean after every loop stops takes very little processor time.
Better yet, the "master loop" can enqueue "Exit" commands to the "slave" loops and get responses from the slaves.
This is called decoupling your GUI. the "user" shouldn't cause your app to behave poorly------- You are the developer- make your app RESPOND appropriately to user activity!
07-28-2011 05:15 AM - edited 07-28-2011 05:16 AM
@Steve Chandler wrote:
[...] Or just a global variable but that is the lazy way and can lead to issues in all but the simplest uses.
I should have tagged the original post; the creator of this picture deserves attribution.
07-28-2011 07:21 AM
Funny! So we can just cut out the middle men?![]()
07-28-2011 07:34 AM