05-10-2012 05:07 AM
Dear All,
I had a multiple event structure inside a while loop. The purpose of doing so is because I had a few 2D picture on the front panel. I would like to detect which 2D pictures had been click using the mouse down event structure for 8 of my 2D pictures.
The problem that I faced now is that when I of the event case or one of the 2D pictures had been click, it will not exit the while loop. I had to click on all the 8 2D pictures before it will exit the loop.
I had uncheck the under the "Edit Event" --> "Lock Front Panel (defer processing of user action) until this event case completes". But I am still stuck inside the loop.
Each 2D picture will perform different action therefore I cannot have an event case of all 2D pictures inside else I would know which 2D picture had been click.
Is there any other way out of this situation? Pls help. Thanks a lot
05-10-2012 06:01 AM
just a quick read of those knowledge base articles should help you :
http://zone.ni.com/reference/en-XX/help/371361H-01/lvhowto/caveatsrecmndtnsevnts/
and
We have two ears and one mouth so that we can listen twice as much as we speak.
Epictetus
05-10-2012 06:02 AM
The while loop can only iterate when all code inside it has executed.
There are several ways to accomplish that:
1) use only 1 event structure (in a while loop) to handle the events of all pictures
2) use several while loops with 1 event structure each
3) use timeouts in the event structures so they can execute even if no event occurs (I would not recommend this option)
05-10-2012 06:18 AM
Hi dan_u,
Can I check with you on point 2. As I am using state machine design on my VI, at the result state, I am actually waiting for any of the 8 2D picture to be pressed. Then according to the picture click, I will go to different state.
When you say serveral while loop with 1 event structure each. If only 1 of the event is pressed, will the state machine continue without waiting for the rest of the event inside the while loop to complete?
I remember me doing the same thing be the while loop with the event case with it will not move as the T is not wired to the while loop of other event case.
Or is there other way to stop the other while loop when one of the event case is clicked? I tried to wire all the while loop stop condition together but it does not work. Pls help
05-10-2012 06:27 AM
If you're using the event structure inside a state machine method 2 does not work. Why don't you go with method 1 (using only 1 event structure for all events)?
05-10-2012 05:51 PM
Why not use a producer/consumer architecture. Have one while loop with the event structure that detects which picture control has been selected. Have that event case post a message to your consumer to perform the processing. You coul dhave feedback to the evnt structure using user events which would allow you to turn the events on and off if you need to control when you should get the events.
I generally do not like to have event structures buried in a state machice. This generally leads to very sluggish and unresponsive user interfaces.
05-10-2012 07:23 PM
Hi Mark,
Sorry to ask stupid question. If using the consumer/producer loop, to handle the event of individual 2D picture been click, we still need to place more than 1 event inside the while loop right? Or are you implying to have 1 while loop for 1 event inside a big while consumer loop? Because I need to detect which 2D pictures had been click.
How can I turn On/Off the event? Is it by sending msg also? Dont really understand the control part. Quite new to labview and only did state machine.
05-11-2012 01:39 AM
A producer/consumer architecture (look at the examples that ship with LabVIEW) is comprised of two parallel while loops. One loop contains the event structure. The other contains your consumer which is basically a queued state machine. It receives messages from the producer via a queue. Your event structure can register a separate event for each 2D picture control or it can use a single event that would determine which spefic controls was clicked on. This is a more general approach and expands easily. Here is a basic example of what I am talking about.
05-11-2012 02:23 AM
Hi Mark,
Sorry, I only have labview 2010. Cannot open your example
05-11-2012 10:55 AM
Here is the 2010 version.