VI High 25: How to use the Array Size and Add Array Elements Functions in LabVIEW

This episode is part of a VI High series focusing on arrays that runs from VI High 24-32.

In VI High 24 we built some simple arrays. Now we’re going to look at some common array functions with 1-D and 2-D arrays. We’ve cut the episode length down to be bite-sized, digestible, and tasty. Bon appetit!

For more on programming in LabVIEW, check out the Sixclear Lucid LabVIEW Fundamentals Training (formerly Sixclear LabVIEW Fundamentals) course at www.sixclear.com/labviewtraining/.

Experience level: Basic

(start transcription)

Hi, it’s been a while.

In our last episode, we took a look at creating arrays on the front panel and on the block diagram. In the two step process, first we put down an empty array shell and then we populated it.

So let’s start over here with Array Size. Put it down. The context help, CTRL-H, is always invaluable for knowing exactly what these do. Returns the number of elements in each dimension of the array. Well that’s cool. So I’ll wire this in here, create an indicator, pump up the output, I see it show up here. I run my VI, and indeed I have five elements in my array.

Now what if I wanted to know the value of all the elements added together instead of just the number of elements in my array? Well, for that I would go to the Add Array Elements function. Put that down. Wire this into here. Create an indicator as before, and run it. And here’s the sum of all these elements. That’s pretty cool.

What if I use this on a 2D array right here? Hold down control, click and drag this up, I’ll get rid of this for now, and wire the 2D array into the function input. Create an indicator. Oh, look what happened. I get an array as the output. I’ll expose two elements and run it, and I get two elements out. There are no more elements, just those. And as you can see, these elements correspond to the size of this array. Four rows. Five columns.

Before we move on, let’s take a look at these wires. First off, a scalar wire is pretty skinny. A 1D array wire is thicker, and a 2D array wire is thicker still. Look what I did. I made this a 3D wire, and it got a bit bigger. And you can guess if I run it and expose another element, yep, I have the size of each dimension. This other dimension is, as yet, unpopulated. You can think of it like multiple Excel spreadsheets. I’m looking at one, and here’s the other. But for now, I’ll hit CTRL-Z and go back, and take this back to two dimensions because we’d like to look at more functions.

(end transcription)

VI High 15: How to Find and Replace Duplicates From Our Selected Random Array Elements in LabVIEW

In our last episode we made a simple VI to randomly select items from an array but we found that it was prone to finding duplicates. This time around we find out how to avoid those duplicates.

For more on learning LabVIEW, check out the Sixclear Lucid LabVIEW Fundamentals Training (formerly Sixclear LabVIEW Fundamentals) course offered by Sixclear: sixclear.com.

Experience Level: Basic

(start transcription)

“When we finished VI High #14, we had pulled out some random names from our Name Array, but we noted that we often ran into duplicates and we said that we would be coming back to item 3 in our implementation plan to find and replace those duplicates. There are, again, a few ways to do this but remember the primary characteristic of our implementation should be: robustness.

Robustness.

Let’s first be aware of some of the characteristics of the duplicates. Sometimes we only get one duplicate, or in poker terminology, a pair. Look at Sarah. Sometimes we get two pair, like 2 Aruns and 2 Veronicas. And sometimes we get three of a kind or more, like greedy Mindy here.

So we need to search through this array of indices to find these duplicates. First let’s clean up this block diagram. Then let’s use a For Loop which we’ll auto-index with this array of indices, and we want to compare this element to every other element in the array, which means we’ll bring in the entire array and disable indexing. We’ll want to remove this element we’re checking from the array. And we’ll use the Delete From Array function to do so. The iteration terminal will supply the appropriate index. So now we’ll put another For Loop inside of this one and index the array without the element we’re checking and compare the element we’re checking to every element in here with an equal function. So is this equal to this. If it’s true, then we want to replace that element in this array that we’re checking. So within a case structure, we’re essentially going to duplicate this little block of code over here except we’re doing it for a single element instead of an array. So I hold down shift and click, click, click and then hold down Ctrl, click and drag them over here. This new element I just created is going to replace the element we’re checking, the index of which is here in this iteration terminal of the outer For Loop. And so we’ll use a Replace Array Subset. I’ll hold Ctrl, click and drag to give us more space, delete this auto wiring which wasn’t helpful, wire  this array into here, disabling indexing. That’s the index, and the new value.”

