Event structures for dummies

After all the great help with data handling, I thought I would ask a question about event structures.
I have a main VI that sits around and lets me read in files and change variables. Once I am happy, I press start which fires up some sub VI that start running in the background. I have tried this using event structures. But then disaster strikes!! One of my variables is wrong and I need to stop/reset the sub VIs (without stopping the main program). However, my subVI is running in a timed loop continuously, within the event structure, so it's stuck. Attached is a very simplified VI of what I mean.
I basically want to run a program, set up some variables, set off a background subVI, update/reset if needs be and then press the big continue button to the next stage whilst the subVI is still chugging.
Any suggestions from the Guru's? I do not think event structures are the way forward
"When I read about the horrors of drinking, I gave up reading"
Attachments:
event structures for idiots.vi ‏90 KB

The important thing about event structures is to use them in the right way. For example as a rule of thumb, don't put into an event handler anything that will take more than about 200 msec or so to complete. Why? Studies have shown that 200 msec is the longest delay you can generate without the user noticing the delay (obviously YMMV).
One good solution (as corys pointed out) is the Producer/Consumer Loop - but there are a variety of others. For example, I have created applications where pressing a button launched a long task as a separate process running in the background. When it finished it passed data back to the GUI using another event, queue or some other mechanism.
Mike...
Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion
"... after all, He's not a tame lion..."
Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

