LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event Structure Execution

I am using an Event Structure for handling the activation of solenoids via front panel controls.  I have one event case dedicated to each solenoid control.  When a control is pressed a VI is called in the event case which energizes the solenoid for a period of time.  There are times when I would like to energize multiple solenoids at once.  For example, I would like to turn on solenoid #1, after a certain period of time while solenoid #1 is still energized I'd like to turn on solenoid #2.  The problem that I'm running into is that the event case for solenoid #2 is not acted upon unit the VI in the event case for solenoid #1 is finished.  Any suggestions. 
0 Kudos
Message 1 of 13
(3,922 Views)

Just have the control for the solenoid in the event case.  Use the event case inside a state machine or queued message handler block diagram so that the control value change sends the vi to the correct case that activates the solenoid.  When the solenoid is activated.  The state machine (queued message handler) can then return to the event case to wait for another push of the button.

 

 

Tom



Message Edited by Tom Haggerty on 01-24-2008 09:37 AM
0 Kudos
Message 2 of 13
(3,920 Views)
Sorry but I didn't quite understand the solution.  Attached is a simple mock-up VI which shows the arcitecture for the program.  Could you possible modify this to show me what you mean?  Thanks a lot!
0 Kudos
Message 3 of 13
(3,887 Views)

No problem, but please convert the files to version 8.2 -- I'm not using 8.5!

 

Thanks,

Tom

0 Kudos
Message 4 of 13
(3,885 Views)
Here you go.
0 Kudos
Message 5 of 13
(3,883 Views)

This is what I meant by using a state machine.  However, this still only executes the sounds one after the other.  In order to get them to occur simultaneously, you would have to code it so that the sound.vi does not suspend execution while the beep is occurring.  I don't think that is possible with the beep.vi but you could make it work with your solenoid controls.

 

 

Tom

0 Kudos
Message 6 of 13
(3,871 Views)
Thanks.  One question, the solenoids use the same VI.  I will need to run multiple instances of the VI at the same time.  Is this done by setting the execution property to reentrant?
0 Kudos
Message 7 of 13
(3,858 Views)
I took a look at the code and am having trouble seeing how multiple actions can happen at once.  Doesn't the VI in a case have to be completely executed before another case can acted upon? 
0 Kudos
Message 8 of 13
(3,854 Views)
You are correct.  Each VI needs to finish before returning to the event structure.  You need to have the event handler be totally separate from the event structure loop.  Like most things in LabVIEW, there is more than one way to do this.  Here are two.
  1. Create a VI which energizes a solenoid.  This VI will energize the solenoid, wait a specified time, then deenergize the solenoid. Recommended inputs are the solenoid identifier and the wait time.  Make it and all its subVIs reentrant, since you will be calling it from several places.  For each solenoid, create a queue (use the energizing time as the data type) and a parallel loop to your main event loop.  Put all the queue references in a cluster or array for easier handling in the event structure.  Wire the cluster or array to the event structure.  Wire the individual queue references to the parallel loops.  In the event structure, when you get an event energizing a solenoid, put an element in that solenoid's queue.  In the parallel loop, put a dequeue with an infinite timeout.  When the dequeue occurs, run the VI which energizes your solenoid.  When you exit, do a force destroy of all your queues.  This will cause an error on the queues in the parallel loops, which is their signal to exit.  This method does not scale very well because you need a parallel loop and queue for every solenoid, but it is simple and obvious for low numbers.  It also has low latency between the button press and solenoid activation.
  2. Create a VI which energizes the solendoid, as before.  In the event which energizes the solenoid, open a reference to the energizing VI using Open VI Reference.  Since the VI is reentrant, you will get a new copy every time.  Use invoke nodes (Control Value Set [Variant]) to set the execution time and solenoid specifier.  Now use the Run VI method of an invoke node to run the VI.  Set Wait Until Done to FALSE and Auto Dispose Reference to TRUE.  This will cause the energizer VI to run as a separate process and return control immediately to your main program.  This method scales very well, but has more latency due to the time needed to load the VI and set the front panel variables.  If you build an application with this, make sure the front panel of the energizer VI is not removed.
Good luck.  Let us know if you need more help.
Message 9 of 13
(3,844 Views)

Thanks for adding to the discussion DFGray.  I have been in meetings all morning!  I agree with your solutions to this problem.  JHess, you can find a template for setting up the Queue, Dequeue method that is described by selecting file...new... and selecting Producer/Consumer Design Patterns (Events).

 

Tom

0 Kudos
Message 10 of 13
(3,817 Views)