“And note that the array that I use the Replace Array Subset with is the full array, not the one from which I had removed that element in question. I’ll wire the resulting array to the border, disable indexing on both of these For Loops, their output. And in the False case of the case structure, we’ll just wire this array through because we didn’t find a match and we’re not changing anything. Now we want these For Loops to keep running until they’ve run through all elements in the array or they’ve found a match. This is a perfect use case of a Conditional For Loop which is available in LabVIEW 8.5.1. and beyond. So I’ll right click on the border of the For Loop, Conditional Terminal, once again I’ll hold down Ctrl click and drag to create some space, and now I’ll wire this boolean to the Conditional Terminal. And we’ll do the same for the outer For loop. And disable indexing, we just want one value.

So what do we do now? Have we entirely fixed the duplicate problem? Well no, this implementation will fix a single pair, if we’re again invoking our poker terminology. But what about the two pair or 3 of a kind? Remember greedy Mindy. This implementation won’t address those problems so we need to take the entire array, after the replacement, and run it through the same process again. How do we do that? We’ll wrap these nested For Loops in a While Loop. Give some space, and we’ll use a shift register to send this array back to the beginning and run it through the same process again. So the input array will no longer come through this tunnel, but rather the shift register. 

And what condition will stop the While Loop? We’ll know we don’t need to run the While Loop anymore when both of these For Loops stop running and they didn’t find a match, meaning that this wire will be false. So we’ll change the Conditional Terminal on the While Loop to Continue if True, wire that value to it, disable indexing, and so the While Loop will stop when the Boolean value is false. Now the output from here will be a set of 6 unique indices. So we’ll just drag this little block of code - Ctrl click and drag - over here, and make another output: Real Winners! Excitedly. And run it.

We see that we’re successful, by checking that, in the case where there’s a duplicate in the Winners list, like Santiago, it is replaced with a unique name in the Real Winners! list. Run it a few more times, we have two Xui Lis, and only one in the Real Winners list. Fantastic.

That’s it, this VI is ready for action, which it will see after 11:59PM CST on June 9 when the sweepstakes ends. If you haven’t entered yet, get to it by visiting the instructions at news.sixclear.com. And once again, good luck!”
(end transcription)

VI High 14: How to Select Random Elements from an Array in LabVIEW

In this episode we are preparing to select the winners of our sweepstakes giveaway. What better way to make the random selection than a LabVIEW VI?
None.
Join us as we look at how to randomly select items from an array and how to avoid the pitfalls of this seemingly simple task.

For more on learning LabVIEW, check out the Sixclear Lucid LabVIEW Fundamentals Training (formerly Sixclear LabVIEW Fundamentals) course offered by Sixclear: sixclear.com.

Experience Level: Basic

(start transcription)

“Avid Sixclear paparazzi are already well aware that entry to our sweepstakes giveaway of six licenses of the Sixclear Lucid LabVIEW Fundamentals 
Training (formerly Sixclear LabVIEW Fundamentals) course is days away from coming to a close. As such, we need a way to randomly select the six lucky winners from the eager entrant pool. What better way than LabVIEW?

Our task is well defined. We will have an array of strings with names of our entrants. From that array, we will randomly select 6 with LabVIEW. There are several ways to implement this, we’ve chosen the most hopelessly interesting.

We will implement a solution in the following manner:

1. Generate 6 random numbers
2. Scale the random numbers by multiplying them by the size of the name array, this will generate an array of indices that can be used to pull out random names from the name array
3. Check for and replace duplicate indices
4. Use the indices to generate an output array of 6 random names

Let’s head to LabVIEW and do it.

I’ve already created a multicultural array of names on the front panel that we’ll use. Generating the 6 random numbers is easy. Just put a Random Number function in a For Loop running 6 times and auto-index the output. That occurs by default. Now to scale those to the size of the name array, we’ll take an Array Size function and use the polymorphic attribute of the Multiply function to multiply the array and the scalar output together. Now these numbers coming out are extremely precise fractional numbers and we just want whole numbers corresponding to indices, so we’ll use the Round Toward -Infinity function. For now, we’ll skip step 3 and just use this array of indices to generate our output names array. We’ll auto-index this array into a For Loop and pass the index to an Index Array function. The array we’re indexing is the full Name Array, and we’ll want to disable indexing on this tunnel coming in because we want that full array. Each iteration of this loop will give us one of the selected names, so we’ll auto-index the output to generate the full list of 6 names.

