From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Elapsed time reset in producer consumer loop

Solved!
Go to solution

Hi, everyone!

 

 

I have a producer(event handler) and consumer(state machine) structure. One of my states says: display message, then wait 5 sec, then display something else, then wait 3 sec, etc, so I have 5 timers with countdowns using the Elapsed time vi. 

I also a have a function which is supposed to start this state all over again, so all the timers need to start at the initial time.

For some reason, this is not working, although I am using the reset function on the elapsed time.

 

Has someone done this before and now how to reset the timers in a producer consumer loop?

 

Best regards

 

 

0 Kudos
Message 1 of 13
(2,451 Views)

Perhaps if you included your code it would be more clear what you are trying to do. It sounds to me like you're wanting to start multiple timers simultaneously, but I may be misunderstanding. If this is the case perhaps you need to build your own elapsed time code - it's really simple.

0 Kudos
Message 2 of 13
(2,430 Views)

Hi, 

 

I want the timers to execute one after another, see attached VI and then reset.

 

 

 

Best regards

 

 

0 Kudos
Message 3 of 13
(2,423 Views)

Hi, 

 

I want the timers to execute one after another, see attached VI, and then reset.

 

 

 

Best regards

 

 

0 Kudos
Message 4 of 13
(2,422 Views)
Solution
Accepted by topic author mirelche

What is going on here? Why the Producer/Consumer architecture? Is this part of a larger program?

 

 

countdown.png

========================
=== Engineer Ambiguously ===
========================
Message 5 of 13
(2,397 Views)

Your queue utilization is a COMPLETE mess and you therefore have race conditions and circular code.  You need to implement a proper state machine in your message handling loop.  DO NOT LET THE PRODUCER DIRECTLY SET THE STATE.  A little trick I do here is to use the queue timeout.  You can store the timeout in shift register so you can change it.  Set it to -1 to wait forever or some other value.  On a timeout (ie, you did not get a message), you perform the next state in your state machine.  If you got a message you handle it.  Use another shift register to set whether or not to reset your timers.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 13
(2,371 Views)

All you probably need is an single while loop containing a case structure (or maybe an event structure containing a case structure in the timeout case).

0 Kudos
Message 7 of 13
(2,333 Views)

Yes, it is part of a larger program, where I need the producer consumer.

0 Kudos
Message 8 of 13
(2,326 Views)

I thought this is what I do with the timeout case in the event structure by enqueing the Wait state there...

0 Kudos
Message 9 of 13
(2,325 Views)

See if this can give you some ideas. (i.e. how to switch states after some time).

Message 10 of 13
(2,318 Views)