LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple event structure in a while loop

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

0 Kudos
Message 1 of 10
(4,806 Views)

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

 

Avoid Placing Two Event Structures in One Loop


We have two ears and one mouth so that we can listen twice as much as we speak.

Epictetus

Antoine Chalons

0 Kudos
Message 2 of 10
(4,801 Views)

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)

 

 

0 Kudos
Message 3 of 10
(4,800 Views)

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 

0 Kudos
Message 4 of 10
(4,795 Views)

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)?

 

0 Kudos
Message 5 of 10
(4,791 Views)

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 10
(4,768 Views)

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.

0 Kudos
Message 7 of 10
(4,759 Views)

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 8 of 10
(4,743 Views)

Hi Mark,

 

            Sorry, I only have labview 2010. Cannot open your example

0 Kudos
Message 9 of 10
(4,735 Views)

Here is the 2010 version.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 10 of 10
(4,714 Views)