If I run this a few times we see that this procedure does indeed work except that we sometimes run into duplicate indices as a result of rounding down each element. You can imagine that multiple numbers in this array could be rounded down to the same number and so we have duplicates. Obviously we have a small Name Array and so we’re more likely to get duplicates, but we need a robust way to find and eliminate those duplicates for any size array coming in. Remember, robustness.

And remember that until next time because we are out of it. Uh, that’s time, not robustness, still plenty of that. In the meantime, you can enter the sweepstakes until June 9, 2011, just check out the entry requirements on our news blog: news.sixclear.com.”

(end transcription)

VI High 13: How to Use and Install Instrument Drivers in LabVIEW (part 2)

In this continuation of VI High #12, we look at the structure and programming methodology of a LabVIEW instrument driver. Who develops instrument drivers and how can we find the resources to help us understand and implement them well? Finally, we look at how to install the instrument driver when not using the Instrument Driver Finder.

For more on learning LabVIEW, check out the Sixclear Lucid LabVIEW Fundamentals Training (formerly Sixclear LabVIEW Fundamentals) course offered by Sixclear: sixclear.com.

Experience Level: Basic

(start transcription)

“By now, you’ve worn your F5 key to a nub refreshing VI High, waiting for the second part of our instrument driver session. It is here.

Last time, we looked how to use the Instrument Driver Finder to locate and install our instrument driver. Let’s take a closer look at that instrument driver: the Textronix AFG 3000 Series. The most helpful place to start is at the VI tree. This is a non-executing VI purely used for documentation. I go to the block diagram and I can see the programming flow for this instrument, so I’ll use VIs in this order in order to build my code. First, I’ll initialize communication to the device, then I’ll use one or more of these VIs to configure the waveform I’ll be outputting. Context Help is especially valuable, I see that I can configure a standard waveform to output, I can configure the output impedance, and so on. I have a couple VIs that fall into the Action/Status category, like enabling output and clearing the arbitrary waveform, and then a few optional Utility VIs, like performing self-tests and resetting the instrument. Finally, I’ll close communication with this Close VI.

How about some examples on how to use this instrument? Where the examples are located really depends on who built the instrument driver. Some instrument drivers are developed by the instrument manufacturer, some by third parties, essentially anyone can develop an instrument driver and submit it on ni.com/idnet. As such, they do vary in quality and technique. The instrument driver can place the examples in the LabVIEW Example Finder, sometimes you’ll find the examples right in the palette or here in the VI Tree. As you can see, this instrument driver places the examples in the Example Finder so let’s look there. I’ll go to Help»Find Examples. Under the Browse tab I’ll go to Hardware Input and Output»Instrument Drivers»LabVIEW Plug and Play and here I see all installed examples. Here are the examples for the Tektronix AFG 3000. I’ll grab a simple one to generate a standard waveform. Go to the block diagram, we see that these VIs follow the same programming flow as I saw in the VI Tree. Initialize, Configure, Action/Status, and Close. Delightful.

Now what if somebody tells me they have an instrument driver they’ve developed, or what if I download one directly from the manufacturer’s website, or ni.com/idnet. How do I get that instrument driver into LabVIEW? The first thing to do is shut down LabVIEW, then I’ll navigate to the LabVIEW folder in my computer’s program files. By default, this is stored in C:\Program Files, I have a 64 bit machine and install 32 bit LabVIEW - along with all the rest of my 32 bit applications - in this (x86) folder, then \National Instruments\LabVIEW 2010\ then the instrument library or instr.lib. Here I would place the driver. So, for instance, let’s say someone developed a driver for a MAS-345 DMM and they handed it to me on a USB drive. Here it is. I can drag it into here, and then restart LabVIEW. Once LabVIEW is restarted, I can navigate to the same place in the instrument driver palette and there it is.

