In this tutorial you will learn about the functionality of sequence structures in LabView, and how where there are placed in the function palette. At the start a brief introduction of sequence structures is provided, after that sequence structures are explained with the help of a VI. At the end of the tutorial you are provided with an exercise to do it by yourself, and in the next tutorials I will assume that you have done those exercises and I will not explain the concept regarding them.
Introduction to Sequence Structures labview
We have already discussed case structure; the other structure that is used in LabView is Sequence Structure. Giving predetermined order to an action event which leads it to the next event is done in a sequence structure. Any number of actions can be predefined in a sequence structure but no action can be skipped from a sequence structure.
One or more small portions of a block diagram are included in a sequence structure, or frame of a sequence which needs to be executed sequentially. Data dependency determines the order of execution of a sequence within each frame of a sequence structure, as in the rest of the block diagram.
In LabView sequence structure is categorized in two major types:
- Flat sequence structure
- Stacked sequence structure.
It is preferable to reply on data flow rather than sequence structure to control the order of data execution. I will data flow in detail in upcoming tutorials. It is preferable to use sequence structure sparingly because they hide the code. Whenever you use a sequence local variable, you break the left-to-right data flow paradigm, with sequence structures.
Unlike case structures, there is only on data source available at the output tunnels of a sequence structure. We can take out the output from any of the frames of a sequence structures. Data at the input tunnels of a sequence structure is available to all the frames of a sequence structure, as we have done in case structures, no matter whether you are using a flat sequence or a stacked structure. It will be explained further in the explanation portion.
Examples of using sequence Structures labview
- Create a new VI and save it for future use. What we want to do now, is to design a block diagram that will run a while loop, and at the end of the loop it will display a message that will show “Loop completed”.
- At first we will design a while loop that will generate random numbers and plot them on a graph. We have already discussed all these things in previous tutorials; hence I am not going to explain this again. The block diagram of the while loop is shown in the figure below,
Figure 1: While loop block diagram
Figure 2: While loop front panel
- Now from the function palette in the block diagram window, select dialog and user interface and then select one button dialog as shown in the figure below,
Figure 3: One button dialog placement
Figure 4: One button dialog block
- At the input side of the one button dialog create a constant that will be a string constant by default, and inside the string write “Loop Completed”.
- We want this message to pop up when the loop completes, but when we run the VI the message will pop up at the instant when the VI is being run, without letting the loop to complete first, As shown in the figure below,
Figure 5: Results without sequence
- This happens because the control doesn’t know which block to run first and which later. It executes the whole block diagram at once. If we want to execute our code in a specified sequence we must provide it with a sequence.
- From the function palette select structures and then select flat sequence structure as shown in the figure below,
Figure 6: Placement of flat sequence
- After selecting the flat sequence structure drag the cursor over the area you want to be executed first in your block diagram as shown in the figure below,
Figure 7: Flat sequence
- After inserting the first sequence the block diagram will look like the one shown in the figure below,
Figure 8: Flat sequence diagram
- What next?? Now, we want to place the one button dialog in the next block of execution sequence. The flat sequence structure is always executed from left to right, hence the next blocks to be implemented after the loop must be placed on the right of the while loop.
- On the right wall of the flat sequence click right and from the dropdown menu select Add frame after, as shown in the figure below,
Figure 9: Add frame after
- This will add a frame after the main while loop frame of the flat sequence structure. Now, place the One button dialog inside the second sequence of the flat sequence structure as shown in the figure below,
Figure 10: Complete block diagram
- Now, when you run the VI this will only execute the while loop and display the waveform until you press the stop button and don’t display the loop completion message because of its lower priority in the sequence, refer to the figure below,
Figure 11: Running VI with sequence
- Now, if you press the stop button the loop will come to its completion and hence the first frame of the sequence will also complete and the control of the VI will move to the next frame of the sequence.
- As the next frame includes the loop completion message hence a message will pop up as shown in the figure below,
Figure 12: Sequence execution
- You can arrange the order of execution of as many tasks as you want. If you want to insert a block which you want to be executed before while loop then right click on left wall of the sequence and select Add frame before, as shown in the figure below,
Figure 13: Add frame before
- You can also insert frame in between two already existing frames by right clicking on the middle wall and then selecting Insert frame as shown in the figure below,
Figure 14: Insert frame.
- Now, lets’ talk about the stacked sequence structure, it is similar to the flat sequence except that the frames are stacked over each other as the name suggests “stacked sequence structures”. Right click on the frame of the flat sequence and from the dropdown menu select Replace with stacked sequence as shown in the figure below,
Figure 15: Replacing flat with stacked sequence
- The block diagram will look like the one shown in the figure below, after replacing the flat sequence in stacked sequence,
Figure 16: Stacked sequence frame 1
- The second frame i.e. the frame with the one button dialog is under the frame 1 and can be seen by using the selector label as we have done in case structures,
Figure 17: Stacked sequence frame 2
- You can also add and remove frame or frames in the stacked sequence as we have done in case of flat sequence, refer to the figure below,
Figure 18: Adding frame in stacked sequence
Stacked sequences are not recommended to use because they hide the part of the code although the code is being executed.
- Use time sequence and try to understand its functionality.
(Hint: Change the flat sequence to time sequence as you have change it into stacked sequence)
<<Previous tutorial Next tutorial>>