LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stopping Two while loops running with queuing

Solved!
Go to solution

Hi All,

 

I am using labview 8.2. 

I have two while loops in my code (one called the main loop and the other average loop - seen on the screen shot file).  I just want to stop both the while loops at the same time (it is ok it the average loop takes a little longer).  I am using global variables to stop (as i tried the local one, but I don't think LabView sees it in the middle of the subroutine).  

 

Please give me some suggestion on this.

 

Attached is a screenshot and my labview code  

0 Kudos
Message 1 of 14
(5,888 Views)
The best way to do this is to use a Functional global. you can write the boolean to the functional global in one loop, while you read from the same functional global from the other loop.
0 Kudos
Message 2 of 14
(5,880 Views)

Hi Lordsathish,

 

Thanks for your quick reply.  How can I create a functional global? Could you give an example (perhaps a screenshot)

 

Thanks

0 Kudos
Message 3 of 14
(5,877 Views)
I have attached the Screen shot...
0 Kudos
Message 4 of 14
(5,874 Views)
Solution
Accepted by zientist

Using a 'functional global' is pretty much the same as using a 'global variable'. In fact, before 'global variables' existed, a functional global was how people got that functionality.

 

The usual way to stop a loop containing a 'wait for queue' is to destroy the queue and use the error out terminal of the 'wait for queue' straight into the stop terminal. That way you don't have to queue some sort of stop command to stop it.

 

Add a destroy queue after the 'main while loop' stops. Then delete the global variable and wire the error out of the 'wait for queue' in the 'average loop' to it's stop terminal.

 

General advice, always try to avoid using local and global variables.

Message Edited by Troy K on 10-24-2008 02:52 PM
Troy - CLD "If a hammer is the only tool you have, everything starts to look like a nail." ~ Maslow/Kaplan - Law of the instrument
Message 5 of 14
(5,868 Views)

Hi zientist,

      A local should have worked as well as a Global, though, with the Dequeue timeout at -1 (wait indefinately) the loop may never stop no matter what type of variable you used.

 

Follow Troy's advice - see example attached!

 

Cheers.

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 6 of 14
(5,862 Views)
Yes... Troy's idea would work here for sure... But is it the best way to do...?
0 Kudos
Message 7 of 14
(5,858 Views)

I'm pretty sure it is the way it is done in the training manuals. Least amount of overhead. I doubt you'd loose points in a CLD exam by doing it that way.

 

The best way to do x... who knows! How long is piece of string? It's always debatable what is the best way to do something.

 

In software there are good ways to do things and bad ways to do things. There is almost never only one way to do something.

If you want to be amused by some really bad ways of doing things, search this forum for 'rube goldberg code'.

 

Message Edited by Troy K on 10-24-2008 03:30 PM
Troy - CLD "If a hammer is the only tool you have, everything starts to look like a nail." ~ Maslow/Kaplan - Law of the instrument
0 Kudos
Message 8 of 14
(5,854 Views)

Troy K wrote:

The usual way to stop a loop containing a 'wait for queue' is to destroy the queue and use the error out terminal of the 'wait for queue' straight into the stop terminal. That way you don't have to queue some sort of stop command to stop it.


Yes, I would go with this too. Here's a simple example that show the basics.

 

Message Edited by altenbach on 10-24-2008 12:20 AM
Message 9 of 14
(5,835 Views)

Thanks Troy and Altenbach

 

It works!!

 

Just wanted to ask, Troy  why do you recommend to AVOID using global and local variables?

 

 

0 Kudos
Message 10 of 14
(5,774 Views)