LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What happens when there are two simultaneous user events?

I need to develop a LV application where the execution of code will be triggered from user events.  In this case two environmental chambers will be used over several hours without operator intervention. The user events will be triggered (set into operation) when certain operations are completed within the chambers.  What will happen when events occur at the same time from the two chambers?  For example, it’s going to take a certain amount of time to execute the relevant code that is triggered by the first user event.  While it’s executing the code, what happens when the other chamber sends a user event?  Is the code for the second user event automatically executed after the first is finished or will the second user event get fouled somehow?  If it always executes the second user event, then I’m good to go.  In other words, it’s okay if the second user event is delayed.  What’s important is that the user event related tasks eventually get accomplished in the two chambers regardless of what they are doing at any given moment. 

 

To summarize the above, I plan to duplicate the code for each chamber and I wonder what will happen when a chamber sends a user event while the other chamber is executing a user event.

 

I’m asking this question because I’d like to properly lay the foundation for the application.  Currently I’m using LV 8.5.1 (developer suite) and Win-XP.  (This is not a RT application.)  By the way I just got clearance to purchase the 2009 upgrade, which I’m exited about.

 

Please advise,

 

Thanks,

 

Dave

0 Kudos
Message 1 of 9
(3,864 Views)

If you put your code together properly the event will be placed in a queue. The first event that registered will execute then the second etc... you can also make the code ignore events change depending on events. You are the creator so you get to deside how the events are handled.

 

Normally if you are using events they will be queued.

Tim
GHSP
0 Kudos
Message 2 of 9
(3,852 Views)

dj143 wrote:

What will happen when events occur at the same time from the two chambers?  For example, it’s going to take a certain amount of time to execute the relevant code that is triggered by the first user event.  While it’s executing the code, what happens when the other chamber sends a user event?  Is the code for the second user event automatically executed after the first is finished or will the second user event get fouled somehow?


It depends on the architecture of your code.

From the above description, it sounds like you need to implement a "Producer/Consumer Design Pattern (Events)".  In other words, an Event Structure with a queue to a consumer loop.  The queue would take care of incoming events.  In this case, yes the second event would be handled after the first one has completed.

 


dj143 wrote:

If it always executes the second user event, then I’m good to go.  In other words, it’s okay if the second user event is delayed.  What’s important is that the user event related tasks eventually get accomplished in the two chambers regardless of what they are doing at any given moment. 



The above suggestion would accomplish that.  It is possible to handle the events for the different chambers in parallel.  In this case, I would implement DynamicVI's (daemons) that would be spawned when the Event occurs, and killed after they have completed.  The architecture would be similar, but the consumer loop would take care of spawning and killing the daemons. The consumer loop would not be processing the task.

 


dj143 wrote:
 

To summarize the above, I plan to duplicate the code for each chamber and I wonder what will happen when a chamber sends a user event while the other chamber is executing a user event.



 

There is no need to duplicate the code, and as a matter of fact, it would be poor coding practice.  What if you need to change the code in the future andforget to modify the 2nd copy of the same code, etc..

The solution in this case would be to create a sub-vi.  You can make it re-entrant and in that case, you could call the sub-vi dynamically and LabVIEW would have a seperate thread for each call tot he sub-vi, thus processing both chambers if they both declare an event at the same time (same time being a general statement that they occur close together and not necessarily at t(a) = t(b)).

 

R

 

Message 3 of 9
(3,847 Views)

Hi Dave,

 

In LabVIEW, events work on polling method, i.e the events are stored in the queue and are executed in the order they are triggered.

In your case, when the 1st user event is triggered, it starts executing it. and in between if the 2nd user event is triggered it gets polled. so it will execute once the 1st user event is completely executed. 

 

to demonstrate the above mentioned behavior of event structure i have created a small vi.

 

have a look at it and let us know if you still have any doubts.

 

 

All the best

 

Ritesh 

 

0 Kudos
Message 4 of 9
(3,836 Views)
Saying that LabVIEW events work on polling method is rather misleading since the entire idea about events is to avoid polling anything and LabVIEW does so quite effectively when you use events.
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 5 of 9
(3,830 Views)

I'm pleasantly overwhelmed by the responses.  Attached is a modified version of Ritesh's vi, which more closely resembles the application that I have in mind.  Click the Start button shortly after running it.  While Numeric is counting up to 50, the Running Loop Iteration will equal and pass 100.  Ideally Numeric 2 will start counting after Numeric is finished; but it doesn’t.  (Assume that Event Run Count =100)  This essentially demonstrates my concern.  Apparently I need to sort out the queuing issues that were mentioned earlier.  Does anyone have a queuing example that I can learn?

0 Kudos
Message 6 of 9
(3,806 Views)

dj143 wrote:

Click the Start button shortly after running it.  While Numeric is counting up to 50, the Running Loop Iteration will equal and pass 100.  Ideally Numeric 2 will start counting after Numeric is finished; but it doesn’t.  (Assume that Event Run Count =100)  This essentially demonstrates my concern.  


 When the "Start" button is clicked, the user event is occurred, hence the loop doesn't pass to the next iteration. The loop will only pass on to the next iteration once the event is executed. when the loop goes to the next iteration after executing the 1st user event, the value of Running loop iteration >100, so it never equals 100, hence the 2nd user event is never triggered.
 
 
Ritesh 

 

0 Kudos
Message 7 of 9
(3,796 Views)
One word of caution when implementing all of your processing in the event loop is that your if your processing takes a fair amount of time and inputs from the user, such as the stop request, are delayed until all events are processed. This can confuse and frustrate the user since they know they hit the stop button but nothing seems to be happening. This is a good reason to use the producer/consumer architecture. By doing so you can design your application to interupt tasks that require a fair amount of time and respond quickly to the user requests.


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 9
(3,794 Views)

Ray.R wrote:

From the above description, it sounds like you need to implement a "Producer/Consumer Design Pattern (Events)".  In other words, an Event Structure with a queue to a consumer loop.  The queue would take care of incoming events.  In this case, yes the second event would be handled after the first one has completed.



The VI that you posted is not at all what I had in mind when I suggested the above.

 

In LabVIEW menu bar, select under File > New... > From Template > Design Patterns > Producer/Consumer Design Patterns (Events).

 

Have a look at it.  It should look like this:

 

 

Message Edited by Ray.R on 03-03-2010 01:02 PM
0 Kudos
Message 9 of 9
(3,765 Views)