That’s it for instrument drivers. As always, check out sixclear.com for more on LabVIEW training and check out VI High for the full video transcripts.”

(end transcription)

VI High 12: How to Find and Use Instrument Drivers in LabVIEW (part 1)

Controlling your instrument is one of the biggest reasons you may be learning LabVIEW. There’s a big difference between doing it with NI-VISA, the interface driver, and an instrument driver. In this episode we’ll see how to find an instrument driver in LabVIEW using the Instrument Driver Finder. Next time around, we’ll look at other ways, like using ni.com/idnet.

For more on learning LabVIEW, check out the Sixclear Lucid LabVIEW Fundamentals Training (formerly Sixclear LabVIEW Fundamentals) course offered by Sixclear: sixclear.com.

Experience Level: Basic

(start transcription)

“We teach people LabVIEW. One of the biggest things people want to be able to do is control their instruments with LabVIEW. Let’s learn how.

First off, which instruments are we talking about? Maybe a standalone DMM, perhaps a pump, a mixer, a lock-in amplifier, maybe a robotic arm, essentially anything that can be connected to a computer through some sort of standard interface can be controlled with LabVIEW.

Next, we should know that there are many layers of communication that go from LabVIEW to an instrument. Let’s look. At the bottom, we have the instrument with which we’re communicating. This communicates through our Operating System (Windows) to an interface driver. This interface driver is specific to the interface, so we would have a separate driver for serial, for 488.2 or GPIB, or Bluetooth, whatever. On top of that we have NI-VISA, which is one unifying or umbrella driver that can communicate with a variety of instruments with a common interface. On top of that we see instrument drivers. These drivers are specific to an instrument, say an Agilent 34401 DMM, or a Tektronix 7000 series oscilloscope. On top of these driver layers we have the applications which interface with them, namely LabVIEW and MAX or the Measurement and Automation Explorer. You can see that LabVIEW can typically interface with our instrument through any of these three methods: instrument driver, NI-VISA, and interface driver.

An instrument driver is a set of VIs already made in LabVIEW that communicates with a particular instrument model. So let’s say I have a Tektronix AFG 3252 Signal Generator connected through GPIB sitting here on my desktop and I want to know if there’s already an instrument driver available so that I don’t need to program low-level commands either through VISA or the interface driver. If I had this instrument driver already correctly installed, I’d go into LabVIEW and be able to see it in my Instrument IO»Instrument Drivers palette. Here I see all the instrument drivers I already have. So if I don’t see it here, I’ll go to Help»Find Instrument Drivers and this launches the Instrument Driver Finder. It’s first looking for my login information. It found me, and addresses me by name. I’m gratified. It’s just using my ni.com profile. If you don’t have an ni.com profile, it’s free, just go to National Instruments website and sign up so they can send you marketing material.

First, I’ll click on Manufacturer, browse through them until I find Tektronix, and then, in the Additional Keywords field, I’ll type in the model number: AFG 3252. Search, and there it is: the Tektronix AFG 3000 series instrument driver, and I’ll look over here to see that my model, the AFG 3252, is indeed supported through GPIB. What a relief. So let’s install it. I click install, LabVIEW thinks about it for a second. Notifies me of success, I’ll start using it. Go back to my Instrument Driver Finder. I see that I can explore the Instrument Driver a little further and look at examples here, but for now I’ll just close it, go back to my Instrument Driver palette and I find indeed the Tektronix AFG 3000 Series. Tack that down, bring it up here and now I’m going to be able to program my instrument.

That was easy, so next time around we’re going to take a closer look at the instrument driver and how to program an instrument with it and we’ll also look at how to install an instrument driver that isn’t found on ni.com or through the Instrument Driver Finder. Until then, please anxiously refresh our VI High blog at blog.sixclear.com.”

(end transcription)

VI High 11: How to Use “Suspend When Called” in SubVI Node Setup in LabVIEW

You may shake your head in disbelief as we explore an often overlooked feature in LabVIEW: the “Suspend when called” option in the SubVI Node Setup menu. Your life is about to get better.

For more on learning LabVIEW, check out the Sixclear Lucid LabVIEW Fundamentals Training (formerly Sixclear LabVIEW Fundamentals) course offered by Sixclear: sixclear.com.

