VI High 8: More on How to Program Events with the Event Structure in LabVIEW
In this continuation of our last episode, we examine one of the most commonly asked LabVIEW programming questions: how do I use the event structure? We examine executing two events from the same event case and the basics of programming a timeout event case.
For more on learning LabVIEW, check out the Sixclear Lucid LabVIEW Fundamentals Training (formerly Sixclear LabVIEW Fundamentals) course offered by Sixclear: sixclear.com.
In the video, we mention that we don’t need to place a numeric terminal in an event case tied to that numeric but we must place the terminal of a latch action Boolean in the event structure case corresponding to that Boolean. Why is that? This is taken from the LabVIEW Help topic ” Using Events with Latched Boolean Controls”:
“When you trigger an event on a Boolean control configured with a latching mechanical action, the Boolean control does not reset to its default value until the block diagram reads the terminal on the Boolean control. You must read the terminal inside the event case for the mechanical action to work correctly. As a reminder, a note appears in the Edit Events dialog box when you configure a Value Change event on a latched Boolean control.”
Experience Level: Basic
“Last week, we showed how to create a very simple event-driven program by programming an event structure to wait on a value change event on a front panel OK button. At the end I left you on a cliff, waiting for this week to learn how to program multiple events as well as explore other caveats. Are you ready?
First, it’s important to point out that the event structure is like a case structure, stacked like a deck of cards, so that you don’t see an underlying case when you’re looking at the top. This event case is waiting on the OK button value change, and this one is waiting on the stop button value change. Let’s say now that I would like to have 2 events generated from this same event case. For instance, I’ll place this numeric control on the front panel, and I would like the same dialog box to pop up if I pass my mouse over this numeric or if I click on the OK button as before. First, I’ll change the dialog box text. Then right-click on the border of the event structure, choose Edit Events Handled by This Case, and in the Edit Events dialog box, I’ll click Add Event. Then in the Event Sources window I’ll choose my Numeric, and in the Events window I’ll expand on the Mouse category and choose Mouse Enter, which is when my mouse enters the bounds of this Numeric control. I see both of these events configured and I’ll click OK. Now if I create some space in this event case by holding down the control key on my keyboard and click and drag my mouse to the right, expand the window, I see both of my events listed in the selector label.
Let’s run my VI. As before, if I I click on the OK button I get the dialog box, and passing my mouse over the Numeric gives me the same event. Note that I did not need to place the Numeric terminal inside of the event case as I needed to with the latch action booleans. For the reason, see the notes in the text description of this video.
Now what’s this hourglass up here? It’s the timeout terminal, and it specifies how long we’ll wait before we execute the timeout case. Currently, we don’t have a timeout case, though it is the default type of event if we were to just place down a new event structure. But let’s configure a timeout case. Right click on the border, add an event case, I’ll choose Application as the Event Source—in other words events that would be generated from the LabVIEW environment—and then choose Timeout as the Event. Ok, and now I’ll put something in this event case, we like dialog boxes, there we go. Now how long does the event structure wait before executing this case? Let’s create a constant off this terminal and see that the default is -1, which means forever. But we don’t want to wait forever, we’ll instead enter 3000 or 3000 milliseconds, which is 3 seconds.
So now I’ll run this again, and just as before, we have events generated from our other controls, but if I don’t generate any event for three seconds…I get the timeout event. So pushy.
Well that’s it for this week, there are many other things I can do, like have more than one event tied to the same object, create filter vs. notify events, and even create programmatic events such as user events. If you’re interested in some of those things, check out the notes for this video or sixclear.com.”