LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create an Event Structure that repeat a task until a push a buttom

Solved!
Go to solution

Hi!

I will like to do a program that repeat a task until a push a buttom (that indicate to start another task). I know how to do this with a case structure, but I want to know how to do it with event. Any idea?

 

0 Kudos
Message 1 of 13
(3,942 Views)

The answer: Event based Producer/Consumer pattern.

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 13
(3,941 Views)

Do you have an example? I have found this but I don´t know how to apply in my case.

0 Kudos
Message 3 of 13
(3,937 Views)

Yeah, that is essentially what i was talking about.

You can use the File >> New (called Template Browser) to create a VI with the appropriate code.

Another option is to use the Create Project wizard to create a Queued Message Handler project. This is a advanced version of producer/consumer.

 

The idea is that the producer tells the consumer "Do This!", "Do That!". In your case, one event tells the consumer to start to work on things continuously until another event tells the consumer to stop doing this.

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 4 of 13
(3,931 Views)

You can use the timeout event for the repetitive actions. Place a timeout of -1 (=infinite) in a shift register and wire ot to the timeout terminal of the event structure. Use a button press event to switch the timout to a finite value (e.g. 1000ms), thus triggering repeated action of the timeout event containing your task code. Switch the timeout back to -1 to go back to idle as needed.

The nice thing is that even if the timeout is very long (many seconds), you can break it at any time.

Place a case structure in the tmeout event to select between tasks.

0 Kudos
Message 5 of 13
(3,919 Views)

Open LabVIEW.  File --> Create Project.  Choose Queued Message Handler.  See if you can fill in as many of the blanks as you can.  We'll be here to help you out (but not here to write the code for you)!  🙂

 

I see I'm a little late to the party.Smiley Embarassed

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 13
(3,915 Views)
Solution
Accepted by topic author lincoln1991

OK I'll help you out a bit.

 

Simple QMH.png

 

Here is how it works:  The top (Producer loop) will pass the Value of OK Button (Switch when released) to the Message Handling loop (Consumer).  When the button goes True the consumer executes the code in the true case and enqueus another True to itself then waits 1 second.  When OK Button goes False, The false value is popped to the front of the queue and the message handler executes the False case, Empties the rest of the queue and waits for the next message from the event loop.

 

The Stop button (Latch when released) exits the event loop and the queue is destroyed causing the Dequeue to return an error and the message loop exits.

 

Obviously this is an extremely simplified QMH.  To read up further on the concepts DO go to File>>Create Project>> And select the "More Information" Link

or not error.png


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 13
(3,910 Views)

You said like this? It didn't work. 

 

Captura.PNG

0 Kudos
Message 8 of 13
(3,902 Views)

@lincoln1991 wrote:

You said like this? It didn't work. 


Who is "you"? Please quote relevant parts of a post when replying. There are many suggestions above.

 

Here's what I had in mind.

 

0 Kudos
Message 9 of 13
(3,897 Views)

Yeah, That won't workSmiley Wink

Time for you to go through the reading suggested in my last post.  We are more than happy to explain anything that might confuse you in that material


"Should be" isn't "Is" -Jay
0 Kudos
Message 10 of 13
(3,895 Views)