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

Similar Messages

  • How to read shared variables inside event structure ?

    Hi,
    I have a problem that my shared variables do not update inside event structure. The program(s) I am trying to get working is seen in the attached screenshot. It works as follows:
    0. I start the vi that is unsquared.
    1. I write a string to a shared variable using vi in red square. I make sure that its updated using write-wait-read.
    2. I run the other vi (blue square), this changes the boolean shared variable.
    The unsquared vi has been running the whole time, it has event structure bind to boolean shared variable change (the one in blue vi). After I have runned the blue vi, the unsquared vi should change the indicator values to match the ones in red vi. However I have to start the blue vi multiple times to get it to change, sometimes even 6 times.
    Also, when I change the value in red vi to a third value and start blue vi multiple times, the unsquared vi shows all the variables. I.e. I put "cat" to red then start red, put "mouse" to red then start red,... and then start clicking blue... Unsqured shows cat, mouse,..., dog (dog is the default).
    How can I force the shared variable to update inside event sructure. I want the current value of the variable, not some historical values.
    Attachments:
    Screenshot-5.png ‏108 KB

    Found the buffering... disabling it solved the problem... thanks.
    FYI, there is another solution that I just found out... attached. Adding timeout to the event structure and the variable read outside the event structure... This makes the shared variable strings (one that is read outside and the otherone that is read inside) different.
    Could someone explain why the variables are in different state even if they are used in the same place and looped with 10ms intervals?
    Juha
    Attachments:
    Screenshot-6.png ‏110 KB

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

  • 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

  • Event structure, case structure, iteration number

    Hi
    I am trying one example about Event Structure from the book,  LabVIEW for Everyone: Graphical Programming Made Easy and Fun. 
    The example in the book looks like this:
    The number of 'work done' equals 'iteration number'.
    But when I build a Vi and try this example, I got this:
    iteration number is two times the 'work done'.
    I have attached my Vi. Does anybody know what's wrong with my Vi
    Thanks
    Bing
    Solved!
    Go to Solution.
    Attachments:
    do some work.vi ‏10 KB

    Both Activation and Deactivateion of the boolean causes Value Change events, but you only add 1 when it's activated. If you set the booleans mechanical action to Latch instead of Switch they should be the same.
    /Y 
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • Run for loop inside event node

    Hi all, 
              We want to run for loop inside event node with 50ms delay. But when i am doing it the Labview is crashing. Please let me know if somebody did this.
    Thanks in advance,
    Regards,
    Harish. G
    Thanks & Regards,
    Harish. G.

    harishg92 wrote:
    Hi all, 
              We want to run for loop inside event node with 50ms delay. But when i am doing it the Labview is crashing. Please let me know if somebody did this.
    Thanks in advance,
    Regards,
    Harish. G
    You're implementing a For loop inside an event structure? (I don't know of any event "node" in which you can run a For loop)
    If so, that's a bad idea because LabVIEW won't be able to process any events while waiting for your For loop to get done, which might be why its crashing.
    There are tricks to accomplishing what you're trying to do without putting any for loops inside event structure. See what I have  attached and if it helps. "N" is number of times you run your For loop, timeout is whatever delay you want in each loop. This can be done in many ways without adding delays in events, another way could be to fire a separate subVI using Asynchronous call (without waiting for the VI to finish) during those delays, just make sure that such subVI finishes processing within your allocated time (that's how I'd ideally implement things). That method is better because you're doing minimal work inside events structure while using wait period wisely in a separate/parallel process.
    I hope that I understood you correctly and did not go off on a tangent.
    -BTC
    New Controls & Indicators made using vector graphics & animations? Click below for Pebbles UI
    Attachments:
    ForLoop inside Event Structure.vi ‏11 KB

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

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

  • Start event from case structure

    I'm running my main programm inside an event of an eventstructure.
    Beside this main event I additionally have 3 other events in this event structure.
    To save "screen space" I would like to start indirectly one of my other events from a case
    placed inside another event.
    Is this possible - would be glad if you have an example.

    You are still completely misunderstanding the purpose of the event structure (see also my answer the other thread).
    The main code of the program does NOT belong inside an event structure. What good is an event structure if it is tied up indefinitely inside one of the event cases???
    An event structure is most useful for dealing with interactions by the user and must be ready to handle those at any time. It is not a tool to "save screen space" (whatever that means). If you are running out of diagram space, consider wrapping your code segments into subVIs.
    LabVIEW Champion . Do more with less code and in less time .

  • Simple example - Break FOR loop inside an event structure based on Front panel event change.

    I am running a for loop inside a state machine architecture that contains a FOR loop. How can I break this For loop based on Event change in front panel ??
    Abhilash S Nair
    Research Assistant @ Photonic Devices and Systems lab
    [ LabView professional Development System - Version 11.0 - 32-bit ]
    LabView Gear:
    1. NI PXI-7951R & NI 5761
    2. The Imaging Source USB 3.0 monochrome camera with trigger : DMK 23UM021
    OPERATING SYSTEM - [ MS windows 7 Home Premium 64-bit SP-1 ]
    CPU - [Intel Core i7-2600 CPU @ 3.40Ghz ]
    MEMORY - [ 16.0 GB RAM ]
    GPU - [ NVIDIA GeForce GT 530 ]
    Attachments:
    Case inside Event 3.vi ‏19 KB
    Case inside Event.ctl ‏6 KB
    Case inside Event 2.ctl ‏6 KB

    Okay. Accpeting that the design is not favorable and not advantageous when my program expands. I have begin to follow producer/consumer programming architecture.
    Please find the attached program which is a simple producer consumer with event structure. I wonder how could I stop looping around the producer and consumer loops over and over again. I am pretty sure that this ENQUEUE ELEMENT loops back to the consumer loop and starts from begining.
    I hope my first program in PC architecture with State machine and Event structure is correct. 
    Abhilash S Nair
    Research Assistant @ Photonic Devices and Systems lab
    [ LabView professional Development System - Version 11.0 - 32-bit ]
    LabView Gear:
    1. NI PXI-7951R & NI 5761
    2. The Imaging Source USB 3.0 monochrome camera with trigger : DMK 23UM021
    OPERATING SYSTEM - [ MS windows 7 Home Premium 64-bit SP-1 ]
    CPU - [Intel Core i7-2600 CPU @ 3.40Ghz ]
    MEMORY - [ 16.0 GB RAM ]
    GPU - [ NVIDIA GeForce GT 530 ]
    Attachments:
    Case inside Event 3.3-ProducerConsumer Event.vi ‏25 KB
    Case inside Event.ctl ‏6 KB

  • Stopping an event structure inside a while loop.

    I am relatively new to LabView, and especially the event structure. I have been looking at previous posts regarding the event structure and people having trouble stopping it. In my VI, I have two event cases in addition to the timeout. I am using this VI for stepper motor control. I have 2 buttons (for each case), one for movement to the left, the other to the right. It runs like it is supposed to, but when I try to stop it I have to press both buttons before it stops. As if the loop has to execute everything inside before stopping.
    In my VI, how can I make the execution stop when I press the stop button? I tried many setups of the stop button and boolean logic (which I believe was correct) but am now stuck.
    Thank you very much ,
    Alek
    Solved!
    Go to Solution.
    Attachments:
    motor control2.vi ‏24 KB

    OK, here's my simplified version. All you need is two event cases.
    Note that (with a tiny difference), the "left" and "right" cases are identical, so they can be handled in one event, reusing most of the shared code.
    We don't need a timeout event
    Just some extra tweaks...
    Message Edited by altenbach on 06-23-2008 05:09 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    RightLeft.png ‏13 KB
    motor_control2MOD.vi ‏15 KB

  • Event in case structure

    Dear all,
    I am using Event Structure in a Tab Control.
    On page 1, there is a Table Control and when the mouse is clicked on it, it returns the Cell Value. The event is working ablsolutely fine, but the problem is i have no idea how to Stop the Event.
    I am attaching my Vi here. Pls have a look at it and let me know of a possible solution.
    Thanks,
    Ritesh
    Solved!
    Go to Solution.
    Attachments:
    Event in Tab.vi ‏18 KB

    ritesh024 wrote:
    But, it means that the Events in Page 1 are getting triggered even when the Control is on Page 2.
    That would take the unnecessary memory and time as there is no need for the events on Page 1 to run when the Control is on a different page.
    No, the event will not get "triggered", because if you are on the other tab it is impossible to fire the table event and a mouse up cannot occur. The event structure is in memory no matter what and placing it inside a case structure only complicates the code and can will lead to problems.
    The event structure should always be in the dataflow, the tab position is irrelevant. Never hide an event structures inside a case structure!
    Here's a quick example (LV 8.5). Tab 1 has your table and senses the cell position. Tab 2 has a light switch. As you can see there is no case structure needed.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Event_in_TabMOD.vi ‏19 KB

  • 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

  • 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

Maybe you are looking for

  • Firefox won't open even when running.

    I have version 34.0.5 updated 12.19.2014. Click on it several times. Sometimes open after many hours of waiting. Run Norton utilities weekly to clean computer. Read your articles. Solution requires going on Internet. How can I do that when Firefox do

  • Trouble with organizing VIs to be used in multiple applicatio​ns? Is there a best practice?

    Question...basically, about best practice.     I have made a VI that I use very often in many different applications.  (a special path stripping thing for help with executable stuff)    Right now, I have used it in so many places always making a copy

  • Free transform tool is not working

    Hi, I'm getting this error every time I try to use the free transform tool, the window doesn't show all the options, the white space where you manipulate the vector has a very low quality image and won't let me move anything. I've tried with diferent

  • Why can't i view my hard drive anymore?

    I used to be able to open and browse through my hard drive, after updating to mavericks many of my filed are gone, no idea where they all ended up, but i would really like to acutally see my hard drive, not just my user account! i had games in the li

  • Drivers that are currently installed but its not familiar and theres no drivers being inserted

    please help me what should i do.. is that a virus?? cuz i been seeing this drivers in my laptop but i havnt partitioned or inserted any drivers but then i still see drivers that are not familiar with me...theres 3 drivers or more please im afraid tha