03-06-2013 07:42 AM
I have two event structures in a single VI, one that handles events that freeze the user interface and one for events that don't. The latter group are all triggered acquisition tasks, where you arm the data acquisition, but possibly might want to abort it (or do other things, while waiting for the data to come. Obviously you need a stop button to be active and responsive. In retrospect, using two loops was possibly a poor choice, but one I made because it never occured to me that these things would only fire once and have to be put in a while loop to be kept active. No other language does that as far as I know. Anyway, the question is how do I keep both active? Do I enclose both in a single while loop? Do I give each there own while loop. Do I give up and merge the two event structures into one. For clarity I would like to keep them seperate, but that is not essential. I'ld like to know what my options are.
Solved! Go to Solution.
03-06-2013 08:03 AM
Having both event structures listen to e.g. a Value Change event on a stop button shouldn't be a problem, the point of events is "one-to-many". 🙂
What events do you want both structures to listen to?
/Y
03-06-2013 08:34 AM
i vote for the use of producer/consumer architechure with dynamic event....
03-06-2013 01:22 PM
The two structures handle mutually exclusive events. The real question is how do you have two concurrently active structures (assuming you can). If they are in sperate while loops will they both run. If they are in one loop will the loop recycle if one structue is still waiting for an event to occur? Is there an issue with having events that freeze the UI in the same loop as events that don't freeze the UI?
03-06-2013 02:12 PM - edited 03-06-2013 02:14 PM
@rossu wrote:
If they are in sperate while loops will they both run. If they are in one loop will the loop recycle if one structue is still waiting for an event to occur?
The answer to this is fundamental to how LabVIEW works. A loop will not proceed to the next cycle until everything inside it completes. If you have two event structures in the same loop, both of them need to process an event (or a timeout) before the loop will iterate.
You can have multiple event structures in the same VI.
By "freeze the UI," do you mean the "Lock front panel..." checkbox in the event dialog? There is no problem with having some events that do lock the front panel and some that do not in the same event structure. I'm not sure that this is what you mean by "freezing" the UI, though.
EDIT: and one more comment. Generally you should not put long-running tasks (like data acquisition) inside an event structure. Instead, the event case should pass those tasks off to a separate loop (for example using a queue) so that the event structure can quickly go back to listening for other events.
03-06-2013 08:22 PM
03-07-2013 02:14 AM
You can register for event callbacks and it's actually really nice when it works good. You register a VI to handle a callback, and that is run automatically when the event happens.
There's an Event based Producer/Consumer in the templates, which sounds like your attempt, check it out. 🙂
/Y