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)