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.
(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)