Event structure or case structure

I have some case structures wired to buttons.  When each button is true, code inside the corresponding case structure executes.  `What are the advantages/disadvantages of using an event structure instead of a case structure?
Ron Deavers, CLD

Place an indicator for the iteration terminal of the main loop to see an obvious difference
Your case structures must be in a loop that constanty runs. If you don't put a delay in the loop, it consumes all CPU, but if your delay is too long, it takes a moment to react to the button changes. The loop spins all the time, no matter if you press buttons or not.
Your event structure also sits in a loop, but nothing happens until you press a button. Now the event structure triggers IMMEDIATELY, executes the event case, and then waits for the next event. The loop does not spin unless needed.
You can even mix the functions by using a timeout event. Code in the timeout event occurs at regular intervals, but at any time, any of the other events can take over.
LabVIEW Champion . Do more with less code and in less time .

Similar Messages

  • 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

  • Transfering a case structure to event structure

    Hi, I am trying to transfer case structures that are currently set up to a control that if on prompt the user where to save and then save all following files to that location till end of program and if off the do nothing. I would like to enable these to be switched on and off at any point and know to use an event structure. The problem is I am new to coding with an event structure and have been able to get the button to work but not continuously save. I attached a screen shot of the original case structure and was wondering if someone could show me how to change it to the event structure format with the same functionality. I'm getting a little lost and confused. Thanks!
    Attachments:
    alltruecases.jpg ‏534 KB

    I can't attach the vi due to the size and I do not think a simplified piece of code is going to help. I did however go through and stitch two jpegs together of the main two sequences. hopefully this gives a better idea of what I am trying to do and where to go from here. thank you.
    Attachments:
    1.jpg ‏669 KB
    2.jpg ‏317 KB

  • Event structure vs case structure?

    I am developing an application that is fairly user input based... lots of boolean control buttons to do different things.
    In the past, I have avoided "value change" event structures, and instead went with a while loop, stacked sequence, and series of case structures. After having done it, I decided this was a terrible idea. This time, I intend to build an array from the booleans, convert it to a number, and feed it in to a single case structure. This will give me the option to add cases for different combinations of the booleans being pressed.
    I guess the question is: What is the best method for doing something like this?  Does one have advantages over the other?
    Edit: I wasn't that clear.  I would like a comparison between the "value change" event structure method, and just feeding everything in to an array -> case structure.  I also am worried that with the bool array -> case structure that I will run in to problems where I end up with too many control variables, and the value of the resulting number gets ugly very quickly. The application has several buttons... next, last, save, load, several different configure setup buttons etc.
    Thanks!
    Solved!
    Go to Solution.

    Aalenox wrote:
    I am developing an application that is fairly user input based... lots of boolean control buttons to do different things.
    In the past, I have avoided "value change" event structures, and instead went with a while loop, stacked sequence, and series of case structures. After having done it, I decided this was a terrible idea. This time, I intend to build an array from the booleans, convert it to a number, and feed it in to a single case structure. This will give me the option to add cases for different combinations of the booleans being pressed.
    I guess the question is: What is the best method for doing something like this?  Does one have advantages over the other?
    Edit: I wasn't that clear.  I would like a comparison between the "value change" event structure method, and just feeding everything in to an array -> case structure.  I also am worried that with the bool array -> case structure that I will run in to problems where I end up with too many control variables, and the value of the resulting number gets ugly very quickly. The application has several buttons... next, last, save, load, several different configure setup buttons etc.
    Thanks!
    Event structure. Among other things, it will allow your loop to "sleep." then wake up when an event happens. With a case structure it's going to be constantly polling. Event structure is pretty much always the right way to go in newer versions of LabVIEW that have it available. I assure you, your first solution was aboslutely wrong and you noticed that, your second is better and was common the way before event structures existed, now that event structures exist, you should go with those.
    CLA, LabVIEW Versions 2010-2013

  • Add event cases to an event structure using scripting

    Hello,
    Iam trying to (using scripting) update an event structure (add event cases) on a vi that is not on memory.
    i get error 1054 The specified object was not found.
    here is a picture of it.
    any help in this will be greatly apreaciated.
    Solved!
    Go to Solution.

    Another suggestion, the following VI is a wrapper for Traverse for GObjects VI and allows you to specify the name of the object you want. I always use this VI, I never use the Open VI Object Reference function, for the reasons tst mentioned:
    vi.lib\Utility\traverseref.llb\TRef Find Object By Label.vi
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman

  • Case order of EVENT structure

    LV 8.2.1 - Regarding the order of cases in an EVENT structure:
    1... Is there any performance (speed) advantage to having the most-commonly used events near the top of the list?  Does it have to search through a list to find which case to execute, or does it happen some other way?  If it searches thru a list, then I want to have the high-frequency events near the top of the list, and the rarer ones nearer the bottom.
    2... If #1 is "no advantage" then what is the point of the REARRANGE CASES dialog?  Why would I want to rearrange them?  Maybe just to collect them into groups of similar function - is that all?
    3... When you SORT CASES in the REARRANGE CASES dialog, what order does it put them in?  The help window says "alphabetical" , but that's plainly not true, because my list includes "Stop" and "Clear", and it orders "Stop" before "Clear" after a sort.  It doesn't put the user events together.  A simple test shows that SORT puts them back in the order you added the cases to the structure.  Is there a point to that?
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

    is it possible you have some invisible chars (like a leading space) or that one of the words starts with an uppercase letter and the other with a lowercase one?
    Nope.  Try it yourself with the Wed, Thur, Friday trick.
    The EVENT structure cares about what order you created the cases in.
    The CASE structure cares about the order of whatever drives the selector.
    Alphabetic order seems to have nothing to do with it. 
    From your reference thread:
    However, this does tell you that if you want to squeeze every ounce of performance out of your event-handling code, make sure the most frequently run event-handling diagram is the first one in the list.
    This from a LabVIEW R&D engineer.
    Hmmm. 
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

  • Passing values between event structure cases

    Hello everybody,
    I have a question concerning the event structure  - how to pass values (let's say a string / the state of a boolean control / the value of a numeric control value / an array of numeric values) between event cases ?
    There seem to be 2 situations here  :
    - when you need to pass the value of the control that triggers an event;
    - when you need to pass the value of a control which is modified in an event case.
    I have read the documentation but i still do not understand very clearly how to do this. Maybe you can point me in the right direction (maybe some threads on the forum that i have missed).
    Thank you very much !!
    (KUDOS for everyone who is interested in this )

    AndreiN2014 wrote:
    - when you need to pass the value of the control that triggers an event;
    - when you need to pass the value of a control which is modified in an event case.
    The first question isn't worded very well.  What exactly are you looking to do?  Are you looking for an event that specifically relates to that control?  If so, just drop it inside of the event and wire it.  Are you looking to trigger multiple events from the same control?  Ie, you hit the control, event1 is triggered which then triggers event2 ... ?  If so, you might consider taking a look at a different architecture.  I can think of very few cases where I'd prefer do this over something like having the button trigger a state and using the state machine architecture. 
    Others have pointed out the Shift Register.  This is the typical way to pass values between one iteration of a loop to another.  We can assume you have some sort of loop outside of the event structure to make it run a second time.  Put a shift register on this loop and the value wired into it will pass each iteration.  But, if it's just a random control, you can also just leave that outside of the event structure and wire it in as well.  This will provide the new value to the next occurrence of the event structure.
    You really need to define your problem before trying to solve it.

  • Extent of Coding inside Event Structure cases

    Hi all
    I am trying to understand the practices while using an Event Structure. I am used to developing most of my projects using an Event driven State Machine Architecture. Most times, I use Event driven-Queued State Machines. I have also used Producer Consumer Architecture with Event structure driving the producer.
    I have always believed that using lots of code, or lots of sub-vis inside one or more cases of an event structure is not a good practice. I reasoned that it will delay the capture of other events occuring while the current case is still executing. This was one of our points during design review, i.e., to reduce the code inside event strucutre cases to as minimal and necessary as possible. We used clusters/queues/LV2Gs inorder to pass on the required data, which will be processed in the other cases/loops.
    However, I happened to recently come across a couple of very old applications upgraded to LV2011. The applications used an event structure in one of the while loops, with one or more parallel while loops inside the Main VI. The event structure was the only code in this while loop, no case strucutres.
    These event structures had loads of code in each case, with sub-vis and nested sub-vis, even DLL function calls among them. Thats when I started to look for information on best practices using event structures and about any available details on the extent of coding allowed inside an event strucutre.
    One sub-vi which was called as a dialog box also had its own event structure (ending up as ensted event structures). I have read about nesting event structures and their disadvantages.
    Off course, the code is working and I am not sure if anyone had any execution problems with the applicaiton.
    However, I am wondering about the pros and cons of having the entire code inside event structure. I would have defined that code a nightmare. Its disturbing me to see that code and being unable to make it better.
    To my understanding, I wish to know if there is any definition or rule regarding the amount of code inside an event structure.
    Thank you

    The exception I use is User driven intefaces where every user action must get a response and each change must complete before the next. In those cases an event only implelmentation is generally fine.
    Now if that code does something that takes long enough for the user to question if the program is still alive should at least get a "Busy cursor" OR a progress bar OR an abortable progress bar where the user get s the option to abor out. THe last case may warrent a parallel process to crunch the numbers.
    But please keep in mind the above suggestions apply only to those User only" type things. Applcations that invlove the word "while" will generally get deamons and other common design patterns used to henld the implementation. But now I have drifted to design teory and away from the subject so ...
    Have fun!
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • How to Transition to a Specific Case from an Event Structure Trigger?

    Can someone help me troubleshoot my program. I've attached my VI so you can follow along with what I am describing. So here is the scenario:
    I have a program that consists of four test states, stop test, request test info, and end program (cluster of 7 booleans). Each test state sends a serial command to a DUT, receives ACK packet, opens relays which disconnects the serial connection and DUT will continuously test by itself. If the user wants the end the test early, they can hit the "Stop current test" which will close the relay reestablishing serial communication, wait 10 secs for device to enumerate on the PC, and then send the serial command to stop the test. From here, the user can request test information from the DUT by hitting the "Request info" button.
    So my dilemma is when I try to implement a time limit for cases 2 - 4. For case "M1-Idle", the program works flawlessly since there is no time limit. The program will send the serial command, transitions to "Open Relay" case and switch back to the "Idle" state to wait for the "Stop" command. The user has to hit stop whenever to close the relay, request info and/or continue testing.
    For case 2 through 4, there is max time limit of 3 hours. This is where I am having difficulty opening the relays and then entering the timer count down case structure to start the timer. Question is, if I am using the Event Structure to trigger on a user action event (i.e. user presses "Run M2-Normal" - Menu.M 2: Value Change) it sends the command and move on to "Open relay" to break the serial connection as intended. Since the next state of "open relay" is "Idle" how can I add case selector to select "M2 - Timer" instead of "Idle" given that it was based on user selection of "Run M2" event?
    Is that even possible? I tried using the feedback node on the state enum but its coming from the case state and not the event state so it doesn't enter properly into the timer state. Any help or ideas is greatly appreciated. Thanks in advanced.
    Main_Working_Copy.vi is the main portion of the program.
    Best regards,
    Henry
    Attachments:
    Main.zip ‏106 KB

    Hi Ofek_zeevi,
    Welcome to the Support Communities!
    The article below explains how to gift a song in the iTunes Store.
    Some songs are not available as an individual purchase.
    iTunes 11 for Mac: Give music and video
    http://support.apple.com/kb/PH12293
    I hope this information helps ....
    Have a great day!
    - Judy

  • Case structure & event structure

    1.What are the disadvantages of case strucure?
    2.What are the advantages of event structure?

    Are these test questions? I could name 10 for each, but why are you asking?
    While there are often many ways to accomplish the same thing, Case structures and Event structures serve different purposes. Straight from the Help file:
    Case Structure
    Has one or more subdiagrams, or cases, exactly one of which
    executes when the structure executes. The value wired to the selector terminal
    determines which case to execute and can be Boolean, string, integer, or
    enumerated type. Right-click the structure border to add or delete cases. Use
    the Labeling tool to enter value(s) in the case selector label and configure the
    value(s) handled by each case.
    Event Structure (Not in Base Package)
    Has one or more
    subdiagrams, or event cases, exactly one of which executes when the structure
    executes. The Event structure waits until an event happens, then executes the
    appropriate case to handle that event.
    Right-click the structure border to add new event cases and configure which
    events to handle. Wire a value to the Timeout
    terminal at the top left of the Event structure to specify the number of
    milliseconds the Event structure should wait for an event to occur. The default
    is –1, indicating never to time out.

  • Trigger Event Structure Case on Startup

    Hello,
    Within my project, I am controlling a linear actuator via Modbus TCP, with an event structure within a loop.  I control its velocity, acceleration ... etc.  It works beautifully, but I must change the values of the mentioned parameters to trigger the event cases, after startup.  I would like to trigger the event on startup of the program and take the current values on the front panel.
    I have heard about "Property: Value(Signaling)", but I cant seem to understand it and how to implement it..
    Any guidance and help would be appreciated!
    Thanks,
    Danny

    It won't work for you because you already have something designated for the timeout case, and you want a different event case than that to run on startup.
    But, here is the explanation.
    At the top left of the event structure is the timeout terminal.  The number you wire in there tells how frequent the timeout case could execute.  If you put a 0 constant outside of your loop and wire it into that terminal through a shift register, it will execute immediately or almost so.  After the event structure, wire a -1 into the right hand shift register.  Then after successive iteration, the timeout case will be disabled.
    Attachments:
    Example_VI_BD.png ‏12 KB

  • Is it better to have one Event Structure with more (10 or 15) cases or several with fewer?

    I have several buttons and events on the GUI of my app to monitor. Would it be better to use one Event Structure with several cases (10 or 15) or have a couple and split the cases evenly? None of the cases have much processing to handle, so there is not a time lag issue. I am just worried about overloading the structure. One of the tech support guys mentioned that the event structures are not that hard to get confused.
    Has anyone had any problems with Event Structures?

    I use event structures very often in my code. I use them just to handle the interface and to run small code. I have had event structures that handled over 50 user interface events and never had a problem. In my personal opinion If there was any code to run I would let the event structure handle the the user interface event that fired a que in another while loop that handled the code.You can find examples on this, if not I will send you one. It is just good programming practice for beginners because it will alow you to build more robust VI's in the future.
    Hope this helps
    Joe
    Joe.
    "NOTHING IS EVER EASY"

  • Switching from case to event structure

    I once down converted some LV 7.0 code to 6.0 and it (automatically) converted an event structure to a case structure.  When trying to upgrade some code to change a case structure to an event structure, I didn't see any means for doing that (a flat sequence, yes... event structure, no).
    Is there a way to convert a case to an event structure -- if not, why not?
       ...Dan

    No, the question is very valid!
    The resulting code does not need to make sense immediately, but I have desired this functionality (=convert case structure to event structure) at several occasions. I have many legacy programs that were made before the introduction of the event structure. Some contain big case structures with many cases, one is the "idle" case which only contains a small wait statement, while others are executed if certain controls change their value. (Sort of a poor man's event structure emulation ). Upgrading this old code would require a simple replacement of the case structure with an event structure so each event case contains the code of one of the original cases, followed by a quick manual cleanup (assignment of the event triggers, etc.).
    Without such a conversion tool, my code upgrade is major work, especially if there are many cases and dozens of shift registers crossing the case structure. Basically, I need to rebuild things from scratch.
    Summary: It would be useful to be able to easily convert between event structure and case structure and vice versa using a "replace" command. I even remember asking for this functionality.  I would use it!
    LabVIEW Champion . Do more with less code and in less time .

  • Event structure inside a case structure

    Hi,
    I've got a problem w/ my porgram, and managed to boil it down to this
    simple example.  The program basically hangs if you change the
    Numeric value when the boolean is false.  I don't understand
    why.  I suspect it has to do with the way event structures are
    treated, but if someone cou please explain this I'd be greatful.
    Also, now imagine I have 7 numeric controls, handled by 7 cases in that
    event structure, and I actually want to do things in response to the
    value change for each.  Can someone suggest an elegant way to do
    that?  I thought what I had here was a good design, but apparently
    not.
    Bjorn
    (I'm using labview 7.1)
    Attachments:
    EventInCase.vi ‏24 KB

    It is generally a bad idea to place event structures into cases. Events structures need to be able to breathe.
    Maybe you can redesign your program and place the case structure inside the event structure, for example? (Also have a look at the online help for the event structure, especially the link "caveats and recommendations for using events ".)
    Detailed analysis:
    Your event case for the numeric is set to "lock front panel until event completes".  If you change the numeric while the case is false, the evet structure cannot execute, so the front panel locks forever. The observed behavior is as expected. All clear?
    In addition, if the case is false, the main loop spins at nearly infinite rate, consuming all available CPU. Place a small wait to be more cosiderate to everything else running on your rig.
    LabVIEW Champion . Do more with less code and in less time .

  • How can I determine whether to use an event structure or a case structure?

    I'm starting a large project and need a state machine. I can't decide on whether to use a case structure or event structure. Is there an article  or other information that describes criteria for selecting between the two approaches?
    Thank you,
    Chuck
    Solved!
    Go to Solution.

    Hi Chuck,
    Well case structures and event structures differ quite alot.  Here's a link for indepth information on Event Structures, and using them in state machines: http://zone.ni.com/devzone/cda/tut/p/id/2962.  Hopefuly this will help you make up your mind.  
    Let me know if you have any questions after reading it. 
    Regards,
    Dominic Walker
    Cardiff University
    Electrical and Electronic Engineering Student

Maybe you are looking for