Successive run - Event Structure

Hello...
I have a simple question. Sometimes we want to use Event Structure and put only a piece of the code in each case. The problem is that a case might have only math code, without any control, indicator or array. Because of this, this case will not have any "thing" that can trigger its execution. 
To avoid this and allow me to control in arbitrary form the execution of the cases, I created a simple code where I can specify which case will be runned after a especific case.
Attached there is a example just to show how it works.
My question, is there a better way to do this?. I mean, specify that after one specific case runs, another specific case will run.
Thanks in advance.
Dan07
Attachments:
Event Structure Run.vi ‏30 KB

There are various problems with trying to use the event structure itself to be the case selector for a state machine:
You can't guarantee that cases will execute in a particular order, because other registered events could fire during a sequence and interrupt the intended chain of events. For instance, if a user presses a button while the event structure is in a sequence where it triggers itself repeatedly.
It takes a lot of effort to create these hidden controls that only exist to fire value change events. And it makes the code confusing because they serve no real purpose. Yes, User Events are the preferred solution to this problem, even if they require more wiring and control, but they don't solve the first problem in the list.
A better solution might be something along the lines of a Queued State Machine architecture. It's a mix inside one loop of an event structure and an outer case structure. It's a little difficult to explain in words, but there's a good template free to download from JKISoftware that also has a tutorial video about it that you can learn more about here. I've recommended this before, but I promise I don't work for them or anything It's just good technology and a lot of thought has gone into it. JKI didn't invent the paradigm, but they've implemented it pretty it well.
It seems to solve a lot of the problems you have. It allows for user interaction through the event structure, and it allows you to trigger a sequence of cases not related to controls or indicators that have events registered for them. And it solves the two problems listed above. The architecture is inherintly self-documenting and clear, and it avoids the pitfall of allowing user interaction to unintendedly interrupt import sequences of events.  The downside is that it's not the simplest of architectures, but it's also not the most complex. Check it out!
Jarrod S.
National Instruments

