cancel
Showing results for 
Search instead for 
Did you mean: 

Stopping Two while loops running with queuing

SOLVED
zientist
Member
Solved!

Stopping Two while loops running with queuing

Message contains an attachment

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  

13 REPLIES 13
lordsathish
Active Participant

Re: Stopping Two while loops running with queuing

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.
zientist
Member

Re: Stopping Two while loops running with queuing

Hi Lordsathish,

 

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

 

Thanks

lordsathish
Active Participant

Re: Stopping Two while loops running with queuing

Message contains an attachment
I have attached the Screen shot...
TroyK
Active Participant
Solution

Re: Stopping Two while loops running with queuing

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
tbd
Active Participant
Active Participant

Re: Stopping Two while loops running with queuing

Message contains an attachment

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)
lordsathish
Active Participant

Re: Stopping Two while loops running with queuing

Yes... Troy's idea would work here for sure... But is it the best way to do...?
TroyK
Active Participant

Re: Stopping Two while loops running with queuing

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
Highlighted
altenbach
Knight of NI

Re: Stopping Two while loops running with queuing

Message contains an image Message contains an attachment

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
zientist
Member

Re: Stopping Two while loops running with queuing

Thanks Troy and Altenbach

 

It works!!

 

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