LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

making only part of a loop wait?

Hello,

 

I have another question to ask about looping. My program is a virtual interface for an Agilent device, that dynamically updates parameters on the device as you change them on the interface. Currently, it works by having an event handler (with 30 different cases, 1 for each field) inside a while loop - the while loop runs continuously, waits 0 seconds for an event, and restarts itself. This all works perfectly.

 

The issue is that, now I want to read data from the device to check if a UE has registered, but I only want it to check once every 5  or so seconds, as I do not want it to interfere with the rest of the program, and I only want it to do these reads/checks if one of my boolean controls is set to true. The issue is that the boolean control is already inside the other while loop, as it's value must be read by the event handler in case it is changed. If I throw everything into one big loop with a time delay, or even add a case statement that only sends the read command once every 10000 times through the loop, it makes the interface unresponsive/glitchy (the time delay for obvious reasons, the case statement executes almost continually, despite only being called once every ten thousand times, slowing everything down). If I put the read commands in a separate, timed while loop, I have no way to access the value of the control in both loops, updating every time the loops run, as as far as I know the loop input tunnel only takes the "initial" value, i.e. the value when the loop was first called, and does not update continuously.

 

So my question is, is there anyway to make part of the code in a while loop wait 5 seconds before restarting the loop, while the rest of the code continues on with no delay, or alternatively is there anyway to have one control supply its value in real time for every iteration of the loop, to multiple loops? 

 

Thanks!!!

Dennon

 

P.S. sorry for this overly long, "wall of text" post... 

0 Kudos
Message 1 of 5
(2,739 Views)
Look at producer consumer architecture. That way you can handle your events separate from your processing and do anything you want in your processing thread time wise.
Message 2 of 5
(2,726 Views)

Hi DennonO,

 

I agree with for(imstuck). It sounds like your application is a great use case for a producer/consumer architecture where you just pass data from your producer loop using queues and then process that data in the consumer loop at its own rate.

 

Aaron P

National Instruments

Applications Engineer

http://www.ni.com/support

Message Edited by Peñata on 05-17-2010 01:49 PM
0 Kudos
Message 3 of 5
(2,661 Views)

Well, this is embarrassing......

 

What is "producer consumer architecture", or more specifically, where can I find out about it?

 

Thanks! 

0 Kudos
Message 4 of 5
(2,645 Views)

Hi DennonO,

 

Here is a good Developer Zone Tutorial article that goes over the Producer/Consumer architecture. Also, a good resource is the ni.com community examples and ni.com/community. Simply search for producer consumer and you should get some hits.

 

Let me know if you have any further questions.

 

Aaron P

National Instruments

Applications Engineer

http://www.ni.com/support

0 Kudos
Message 5 of 5
(2,643 Views)