LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you connect two while loops in Labview?

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

0 Kudos
Message 1 of 16
(6,949 Views)

@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!

0 Kudos
Message 2 of 16
(6,948 Views)

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.

=====================
LabVIEW 2012


0 Kudos
Message 3 of 16
(6,934 Views)

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

0 Kudos
Message 4 of 16
(6,926 Views)

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.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 5 of 16
(6,922 Views)

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.

=====================
LabVIEW 2012


Message 6 of 16
(6,907 Views)

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!

 


"Should be" isn't "Is" -Jay
Message 7 of 16
(6,895 Views)

@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.

 

stages.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 8 of 16
(6,863 Views)

Funny!  So we can just cut out the middle men?Smiley Very Happy

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 9 of 16
(6,848 Views)

@jcarmody wrote:
  I should have tagged the original post; the creator of this picture deserves attribution.  

 

I found it here.

 

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 10 of 16
(6,845 Views)