Experience Level: Basic to Advanced

(start transcription)

“Recently, a few of us Sixclearers attended a LabVIEW Architects Forum here in sometimes too sunny Austin, TX. The presenters briefly discussed the Suspend When Called option in SubVI Node Setup. Jaws dropped as, almost to a person, we realized that we hadn’t been fully utilitizing this important feature. Let’s explore.
This very simple VI takes 2 numbers, Numeric and Numeric 2, and multiplies them in this subVI featuring an iconically clever play on words. We’re just multiplying them together, and then checks to see if that product passes a threshold value of 10. To check this, I’ll put a 2 and a 3 in the front panel numerics, run the VI, we have an output of 6, which does not pass the threshold value of 10 and so our LED stays off.
If I right click on the subVI I bring up the SubVI Node Setup. I’ll click on Suspend When Called. Ok. Now when I run the VI the front panel of the subVI comes up and allows me to interact. I can, for instance, change the value of the incoming data, run the subVI again. So now I can essentially supply whatever data I want to the subVI, regardless of what my calling VI actually supplied. So I’ll click on Return to Caller and the VI stops.
Additionally, and I hope you’re sitting down, if I run this again I can place a new value in the output of this subVI, regardless of what the subVI actually did. So, for instance, right now we have a 16, which has passed the threshold, and instead I’ll place a 9, Return to Caller, and we see that the value has not passed the threshold. This is extremely valuable if you have code reading from many sensors or test points. Let’s say I want a certain shutdown procedure to occur if a temperature surpasses a threshold value, or I want additional analysis if my device under test outputs a certain waveform. Rather than actually having to run the hardware and try to recreate those scenarios, I can simply have the subVI that calls those sensors output the value I want. Ok, you can stand back up, and cheer.”

(end transcription)

VI High 10: How to Control Execution Order with the Error Cluster in LabVIEW

In this episode we’re continuing the discussion started in VI High #9: controlling execution order in LabVIEW.

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 there is plenty more to discuss regarding error clusters. Take a look at Handling Errors in the LabVIEW 2010 Help:

Experience Level: Basic

(start transcription)

“Last time we examined dataflow and execution order, looking at the rules that govern how nodes execute. If you haven’t seen that one, take a look at VI High #9, it’s pretty good.
At the end, I mentioned that there are ways that we as programmers can easily control execution order. Using the error clusters is one of the best ways. For our purposes, we’ll say there are 2 main reasons to use the error cluster in LabVIEW:
1. Control error handling
2. Control execution order
Now, we could have an entirely separate discussion on the first bullet: which is controlling how our application reacts to an error. We’ll leave that for another discussion and focus on execution order. Though we won’t be using the contents of the error cluster in this discussion, let briefly take a look at what’s in there so as to assuage your raging curiosity. There are three items in the error cluster: -a boolean named status, indicating if - yes or no - an error has occurred, -a numeric named code indicating what the error is, -and a string named source indicating where the error came from.
For the purposes of our execution order discussion, the most important thing to understand is that the error cluster is simply a single input and/or an output from a node. As such, it dictates when the node will execute.
For instance, let’s take a look in our File IO palette at the Open/Create/Replace file. We see that we have the error cluster going into the lower left and out of the lower right, error in and error out. While we have this function out, let’s take a look at some binary file writing. Don’t worry, you don’t need to be familiar with binary file IO to get this concept. To write binary data, I will use this Open/Create/Replace file, and then Write to Binary File, and Close File. The order by which they’re placed is the correct order in which they should run but how do I force them to have this execution order? Well they all have this file refnum input and/or output in the upper left or right so I’ll connect those up and, because of dataflow execution, I know that this Write to Binary File function can’t execute until it receives data from here, same with the Close File. So I have the inherent execution order of open, write, and close. Now that’s easy to do since they have this common input of the file refnum. But what if I wanted to put some other VIs in this VI chain which didn’t have those inputs or outputs?
Let’s say I wanted to build a simulated sine wave, perform an FFT on it, and then write that data into the binary file. I’ll go to my waveform palette, analog waveform, sine waveform. And for my FFT, I’ll use this FFT Spectrum. I want them to execute right in between opening the file and writing to the binary file but these 2 VIs don’t have the file refnum input. How do I ensure that they execute in that order? This is where the error cluster comes in, it’s a common input between these different types of VIs and functions. So I’ll just put them in here, connect up the error clusters and now this Sine Waveform VI is waiting on the error cluster output from the Open/Create/Replace File, and the FFT Spectrum VI is doing the same, and so on.
Now do you feel that savory sweetness in your mouth? You’ve just had a taste of the LabVIEW dataflow paradigm. There’s plenty more to discuss but that’s all we have time for today, take a look at the text notes for this video for more information. “

