09-28-2016 10:00 AM
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?
Solved! Go to Solution.
09-28-2016 10:01 AM
The answer: Event based Producer/Consumer pattern.
Norbert
09-28-2016 10:06 AM
Do you have an example? I have found this but I don´t know how to apply in my case.
09-28-2016 10:11 AM
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
09-28-2016 10:30 AM - edited 09-28-2016 10:41 AM
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.
09-28-2016 10:34 AM - edited 09-28-2016 10:35 AM
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.
09-28-2016 10:40 AM - edited 09-28-2016 10:45 AM
OK I'll help you out a bit.
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
09-28-2016 10:43 AM
You said like this? It didn't work.
09-28-2016 10:47 AM
@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.
09-28-2016 10:48 AM
Yeah, That won't work
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