Similar Messages

  • How to handle event structures for two buttons and two counters.

         *I have two buttons A and B, and have to compare the difference in hits between them.  So do I place an event structure within a while loop for each button (2 buttons, 2 event structures, 2 while loops), or does it need to be one event structure with cases for both buttons whithin one while loop? 
         *How do I pass the values of buttons A and B's hit counters out of the while loop in order to calculate the differences between them after each increment, not just the final count after the stop button is hit? 
         *How would I make one stop button work to handle both buttons A and B?   I tried to place the actual stop button in one button A's structure and its global in B's structure, but It wont seem to let me use a local variable for a latchable control
    Checker

    You should probably have not started a new thread and waited until your question in the original thread was answered. You can modify altenbach's example for a second button. You have a single event structure with a new event for the second button. You have a second shift register to track the number of times the second button is pressed. Inside the while loop but outside the event structure, you just have a subtract function in or to report the difference. do not modify the posted example for the stop button. It works perfectly as is.

  • 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

  • I using an event structure for an input box and also for hardware input

    Hi there!
    I have many input boxes and display boxes on my user interface and i have a case for it in the event structure. If the user changes the values of the input boxes, the particular event case writes this new value to the hardware. However, in the timeout section of the event structure, we read the inputs from the hardware and we set the value for its related display object.  Within the timeout section i set the value for the related user interface display component, by making use of the property node value.
    Furthermore, for most of the display components, i have a event case for a value change associated with it. In that event case, i check for range errors and so forth.
    My assumption was that when i read the value in from the hardware and set the property node value, the user interface component's value will change and it would then trigger the event of the value changed for that component. 
    My assumption worked to the point of updating the component's value, however, it did not trigger the event  for the value changed for this component.
    Please advise me on how to achieve what i wish to.
    Thanks.
    Regards,

    Local variables are actually much more efficient than property nodes as far as execution speed goes. Take that same VI and delete the property node and instead write to a local variable inside the loop. You'll see the speed nearly identical to writing directly to the indicator. But note that variables also cause a copy of the data to be created. So if you're just using the "Value" property, you're much better off using a local variable. But don't use both at the same time. If you are reading/writing other properties when you update/read the value, you might as well use the value property.
    Sometimes you can't get around using either variables or property nodes. Initializing controls to saved values from an ini file is one example. But in this case, they are only written to once as the application starts so the performance hit is negligible.
    One thing you can do is store values in a shift register as they are read and pass this through your application so the last value read can be accessed from anywhere. You can even create a cluster that runs through the shift register to hold several values in a single register. This can be expanded a bit farther to create what's called a Functional Global. This basically a subVI with a While loop that only runs once on each call. It has a shift register to store data and a Case structure to Read or Write data into the register. There's a pretty good example that ships with LabVIEW showing how these work. Open the Example finder and search for "Functional Global Communication". This example shows how to use them to pass data between two independent loops, but they work just as well in a single loop application.
    One of the big advantages of these Functional Globals over the standard LabVIEW Globals and local variables is that you can add cases to manipulate the data in addition to just storing it. Also, since it's a subVI, access to the data is protected to one caller at a time whereas variables can have multiple reads and/or writes at the same time. This can cause race conditions.
    Hope that helps a bit.
    Ed
    Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
    Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.

  • Producer/Consumer Design Pattern + DAQmx + Event Structure

    Dear community users,
    at the moment I try to implement the Producer/Consumer Design Pattern into my current project. For this purpose I am trying to make a "minimal-example" in which I use the Producer/Consumer Design Pattern for the data acquisition and analysis (display in GraphXY, calculation etc..) process. In the Producer Loop I perform the data readings via DAQmxRead.VI and in the Consumer Loop, in this example only, I display the data in a GraphXY. At the same time I want to control the data acquisition via an Event Structure, for example Start Measurement/Stop Measurement Buttons. To configure the measurement time, for example if the user only wants to measure 150 sec, I use the Time Out Event of the Event Structure. This is a technique which is often used, when data acquisition and Event Structures are used at the same time (Excuse me if this is wrong!). Due to understand the Producer/Consumer Design Pattern I looked up in the Template\Framework of LabVIEW.
    In the attachment you will find my "minimal-example", which -sadly-, not working. What should I do ? 
    Thank you.
    Best regards,
    tugrul öztürk
    Attachments:
    daqEngine_PCP.vi ‏35 KB

    Your VI will never stop due to the Ok Button that stops the producer loop is read OUTSIDE of the loop.  Add an event case for it.
    Move the Start and the Ok Button inside of their respective event cases.  This will allow the latch to reset when they are read.
    Change the Ok Button to a stop button.
    Use a Greater Or Equal instead of Equal for the measurement time comparison.  What if somebody randomly changes it to 0 on you?  Again, you will never stop.
    Is the DAQ only supposed to read for "Measurement Time".  Right now, it constantly reads.  So if you don't use the DAQmx Read, you will get a buffer overflow error.  You need to put the DAQmx Start Task inside of the Start event case and then the Stop DAQmx Task inside of the Timeout event case when the measurement time is exceeded.  You should also perform the read regardless inside of the Timeout event case.
    I HATE telling the consumer loop to stop by destroying the queue.  You can look data that way.  Instead, send something an empty array.  In the consumer, check for an empty array.  If it is empty, stop.  Destroy the queue only AFTER BOTH LOOPS HAVE COMPLETED.
    You should also report your errors in some way.  Simple Error Handler at the minimum.
    Since you are using Continous Samples, don't limit the buffer.  Leave the Samples per Channel unwired on the DAQmx Timing VI.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • No more than 2 event structure?

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

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

  • Time Structure for multiple controls changes?

    I have some controls like shown in the picture. Lets say I want to check for changes done by the user in the String controls, since every string is inside a separated cluster, I would have to create a single case (inside a Event Structure) for each string or add them one by one to the same case, again one by one. How can I check for events on all the controls of the same type without having to add them manually one by one? Or, if I check for events on all the controls, how can I then identify wich control triggered the event structure?
    Attachments:
    Desing.png ‏402 KB

    Ty very much, I will create a "all elements" value change case, and then compare. But since in my cluster ther is a lot of diferent types of elements,the new value type gives me a analog cluster with the new value written into it, and also the control ref. Since I have all the control references stored, I would prefere to compare them instead of comprare individual elements of the cluster (to avoid a lot of unbundles and stuf), but i cannot compare this control refs (see image atached). I assume that control ref given by the Event structure is polimorfical, or weak control ref, and mine is strict. How can I convert classes?
    Attachments:
    Event Structure.png ‏145 KB

  • Local variable event structure

    Hi,
    I am using an array control and event structure for detecting changes in the array value.
    At first,I have performed changes in the array(during runtime) and the event structure detected it.
    The next step was adding a parallel while loop in which I am writing to the control array(using local variable).
    During the runtime the layout of the array indeed changed,but the event structure didn't detect it.
    I have attached 2 figures :1)The loop of the event structure 2)the parallel loop.
    Is it possible working in such way?
    How can I make the event structure detect changes the software performed in the control array?
    Thanks,
    Leonid
    Solved!
    Go to Solution.
    Attachments:
    event.PNG ‏43 KB
    update.PNG ‏34 KB

    This is a long discussion about "red flags"
    Norbert
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • Conditional stopping event structure

    Hi all
    Attached is my Vi , I want to stop the event structure in loop 1 , from the loop 2 which is continously running in parallel and getting digital input from a DAQ device.
    whats happening is first I am checking the status of teh digital input and then on that I am excuting the true structure. once I am in the True case , an event structure for user operations and a parallel while loop is used to monitor the digital input , what I  want to do is as soon as the digital daq input is low again i should be back to my fasle case in the main loop but the loop 1 with event structure is not stopping.
    help
    regards
    Regards
    Attachments:
    Untitled 1.vi ‏12 KB

    Snamprogetti wrote:
    You can't put an event structure into a case structure. It will run even if you are in the other case.
    See http://forums.ni.com/t5/LabVIEW/An-event-structure-can-freeze-the-front-panel-even-if-not/m-p/106629...
    What then, is a queued state machine? . The issue is the event structure still queues your events whether or not you are in your "idle" case. So if you don't promptly return to your idle case, events can back up in the event structure causing your program to act like it's lagging. Setting a busy cursor can help to solve this problem. I felt this should be clarified because a properly set up queued state machine is very powerful. This obviously isn't the solution for the parallel loops here but I thought I should add to your point..
    CLA, LabVIEW Versions 2010-2013

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

  • While loop inside a event structure

    Dear
    I have no much concepts on event structure.
    Let's assume there is a dialog box with Okay and Cancel button.
    I put the event structure for Okay and Cancel button.
    In Okay event, there is a while loop for detecting some data continuously.
    In this case, I want to use Cancel button to stop the while loop during the detection.
    How can I do to receive signal from the Cancel button?
    Thank you in advance.

    I'm not sure that the event structure should be used to handle that situation : while the OK event is executing, either the Front panel is locked and new occuring event will be stored until the OK event is completed (so the Cancel button action will not be detected !) or the Front panel is unlocked (see below *) and the Cancel button action will stop the loop, but the Cancel button event case will not be executed, since the event has already been processed in the OK case !
    You should probably use a single button to run/stop the loop, as shown in the attachment
    * While editing the event case, unmark the "Lock front panel for this event complete" at the bottom. But of course, the code in the cancel case will not run, since the event occuredMessage Edité par chilly charly le 03-31-2007 05:27 PM
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Event button.vi ‏11 KB

  • Event structure-Plese help

    I have made a GUI for communcation between two pc with various parameters.
    I have used an event structure for 1st PC because i have 3-4 parameters which i want to run as i press the boolean on front panel.
    However my problem is suppose I press the 1st boolean, I want the 2nd pc to receive and respond that data has been received. And since there are 3-4 parameters, i will have to use event structure for 2nd PC too. But there will be no one to control front fanel of 2nd PC.
    So, how do i do it. Any alternative to event structure in which it resoponds to data recieved and not on user input.
    Thanks. 

    In my experience with serial communications, you will want a loop for nothing but reading from the port.  You can use a global or a Notifier to tell this loop to stop.  You will want a second loop for GUI and message handling.  So I encourage the use of the Event Structure here, using User Events to send the commands/data to this loop.  Then you will want a third loop for sending commands through your serial port.  Send the commands/data to this loop using a queue.
    So the process will go like this for PC-2:
    1. Read command through serial port.  Serial Read loop sends this message to GUI loop via User Event.
    2. GUI loop processes user event, does whatever is needed, and sends the response to the Serial Write loop via a queue.
    3. Serial Write loop reads the message to send from the queue and writes it through the serial port.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Please help me fix this event structure

    Hi there. I have this VI that has an event structure in it, I was changing some aspects of the vi, broke the wire to the stop event, and "poof" the VI is broken and I do not have the ability to fix this with my BASE package of labview.
    Can someone fix this issue with the event structure for me? It is broken in  "FC80-Serial-Event-80KW Blower.vi"
    The VI "FC80-Serial-Event-19.vi" is an example of the event structure when It is working properly.
    I have attached both.
    Thank you for your time and efforts.
    Attachments:
    FC80-Serial-Event-191.vi ‏289 KB
    FC80-Serial-Event-80KW Blower.vi ‏237 KB

    Try this.
    Attachments:
    FC80-Serial-Event-80KW%20Blower[1].vi ‏249 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 .

  • Event structure in RT project

    Hello.
    In my main VI i have an event structure for few buttons. When I run the VI itself it works perfect.
    When I open a new project, adding cRIO 9074 as a target, then adding the VI to the project the buttons doesn't respond. The event structure doesn't work.
    Why? Is there any problem using event structure with RT targets?
    Thanks 

    Tacchi,
    Front panel events do not work on RT targets.  Only dynamic events are allowed on RT.  The reason for this is that when a VI is running on RT, its front panel doesn't actually exist.  See this KnowledgeBase for more info:
    http://digital.ni.com/public.nsf/allkb/42B70D2D0C4B568586256E2F0051441D
    Chris M 

Maybe you are looking for