Multiple event structures in one VI

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.

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.

Similar Messages

  • Multiple event structures in one program

    I know it's not good practice to have one event structure inside another event structure (I don't know exactly why). But if another event structure is in the subvi, is it safe? Please comment.

    guangdew1 wrote:
    I know it's not good practice to have one event structure inside another event structure (I don't know exactly why).
    This is because of dataflow and the way event structures work. If you have an event structure inside an event structure, both event structures will accumulate events whenever one occurs, but it is unlikely that they can be handled in the order they occur or at all. By default, event structure are set to lock the front panel until the event completes, meaning that if an inner event gets triggered first, the code will lock up, because it will no longer be possible to trigger one of the outer events. If the outer event occurs first, it cannot complete, because it requires a later firing of one of the inner events before it is ready to handle the next event that occurs in the UI. Even if it marginally works if the panels don't get locked, you are requiring the user to trigger events in a certain order. How is he supposed to know what's allowed or not?
    If this is not exactly clear to you, you need to start with a few tutorial and learn about dataflow, Then start using a single event structure and see how things work by programming scenarios and see what happens.
    guangdew1 wrote:
    But if another event structure is in the subvi, is it safe? Please comment.
    Event structures are only useful inside interactive subVIs that show their front panel. even then I strongly advise against calling anything interactive, or anything that takes excessively long, inside a main event structure. You end up with code that can become unpredictable, can deadlock, is hard to debug and flies in the face of all good programming guidelines.
    Obviously, you have some specific application in mind where you think something like that is useful, I can guarantee you that there is a much better solution is you think about this a bit longer. If you need help, please describe exactly what the program should do and how it should react to user interactions at the various stages.
    A program should always be approached from the code and UI needs. Don't start with a harebrained code construct (events inside events) and then look for a use. It does not exist! 
    Event structure only belong in toplevel loops. They should never be hidden insde squences or case structures (or other event structures as already mentioned above). If you have multiple toplevel loops that run in parallel, it is safe to place up to one event structure inside each. Each event structure can have an unlimited number of event cases. This should be sufficient to handle any programming need you might have.
    LabVIEW Champion . Do more with less code and in less time .

  • Can I have multiple event structures with the same event cases?

    Hello, 
    I'm doing an application that reproduces the front panel of the HP6675A power supply. To achieve this, I have done a state machine with different states
    (initialize, measures, voltage, current, ocp, ov, store, recall, etc). In each state, should have an event structure that catches the events of the buttons, like for example: if the current state is the Voltage mode and the user press the current button the next state will be the Current mode. For this in each state of the state machine should be the same event structure with the same events.
    My problem is that the Vi doesn't work properly when I have multiple event structures with the same event cases. There are some possibily to do this, and how? Or is impossible to have multiple events? I have been reading some posts, but I don't find solutions. 
    Any help is appreciated.
    Thank you very much.
    Solved!
    Go to Solution.

    natasftw wrote:
    Or as others mentioned, make two parallel loops.  In one loop, have your state machine.  In the other, have just the Event Handler.  Pass the events from the handler to the state machine by way of queues.
    A proper state machine will not need the second loop.  The "Wait For Event" or "Idle" state (whatever you want to call it) is all you really need in order to catch the user button presses.  The setup is almost there.  Maybe add a shift register to keep track of which state to go to in the case of a timeout on the Event Structure.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Using multiple events structure inside state machine to control the Tab

    Hi y'all,
    Anne here.I have a Tab indicator in my front panel and I want to be able to control the flow of my program based on what controls I clicked inside the tab. I am using a state machine architecture and inside every state, I use an event structure to check for user interaction  to determine the next state and what tab page is going to be displayed next. This means that I am actually using multiple event structures in my application and I use them in just one while loop, but just that they are not running in parallel since I am only using "one event structure per state" which means that only one event structure is running at one time. My questions is, programming technique wise, am I doing it correctly? So far, I am not facing any problem (I am still in the early stage of the project) but I want to check with you all first on your opinion regarding this architecture. Will there be any issue on using multiple event structures in a vi? Since I will be using a tab, and the controls available in the tab will be the controls that will control my event structure for that state, by right, there should be no issue. Am I correct to assume this? Is there any limit on the use of event structures? I have attached here a simple sample of the architecture that I am talking about for your reference. I have attached a 2010 version and a 8.6 version. Let me know what you think or any opinions that you may have.
    Hoping to hear from you soon! Thanks so much in advance!
    Cheers!
    Anne
    Attachments:
    State Machine-Event Structure Sample_2010.vi ‏19 KB
    State Machine-Event Structure Sample_8.5.vi ‏25 KB

    Hi jak888,
    I decided to use tabs cause I don't want to have subvi pop ups every time i need to perform the process in the state and show an update in the front panel. This is actually going to be more of an ATE where you will have to choose first whether the one using is the operator or the engineer. If the operator is logged in, she will proceed to choose what test to run (this state will have its own event structure). This part, I don't want a pop up, so what happens is that from Login page, if the user logs in as operator, the tab will automatically switch to the Test Selection page. After selecting the test, it will proceed to Start Test state and the tab will show the Result Summary page. If the user logs in as engineer, then a totally different tab will be automatically shown next and so on. By doing this, I will be able to show an update on the front panel objects without having the subvis pop up. I will also just need to use the call reference functions to call my subvis, making my Main VI more generic. The tab Page header will be hidden so the operator will actually not see that there is a tab and that there are a lot of controls and indicators cause they are hidden in the tabs and that page will only be shown based on what they selected from the main tab. 
    I appreciate your thoughts! thanks so much!

  • 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

    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
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot
    Attachments:
    Event Producer-Consumer.vi ‏14 KB

  • Event structure: have one event trigger another event

    I have an event structure with two events. I want the finalization of the first event to trigger the second event. Both events are triggered by a boolean value change, say "boolean 1" and "boolean 2". Can I have a local variable of boolean 2 inside event 1. By changing its value, it should trigger event 2. However, this doesn't seem to be working. (see attached example)
    any help?
    Solved!
    Go to Solution.
    Attachments:
    test.vi ‏9 KB

    Tim's reply is the answer you are looking for.
    I would like suggest that you create a sub-VI that doesw the work in the second event you want to fire so tht rather than resorting to having one event trigger another, you can simply use the sub-VI that does the work in event_2 after the sub-VI that does the work for event_1.
    If you decide to stick one event triggering another, please clearly document the sceme in BOTH events. What you want to avoid is latter deciding event_1 should be triggered by Event_2 and the next thing you know, your app hangs.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Multiple Event Structures - LV8.0

    So why does this program hang?  I know that it is best to use one event structre but why?  It seems for a simple application that this should work.
    Matt
    Matthew Fitzsimons
    Certified LabVIEW Architect
    LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
    Attachments:
    multipleEventDiagams.vi ‏15 KB

    That certainly explains the hanging you saw. Remember that Event Structures by default will lock the front panel until the event case for a given event occurs. So in your VI, if you press Button 2 once, then you terminate the bottom loop. But the event structure is STILL registered for the Button 2 event. So when you press Button 2 again, the front panel gets locked, because the bottom event structure will never get to execute again (its loop has been terminated).
    You could have fixed this (I realize it all boiled down to a mis-wired connection) by unchecking the check box in the Edit Events dialog for your Button 2 Value Change event case that says "Lock Front panel until...".
    Hope this explains this, even though you've solved it!
    Jarrod S.
    National Instruments

  • Multiple events triggered by one modification

    Hello,
    I'm trying to trigger multiple events with the modification of a single user field. In Lookup.USR_PROCESS_TRIGGERS, I've defined the same field twice and associated them with two different events. My lookup looks something like :
    Code Key
    Decode
    USR_FIRST_NAME
    Change First Name
    USR_FIRST_NAME
    Change Full Name
    This works perfectly, but it seems that the duplicate Code Key randomly disappear after some time leaving me with a single entry for USR_FIRST_NAME. Is this normal? Is there another way to make a single field trigger 2 events?
    Thanks,
    --jtellier

    You're doing it wrong.  You should not have duplicate code keys.  Here is what you can do though.
    Code Key = USR_FIRST_NAME Decode = Change First Name
    Now on your process definition, as long as the task starts with "Change First Name" you can add as many instances as you want.  You can create the following tasks and they will all trigger:
    Change First Name
    Change First Name - Full Name
    Change First Name - Display Name
    Change First Name - Email Address
    Just the first part matters.
    -Kevin

  • Multiple events structures for same control

    Hi,
    I would like to use a same blinking button into 2 event structures seperately.
    Please see my VI, after the first event is done, the second event is not wait for user to press the button, and it is auto triggered.
    How to solve that? Is there any way to reset the event?
    Thanks.
    Attachments:
    2 events.vi ‏13 KB

    It is also not clear what you are trying to do with the blinking. In your code, the LED will blink basically always. (you don't use the timeout event).
    In the first frame, blinking is enabled. Nothing happens in the second frame until the start event occurs. At this time blinking gets disable for about a nanosecond and gets immediately enabled again in the third frame. Even if the second eveng would not execute, you'll never see a difference. So what's the point?
    Here's a quick draft where each press of the start button toggles between blinking and not blinking. Maybe it can give you some ideas.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    2 eventsMOD.vi ‏10 KB

  • Multiple event handlers for one button

    I'm trying to create a button with 2 event handlers, such
    that when you roll-over the button, a submenu pops up, and when you
    click the button, you go to a certain frame. I feel like this
    shouldn't be hard at all, but it's not working. Below is the
    actionscript I have tried. Both event handlers work as I want them
    to if alone, but the on(release) functionality does not work when I
    try to put them together.(I have Flash 8). Thanks for your help!
    on (release) {
    _root.gotoAndStop("one1");
    tellTarget (_root.navigation) {
    gotoAndStop (1);
    on (rollOver) {
    this.gotoAndPlay("links");
    tellTarget (_root.navigation.introduction) {
    gotoAndStop (1);
    tellTarget (_root.navigation.overview) {
    gotoAndStop (16);
    tellTarget (_root.navigation.coronary) {
    gotoAndStop (1);

    this code is ok, it seems that when u rollover on the button,
    the event is fired and it keeps on running the time u r on it. i
    think just add
    delete this.onRollOver inside rollOver event.

  • Multiple Event Calendars on One Page

    I have several event calendars  on a webpage that are broken down by categories (IE: {module_calendar,48,c,94584} ). When I do this only the first calendar on the page will change dates. The other calendars won't change the date.
    Is there a way to fix this? Is this intended behavior or a bug?
    Note: I would provide the page but it is within a secure zone that charges a membership thus I cannot post access to it publicly.

    I have several event calendars  on a webpage that are broken down by categories (IE: {module_calendar,48,c,94584} ). When I do this only the first calendar on the page will change dates. The other calendars won't change the date.
    Is there a way to fix this? Is this intended behavior or a bug?
    Note: I would provide the page but it is within a secure zone that charges a membership thus I cannot post access to it publicly.

  • Event structure triggered by multiple events

    I have an events structure where one case needs to handle a button
    press from any of three controls from the front panel.  When i
    press any of the three buttons, the program is going into the correct
    event case.  However, once i am in the correct case, i need to
    know which button was pressed so that i can perform slightly different
    tasks?  Any ideas?
    Kind Regards,
    Bryan

    There are many possibilities. Attached is one simple example (LabVIEW 7.0) that does not use control references.
    (If only one of the buttons can be active at any time. you could also use a single radio button as a control)
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ComboEvent.vi ‏35 KB

  • Daqmx "Done" event not triggering event structure

    I would like the user to be able to abort my daqmx task by pressing a button.
    I am attempting to use the method in this VI:
    https://decibel.ni.com/content/docs/DOC-15815
    It utilizes an event structure with the daqmx Control Task VI to abort.
    The example VI above works for me, on my system with my USB-6356 device, as expected.
    When I attempt to incorporate the same method into my VI it does not--despite having an identical arrangement, so far as I can tell.
    I believe that my problem lies with the event structure, and the dynamic registration.  I am unfamiliar with this and must be using it incorrectly.
    I have attached my VI, though it is cumbersome.  The code which I am struggling with is in the "Acquire" case.  As far as I can tell, I am doing exactly the same this in this particular case as in the example mentioned.  Yet in the example, the event structure completes, or aborts, whatever you want to call it, right after the "Wait Until Done" VI executes.  In my own VI, the "Wait Until Done" and "Clear Task" VIs execute, but the event structure does not register it.
    Here are my specific questions: is there anything extra or special that one must do in order for the Task to properly trigger a "Done" event and pass through the event structure?  At what point is the daqmx task "Done"? 
    thanks,
    Matt
    Attachments:
    BoomTubeMain.vi ‏175 KB

    natasftw,
    My event structure is identical to theirs; what you are seeing are the two different cases that exist in the event structure.  In both the example and the VI, there is a <task out>: Done and a "Dynamic Event": Value Change.  In the dynamic event case, I have my abort button and relevant code--this I believe is the code you were referring to, which you thought I was missing...  Regarding my multiple event structures, they should operate completely independently as they respond to different events.

  • How to implement boolean comparison and event structure?

    Hello all,
    I'm currently developing an undergraduate lab in which a laptop sends out a voltage via USB-6008 to a circuit board with an op-amp, the voltage is amplified, and then sent back into the laptop. The student is going to have to determine an "unknown" voltage which will run in the background (they can do this by a step test, graph V_in vs V_out and extrapolate to the x-axis).
    Currently, I have two loops that are independent in my VI. The first loop is used to "Set the zero." When 0 voltage (V_in) is sent out of the laptop it returns a value around -1.40V (V_out) typically. Thus, I created the first loop to average this value. The second loop, averages the V_out values that come into the laptop as the V_in numeric control changes. Then I take the "set zero" value from the first loop and subtract it from the second loop average to get as close to 0V for V_out when V_in is 0V.
    The problem I'm facing is, the event structure waits for the V_in numeric control value change, but after "SET ZERO" is pressed, if there is an unknown value, it will not be added to the average for V_out until V_in is changed by the user. So, I tried implementing a comparison algorithm in the "[0] Timeout Case." This algorithm works for step tests with positive values for V_in, but there are two problems.
    1) Negative values cannot be used for V_in
    2) If a user uses increasing positive values for V_in there is no trouble, but if they try to go back to 0, the value change event has been called and it is added to V_out as well as the timeout case.
    Sorry for the extremely long post, but I've been banging my head over this and can't figure out how to properly implement this. I'm using LabVIEW 8.0.
    Attachments:
    Average Reset Test.vi ‏371 KB

    OK you have bigger problems than Raven's Fan is pointing out.
    When the first event loop stops ( after pressing "") (the boolean text is "Set Zero")  The second loop may start- (AND PROCESSES all of the events it was registered to process before the loop started!)  that would enclude the value change event from "" (The boolean text is Stop) Being pressed bebore the loop started.  Of course, since the labels of "Set Zero" and Stop are identical nulls....................................................BOTH event trigger at the same time and are processed as soon as the event loop they are registerd to is available.
    Get it ... The two buttons labeled "" both queue Value change events to both loops registered to act on the value change of the control labled ""!
    Both loops will do what you programmed in the case of "" Value Change!  This can, (as you have observered) lead to confusing code actions.
    Do avoid controls with duplicate labels (There is a VI Analizer test for that!)  Do avoid multiple event structures in the same hierarchy. 
    DO NOT bring this to your studients to help you learn LabVIEW!  We get enough studii asking embarassing questions
    VI Analizer will help you provide sound templates.  If you need help with that hit my sig line- e-mail me and I'll always be willing to help.
    Jeff

  • No more than 2 event structure?

    I don't anderstand how can I do my programm because I read that we must not use 2 events structures in one loop. But concerning my programms for instance I have to fill arrays only when I press each appropriate "Ok" button (for instance for 5 case I have to press 5 different OK button ) and so on (when I press OK number 6 the program write to excel program.. when I press OK number 7.. )
    How can I do it? I need to create 7 events structures for 7 actions?
    labview 7.0

    When they say not to use two event structures in one loop they are refering to the number of actual "event structures" that are dropped on to the diagram, not the number of events that one structure can handle. You could have "an event" configured for each of your "ok" buttons, and then have those events, when triggered, select a different case of a case structure, possibly on the "timeout" event. If you built it like that, make sure to have a timeout value wired to the upper left corner, or it will default to -1 (never timeout).
    Here is a very simple example of one way to implement it.
    Putnam
    Certified LabVIEW Developer
    Senior Test Engineer
    Currently using LV 6.1-LabVIEW 2012, RT8.5
    LabVIEW Champion
    Attachments:
    simple event.vi ‏36 KB

Maybe you are looking for

  • Chroma keying - Motion 5 vs Adobe: which is better?

    Has anyone compared chroma keying with Motion 5 vs Adobe Premiere Pro cs5.5 or even Afer Effects cs5.5? Are the advanced features in M5 just as good as ultra keyer in Premiere Pro or Key light in AFter Effects? I am looking to do vids with lots of gr

  • Reverse invoice in MIRO

    Experts, if I want to reverse a invoice which is already entered into MIRO, how must I proceed ? Thanks in advance Jörg

  • Using Automator for photography file needs

    I've been looking on here but can't find a way to do what I need done exactly. I shoot in both raw and jpeg and I want to be able to run one action on a folder to do the following. Arrange the files in a folder by name and in ascending order. Create

  • VIDEOS HAVE NO SOUND?!??? HELP!

    I have a 30GB Video Ipod. I was trying to put the movie Click on it. I converted it to the Ipod format and then put it onto my ipod. Everythings fine right? Alright so once it was on there, and I tried playing the video to test it, it didnt have any

  • Shuts down when waking up

    When I go to wake the computer up, it often shuts down and necessitates a reboot. Probably happens half the time. This will also be cross-posted in the OS discussions. Can anyone help?