(end transcription)

VI High 9: How Is Dataflow and Execution Order Determined in LabVIEW?

A common question for beginning LabVIEW programmers is: how is LabVIEW execution order determined? Does it flow left to right? Top to bottom? The answer is that it follows a dataflow execution model. In this episode, we examine what that is.

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 there are several ways of determining execution order. We will look at using the error cluster next time around, which is often the optimal way. Simply connecting the error cluster of VIs in a chain will force them to execute in the correct order.

Experience Level: Basic

(start transcription)

“I first saw a LabVIEW block diagram while working in a biomass combustion research lab at school. I looked at the block diagram and asked my senior research partner: how do you know what executes first? Does it go left to right? Top to bottom? He explained it as a mix of science, magic, and love and told me to get back to work building the reactor chamber. Let’s demystify, clarify, and understand dataflow and execution order.
Data in LV flows through nodes. Nodes are objects on the block diagram that have inputs and/or outputs and perform operations when a VI runs. In order to determine execution order, LabVIEW follows 2 dataflow rules:

1. An object executes when all data at its input terminals is available, and
2. An object outputs data from its output terminals when it has finished execution

For instance, this block diagram has 2 nodes: this add function and this multiply function. How can I determine which of these will execute first? Intuitively you may say that it’s the add function because it comes “first”, or it’s over to the left. But the real reason is that it meets the requirement for execution according to rule 1 that we just looked at: it has all the data available at both input terminals because both of these controls can immediately supply data to the terminals. Looking at the multiply function, we see the lower input can immediately receive its data from this constant, but the upper input is waiting on data from the output of the add function. And we know that the Add function won’t output its data until it has finished executing, according to rule 2. Thus we have an inherent execution order: the add function MUST execute before the multiply function. And if we watch in highlight execution, we see that’s precisely what happens.
Now let’s look at this block diagram. We have the chain of VIs we just examined, and then another like it. When I hit the run button, which of these functions will execute first? Obviously of the Add and Multiply functions, we know that the Add will execute first. And of the Subtract and Divide function, the Subtract will execute first. But which of the Add or Subtract functions will execute first? This is a bit more tricky as there does not exist a dataflow dependency between these 2 functions, in other words they don’t share inputs and outputs. In this case, LabVIEW will simply choose whichever it is more efficient for it to run first. This could be either, depending on a variety of factors.
Now we don’t want to give the impression that LV is erratic or unpredictable, because if we really wanted to dictate that one of these functions would go first we can do that very easily. However, in this case, by programming the block diagram in this manner, we’ve essentially told LV that we don’t care which of these will go first, and so LV just chooses one. There are several ways of dictating execution order, and we’ll take a look at that next time.
Now let’s combine these chains of functions. The question is, will the multiply or the divide function execute first? Think about it. The answer is still ‘we don’t know’. No doubt some of you thought that the Multiply function would definitely execute first. Let’s explore that line of reasoning. The rationale is that after the Add function executes, LV now has 2 choices of which to execute: the Multiply or the Subtract. If Subtract is chosen, then naturally LV will go back and execute the Multiply function. Right? No. Remember, that after the Subtract function executes, now there are 2 possible nodes that have all the necessary inputs in order to run: the Divide function and the Multiply function. So LV could execute either. And so the answer is again, we don’t know.
As I mentioned before, there are several ways of eliminating this question of which will go first, however, you don’t need to impatiently wait for the next episode to find that out. Take a look at the text description of this video or feel free to send us threatening and vulgar emails at labviewtraining at sixclear dot com.”

(end transcription)

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

(start transcription)

“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.”

(end transcription)