LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I make an event occur every X secs while using an event structure

Solved!
Go to solution

I am using an event structure so that my chart and controls will respond quickly to a user event such as hiding or showing a waveform or hitting the stop button.  However, I am having difficulty in that I would like the read of the data to happen every 60 secs.  I tried putting 60 secs as the timer on the Timeout case but user interaction with the screen causes the timeout not to happen exactly at 60 secs.

 

I tried using a shift register to pass the tick count and then subtracting that from the current tick count so that I could set an indicator to True and have an event case for that.  I learned that the event structure doesn't function like a normal while loop so the shift register won't work.

 

Any ideas?

0 Kudos
Message 1 of 8
(6,025 Views)
Solution
Accepted by topic author CarolK

I'm not sure I understand what you mean by "I tried putting 60 secs as the timer on the Timeout case". Does this mean you wired 60000 to the "Event timeout" terminal? That would make the Timeout even trigger if there had been no user event within 60 seconds. This means that if there's an event, the "timer" gets reset, and the "Timeout" case won't fire until there has been no activity for 60 seconds.

 

I also don't understand the bit about the shift register.

 

Ultimately, you have several ways of doing this. You can set the "Event Timeout" to a small value (say, 10 msec), and then compare the time against the last time you had a read. If 60 seconds have passed, then do your read. You could also set up a parallel loop that does your read. This is basically the producer-consumer architecture. The secondary loop would operate in a similar fashion as to what I just desribed, as you don't want to have a timer of 60 seconds since that would mean you would have to wait up to 60 seconds to break out of the loop. Not sure which is the better approach for you since I don't know what else your code is doing.

 

See attached for an example of the first option.

Message 2 of 8
(6,000 Views)

Hi Carol,

 

I would use a timedLoop to read the data and refresh / update the waveform graph.  The Event Structure would only be used for User Events (unless there are other events you want to set up as triggers).  There is a "fancy" way of implementing this by using a daemon whose only function is to read the data on a timely basis and refresh the graph.   You may also need an ActionEngine to pass running parameters to the timedLoop or daemon in order that it stops / pauses / clears / etc..

 

You can find search ActionEngines within this forum. You can also search Functional Global variables which could also do the trick. 

 

There may be many different ways of implementing your solution.  Since you want the same action repeated at every 60sec intervals, then a timedLoop may be a good solution for you.

 

R

0 Kudos
Message 3 of 8
(5,997 Views)

Another possibility would be to dynamically recalculate the remaining timeout whenever a non-timeout event occurs.

 

Here is an old example (from the end of this old discussion).

 

0 Kudos
Message 4 of 8
(5,981 Views)
I would recommend a parallel while (or timed) loop, because you have to do something parallely to and independent from user events from the front panel.
Message 5 of 8
(5,976 Views)

I was about to reply to Eugen that it was what I had proposed...  But after re-reading my post I noticed that I forgot to mention that the Event Structure would be in one while loop and the timedLoop would be a parallel loop.    😮

 

Same idea with the daemon.  It would run concurrently with the UI code which had the Event Structure..  The Event Structure could spawn it when starting to acquire data and kill it when done.

 

However, do have a look at the example(s) Altenbach included in his post.  They may be faster to work with.

 

R

0 Kudos
Message 6 of 8
(5,946 Views)

Ray.R wrote:

However, do have a look at the example(s) Altenbach included in his post.  They may be faster to work with.


It's a pretty old example and I probably would do a few things slightly differently. Problems could occur if events fire constantly and the timeout event never has a chance.

 

A event loop for the UI and a parallel timed loop for the timed operations also has potential problems, because it might take 60 seconds for the loop to shut down when you want to stop the program. There are many ways to solve this.

0 Kudos
Message 7 of 8
(5,930 Views)

altenbach wrote:

 

A event loop for the UI and a parallel timed loop for the timed operations also has potential problems, because it might take 60 seconds for the loop to shut down when you want to stop the program. There are many ways to solve this.


I agree..  That is what I had in mind for the ActionEngine.  It could monitor the run status and stop the loop.

 

The better approach is what I suggested in my first post to use a daemon (or Dynamic VI).  When exiting the program, just kill the daemon.  The ActionEngine could provide the reference to the waveform graph in order to refresh it on the front panel of the calling VI.

 

Unfortunately I am without LV these days.  (Doing embedded C stuff)..  So I could not whip-up an example..

 

R

0 Kudos
Message 8 of 8
(5,908 Views)