Similar Messages

  • Run event structure on startup

    i have an event structure in a while loop.
    when I run the vi i wish to run one of the events 1 time without a user input.
    can this be done?? and if so how??

    This does not work with latch action booleans, you need to fake latch action with a switch action and a local variable. The attached modification show a working version of your VI.
    Of course I typically prefer a solution similar to George's.
    The need for a generic "first run" event has been discussed before, see my example and discussion in this old thread:
    http://forums.ni.com/ni/board/message?board.id=170&message.id=108599#M108599
    Message Edited by altenbach on 03-17-2006 08:20 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    InitEventMOD.vi ‏14 KB

  • How to run a vi by referencing in event structure

    Hi
    I searched for an example in Event structure. I just modified that but i am getting error(error code :1 )message when i run the program.
    could anyone give suggestions why is it so.
    I have attached the example program and my modified program
    Thanks
    Attachments:
    Untitled 10.vi ‏18 KB
    Main Launcher.llb ‏65 KB
    A.vi ‏9 KB

    [Edit: Sorry just a minute late. Even not able to remove the attachments. Its throwing some exception error.]
    Sorry, your request failed. A notification has been sent to the development team to investigate.
    Exception ID: 3A98D61C
    Please click the Back button on your browser.
    Message Edited by mathan on 06-27-2008 06:34 AM
    Message Edited by mathan on 06-27-2008 06:38 AM
    Attachments:
    Untitled 10.zip ‏19 KB
    Main Launcher1.llb ‏30 KB

  • Run-Time Menu and Event Structure~~HELP~~

    Hi, brothers,
    I'm new user for LabVIEW. Use the version of LabVIEW is 8.6
    One problem describe as below:
    Can Run-Time Menu and Event Structure exist simultaneously?
    Without Event Structure, Run-Time Menu works well, but Run-Time Menu works abnormally.after adding Event Structure,
    How do I modify the problem?
    Thank you for your help.
    Attached is the program.
    Attachments:
    PC_Adjustment.zip ‏44 KB

    Yes they can coexist, but not how you did it.
    Every iteration of the while loop you wait for an event in the event structure, and you look if the user has selected anything from the menu.
    To get this working you should add an event for <this VI>\Menu Selection (User):
    Ton
    PS you should add a stop button, the only way you can stop the VI is hitting the 'emergency stop' button, with hardware connected (like you have) this is not the adviced routine
    Message Edited by TonP on 09-26-2008 07:34 AM
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!
    Attachments:
    Main_BD.png ‏5 KB

  • Event controll: How to stop a running while loop inside a event structure

    Hello,
    I have some problems with controlling a while loop inside a event structure (see attached VI).
    I habe 3 buttons ("Start Measurement, Stop Measurement, Quit Program"). When a measurement is running, it should be possible to stop the measurement by clicking on "Stop Measurement", but this does not work.
    Has anyone an idea?
    Thanks a lot and best regards,
    Michael
    Message Edited by MichaGue_01 on 04-23-2010 04:37 AM
    Solved!
    Go to Solution.
    Attachments:
    Event_Controll.vi ‏27 KB

    Hello,
    Try not to use while loops inside a Event structure.
    My approach is using two While loops (one will have only the Event structure).
    I had to use to Flag buttons that make it a bit more complicated but i am sure somebody will come up with a better idea, or you might want to have a think about it yourself.
    Have a look on the modified version on the attachment.
    Once you are happy how it works then you can Hide the 2 flag buttons from the Front Pannel by going to Block diagram right-click the indicators and choose option "Hide Indicators/Controls"
    I did it in LV 8.6 so i hope you can open it on your PC if not i can downgrade it.
    If you have any problem let us know.
    Regards
    Dimitrios
    Test Systems Computing Engineer
    Cummins Turbo-Technologies
    Attachments:
    Event_Controll[1]_modified.vi ‏18 KB

  • How to run the two events at the same time by using event structure

    In my project, I have to run two stepper motor which can run both forward and reverse direction by changing the control in front panel so I am using event structure. In front panel I gave two separate controls for both stepper motor such as forward,reverse and stop. I would like to do motor1 will rotate alone, motor2 will rotate alone and both motor will rotate at the same time when user click the control in front panel. My doubt is how to run a motor2 while motor1 is running at the same time please tell me the suggestion for this problem
    Attachments:
    motor.png ‏192 KB

    How do you control your motors?
    Most motion control systems do supply two modes:
    a) position based motion: The motion axis has a positioning system (most often some kind of encoder system) which enables the motion control to know where the axis is currently located. Passing the target location to the controller will result in the axis to move to that location. This is, for most applications, the recommended approach. It does require some sort of motion controller device.
    b) direction based motion: This essentially tells the periphery device for the motor to move at a certain speed into a certain direction. As it does not stop at a dedicated location, it induces great risks for many applications if there are no kill- and/or end-switches. Depending on the setup, this can be either done with motion controllers or pure by software control (e.g. "controlling" the voltage level for the motor).
    If you go for a), there is not much preventing parallelism as you request.
    Option b) depends on the setup. If you have a control loop in the software itself, you have to move to an architecture like the producer/consumer. Please note that this does not incorporate any security measures for the external devices.
    hope this helps,
    Norbert
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • Event structure - "first run"

    Dears all,
    how can I manage the "first time" of an event structure?
    See the VIs enclosed.
    Thanks a lot at all.
    Attachments:
    Event structure - first time.llb ‏44 KB

    You don't need to mess with dynamic events. Simply add a timeout event to the event case you want to trigger.
    Feed the timeout terminal from a shift register initialized with zero and wired a -1 to the shift register on the right.
    The event case will immediately trigger once due to timeout. After that, the timeout will be infinite.
    (See attached image)
    Also have a look at my old post. The need for a generic "initialize event" has been discussed long ago in more detail, but I can no longer find the thread.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    FirstRun.gif ‏11 KB

  • 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

  • Can you share FP Controls between different Event Structures

    I'm creating a program that will either read real-time data from an VNA on the GPIB bus, or read a saved s2p (Agilent) file and analyze it. The FP consists of 5 graphs, and various controls which handle events like printing, changing filters, or exiting. on the BD I have a case structure controlled by an operator selection pop-up. I tried using the same FP controls in the event structures I have setup in each case, as only one event structure would ever be executing at any given time, but the program doesn't seem to like it ast run-time. I've worked around the issue by creating "duplicate" controls and using the property setting to make them visible/disabled, etc., but the is seriously congesting my BD.
    Anyone know a way to share controls with seperate event structures?

    It sounds like the root problem is the overall structure of your program. I highly recommend that you check out the Queued Message Handler project template in LabVIEW 2012, that will show you how to utilize a single event structure and pass events to a consumer loop. If you program is too large to consider an architecture change at this stage of the game, then there is a workaround for your problem.
    What is most likely happening is that you have the event structures all set to lock the front panel until the event completes. However the case structure that you have wrapped around these event structures is causing all but one of these event structures to be unreachable thus preventing you from handling the event. Again, as I stated above, the "RIGHT WAY" to fix this is to select a better program structure but the "kluge work-around" fix is this: Dynamically register for the value change event on all of the controls you are trying to trap events for. Dynamic events can be deregistered and re-registered at run time. This will allow only the event structure in the active owning case structure to be registered for the events, thus no other event structures will get in your way.
    Disclaimer: This advice is given based on very minimal information and a great deal of speculation and may not be correct. Please include your code if you need further assistance.
    Charles Chickering
    Architecture is art with rules.
    ...and the rules are more like guidelines

  • Event structure in Sub VI

    Hello ,
     I have a developed a program which captures video and user can save images out of it. I have used .NET reference to handle the video part, and the VI is attached in this post. Now i have to make this VI as a sub VI and running this from Main VI. I tried creating event structure in Main VI which i used in sub VI , still i could not suceed. Kindly assist me in this regard
    Solved!
    Go to Solution.
    Attachments:
    Webcam-Control-Projekt-mit-Reference-Design-2013_original.zip ‏286 KB

    Hello Michael,
     I have attached a model in which Main VI calls the Sub VI using Event Structure. Two events can occur in Main VI and their corresponding event Structure is called in Sub VI using Register events. When i run this VI the out put is fine some times but other times i need to trigger event many times before i can see its effect in Sub VI, my doubt is that Register events are reliable, whenever (during the execution of LV) if event occurs will surely its code in the sub Vi gets executed?
    also I have put a indictor(numeric) in the SUb VI which i connect back to Main VI, when i run, i can see the result only in the sub VI not in the main VI.how to see in Main VI?
    I have used the this model (which is attached ) to implement my project(which i already mentioned) . one switch for starting the video and other for recording the image. The video is getting started with out any trouble, but imgae is recorded only few times when i press the button which is for image recording, most of the time second event fails to get executed. Also there are difference in output when i run with and without "Highlight execution", why this happens, is this because of Reg events?
     any more info if required let me know, i will provide.
    Attachments:
    Main_sub_VI.zip ‏18 KB

  • How to use a event structure with a state machine

    First, I would like to inform you that I only work on LabView part time, and have much to learn.  Anything I do learn, I usually forget until I need it again, because I only work on it part time.
    Using your StopWhileLoopMOD[1].vi, I am trying to put a state machine inside the event structure.  
    Related link: http://forums.ni.com/t5/LabVIEW/How-to-stop-while-loop-in-Event-case/td-p/465564/page/2
    Here is my application:  on the front panel, the user can select any combination of 7 different tests.  I have created cases to perform each step of each test in the correct order, but if the user presses stop, the tests won't stop because some of the cases have a while loop inside the event structure (like you mentioned is a bad idea).  The user should be able to stop the test, reselect tests to perform, and re-start the tests. 
    When the start button is pressed for the event structure, I need all the cases to run in the proper order, unless stop is pressed.
    In the past I have indexed an array and used that to run the state machine, but it won't stop immediately.  
    I have sub VIs that are built in while loops because the outputs of the product needs time to stabilize.  The state machine stops and waits up to a certain number of iterations.  If it passes the test, the while loop stops and the next state starts.  If it takes too long, it exits and reports an error.  Maybe I need to just use the state machine and not an event structure?
    Is there a good example of an event structure?
    metzler CLAD
    Solved!
    Go to Solution.

    I'm not sure exactly what you are asking, but it sounds like you want to script a bunch of tests and if the user says stop, to immediately stop the current test and abandon the others?  I'm going to assume that you know how to clear the array so that it will abandon the others, so I'm guessing that you are having trouble abandoning the current test?  If this is indeed the case, then the problem is that you are not able to propagate the message from the main VI FP which is the GUI to the sub vi which is the test, where the test may or may not have a GUI (FP visible) of it's own.  Threading was the first thing to come to mind, but this may not be necessary using events.
    You can do this by passing a refnum of the stop button to the subVI, where you can then add that wait to the event case structure.
    I've attached 2 VIs, mainvi.vi which is just a loop displays the count*2 (number of seconds passed since running) that will call subvi.vi and then check to see if the stop button is pressed.  mainvi.vi is by no means a state engine, it is just a simple loop for demonstration purposes.  subvi.vi just waits 2 seconds and leaves, it is a better structured state engine with an init state to start a poll case to wait for events and an exit state to clean up.  You can modify this any way you wish to get it to do what you want.  You will note that even if subvi.vi is being executed, it will terminate immediately when the stop button is pressed.
    Hope this helps.
    A
    Attachments:
    mainvi.vi ‏17 KB
    subvi.vi ‏33 KB

  • Can I get the event structure to NOT queue events?

    I was wondering if it is possible to have the event structure not queue events that happen while the vi is executing code associated with another event. Basically, I have a toggle switch that, when "on", captures a live feed from a camera and displays it to the screen. This is done in a while loop that executes until the toggle switch is turned off. At this point, that event is done and the vi returns to the uppermost level of the event structure and resumes looking for events. The trouble is that the whole while the video capture was happening, the event structure was queueing events that were occuring during that time when the user was hitting other front panel buttons that had their own event associated with th
    em and would not execute at that time. When the video capture toggle is turned off the event structure then executes any other events that were queued during that time and I don't want it to. I can't lock the front panel while the video capture is happening so the user can't push buttons because they have to be able to push the button to turn the video capture off. Any suggestions? Thanks in advance.

    > I was wondering if it is possible to have the event structure not
    > queue events that happen while the vi is executing code associated
    > with another event. Basically, I have a toggle switch that, when
    > "on", captures a live feed from a camera and displays it to the
    > screen.
    I think there are lots of other articles about this on devzone.
    To summarize them, the key is that the event structure intentionally
    synchronizes events with diagram execution. The typical way to do what
    you want is to have the event start up another loop or subVI running
    asynchronously.
    Usually there ends up being one loop with an event structure in it.
    Another loop that executes a statemachine, possibly as simple as just
    two states of acquiring and not. Use the events to pr
    od the other loop
    between states via locals, globals, occurrences, etc.
    Greg McKaskle

  • 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

  • Using a Global as a value change in an Event Structure

    I have many events I want to react to based on Global buttons.  How do I get the Event Structure to recognize a global button value change?  This screen shot is one of my many attempts.  So far my events only change with a real button on the FP.
    Thanks in advance,
    Doug
    Attachments:
    Event Structure.JPG ‏147 KB

    nonecure wrote:
    Jim,
    The Value (Signaling) does not work either.
    I would rather not use a notifier, so maybe I need to get away from using an event structure.
    Thanks
    It should work if your code was executing correctly. The image you posted...
    may be the reason.
    If you watch the code in execution highlighting it may help you figure what is happening.
    1) There is no guarentee that "initialize" will be written to the local "State" before the loop starts running. Use a shift register to track your state from iteration to iteration.
    Do you get any errors?
    Ben 
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • What are the Dynamic Events avaliable in the LabView 6.1 Event Structure?

    I recieved LabView 6.1 recently and I am working with the Event Structure, and I'm trying to figure out what Dynamic Events are avaliable in the event structure, and how to access them. If you don't understand what I'm talking about, open a new VI in LabView 6.1 and drop an event structure on the diagram. Add an event and look at the dialog box that appears on the screen, specifically the Event Sources section. The third option in this area of the screen is "grayed out" but reads "Dynamic". I'm curious what these events are, and how I access them. I'm running WinNT 4 SP6.
    Thanks,
    Chris Davis

    I believe this is part of a feature which is not yet present in LabVIEW 6.1, but may be present in a future release.

Maybe you are looking for