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 .

Similar Messages

  • 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.

  • 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!

  • 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

  • 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

  • Let all channels(with same data structure)run one program

    Hello,
    I want to let all channels with same data structure run one program,how can i program it?
    Thanks!

    Hi charleen,
    You're going to need to provide more details for us to help you.  In general "channels" do not "run" programs.  You can, however, run a program which loops over channels, checks their properties, and decides whether to include them in the overall analysis.  What do you mean by "data structure"?
    What do you want to actually happen in the "program"?
    Brad Turpin
    DIAdem Product Support Engineer
    National Instruments

  • 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

  • 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 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 GUI's in One Program

    Hi, I am building some Java GUI's and I have a query/problem. I have set the windowClosing(WindowEvent e) method to hide frames (when the x button is clicked) rather than close them ...
    public void windowClosing(WindowEvent e)
    { setVisible(false); }
    I then have a statement in my main class to say that if all windows have been hidden(thought to be closed),then when the last one is closed, exit the program.
    So for example with 2 frames, i have a statement
    if(observable.setVisible(false) && obs1.setVisible(false))
    { System.exit(0); }
    where observeable and obs1 are the frames. for this I get an error "'void' type not allowed here if(observable.setVisible(true) != true"
    So my question is, should I be doing this a different way or what am I doing wrong.
    The Reason that I am trying to do it this is that I am using Inheritance for some of the Frames so I guess that they are not all independant of one another, therefore if I close one of them, they all close and the program exits.
    Any help gratefully appreciated.

    As the previous post says, you shuld replace setVisible with isVisible in your code: if(observable.setVisible(false) && obs1.setVisible(false))
    setVisible is a method that returns "void" or said in other way, does not have return.
    That's why you get the error "'void' type not allowed here", because the method setVisible constitutes an expression of tipe "void", and this is not allowed in an 'if' statement, only boolean expressions.

  • How to use multiple visa read in one program

    hi
    i am working at Hameg HM8143 power supply i want to measure voltage and current simultaneiously and use the measured values for further calculations. for this i used two visa read blocks.
    >>>>>>the measured values are shown in the same visa read string however i want it to be shown sepetately,
    >>>>>>One of the VISA read block gives error. so i want to know how to use VISA read to get current and voltage simultaneously in seperate strings
    >>>>>>than how to convert strings to numbers  for using them for my calcultions.
    i am attaching screen shot as well
    Attachments:
    screenshot.JPG ‏164 KB

    you can not use a single serial to send 2 commands simultaniously?
    There is a single serial line so one command has to be before another.  This doesnt mena that you can not read from 2 seperate threads but will have to ensure that there is a locking mechanism to make sure that your queries are atomic.  In labview encapsulating all communications can be done with an action engine which will allow for concurrent execution with automatic blocking of your resource (serial device).
    Paul Falkenstein
    Coleman Technologies Inc.
    CLA, CPI, AIA-Vision
    Labview 4.0- 2013, RT, Vision, FPGA

  • 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.

  • Please help with structure of my program

    I am hoping someone can help me with a motor control program that I am
    writing.  The program is too large to post here, but I attached a
    rough outline of the program.  I think the problem is with the
    higher level logic, so hopefully that will provide the necessary
    information. 
    I have a front panel with lots of buttons to control the motors (eg:
    power, stop, start).  There is an event structure that contains
    most of those buttons (power, start, etc), but if that structure is
    exectuting, the other buttons won't work.  I need to be able to
    stop the motors and exit at any time (for safety), so I made another
    event structure that contains the stop and exit buttons.  Is this
    the right way to do this?
    Also, I want all the loops in the program to run continually until the
    exit button is pressed.  Since the exit button actually calls
    exit.vi and closes the whole program, I just wired a F constant to the
    stop on the while loops so they never stop.  Could this be causing
    my problems? 
    Hopefully I provided enough information here, but if not, please write back and let me know.
    Thanks,
    Kasey
    PS. In case anyone wonders why the whole thing is in a sequence, I need
    it for other aspects of the program (safety lights, etc...).  I
    doubt it makes a difference, but I wanted to include it.
    Attachments:
    screenshot.jpg ‏258 KB

    This is the first time I have seen a case where it is useful to have two or more event structures in one program.  Since they are in separate parallel loops, I would think there would not be a problem.  I like the idea that the program can be stopped in the middle of an event, for safety reasons.  Great structure, Kasey.  The only thing I would add is to make sure that your exit vi gracefully shuts down the program.  Like if files or references are open, they get closed before terminating the vi.  Just be on the look out for race conditions since you have 3 events that can happen at one time.  One event might affect some indicator that is being handled by another event.  Also, instead of wiring a false to the other loops, maybe you could use local variables of one general stop boolean.  Since your exit vi stops all execution, it may not make much of a difference.
    - tbob
    Inventor of the WORM Global

Maybe you are looking for