Laboratory Virtual Instrument Engineering Workbench (LabVIEW) is a design platform developed by National Instruments. It uses a visual programming language named 'G' that helps the developers in graphically building the systems. The text-based code is replaced by graphical icons. The systems are built with a combination of software and hardware. The developers can add hardware and represent complex logic on the diagram. Structures are important while building complex logic for the diagrams. In this post, you will learn about various structures available in LabVIEW. You can also get to know how to use these structures.
The structures in LabVIEW contain sections of graphical code. They control and determine when and how the code should be run in a virtual instrument (VI). A structure can be referred to as a graphical representation of a loop. It helps in iterating a piece of code as many times as we want.
Open LabVIEW, and open the Front Panel. Click on the 'View' option from the top menu and select 'Functions'. Choose the 'Programming' option and click on the 'Structures' icon. You will get a list of all the structures of LabVIEW. To use a structure, drag and drop them on to the block diagram.
LabVIEW offers different kinds of structures that serve different purposes. Here is the list of structures that are available in LabVIEW.
Let's discuss in detail each of these structures and how to implement them.
The While loop is very much similar to the Do While loop we have in any text-based programming language. It executes a piece of code (a subdiagram) until a stop condition occurs. The While loop executes at least one time. It is mostly used to keep a program running until a user clicks on the stop button.
When you want to place a subdiagram in a while loop, select the While loop from the Structures palette. You will get a cursor through which you can drag a selection rectangle around the diagram that you want to repeat. Once you release the cursor, you can observe a While loop boundary around the section that you selected. Then, you can proceed and add any block diagram objects that you want to the loop. The iteration terminal on the loop is the output terminal, and it stores the number of iterations that are complete. The iteration count in the iteration terminal always starts with 0.
A Foor loop iterates for a specific number of times. It executes the subdiagram within the block for n time, where n is the value wired to the count terminal. The count terminal is the input terminal that indicates how many times to repeat the subdiagram. The iteration terminal on the loop is the output terminal that indicates the current loop iteration count. The iteration count always starts at 0 and it ranges from 0 to n-1
A For loop might not execute sometimes in a VI when the condition is not met. We can change a While loop to a For loop. To do so, right-click on the border of the While loop and select the 'Replace with For Loop' option from the shortcut menu.
A sequential structure is used when a subdiagram should be executed in a linear process or a sequential order. Most of the calculations in LabVIEW might execute in a parallel fashion. So these calculations are forced to follow a sequential order from left to right. This way, we will have control over the order of execution.
A sequential structure is especially used when the next calculation is dependant on the current input. The output tunnel can have only one data source and the output can come from any frame. There are two types of sequence structures.
The flat sequence structure is used to execute frames from left to right. The data values to the frames have to be wired properly. When a frame execution is complete, the data leaves the frame. The input of one frame might depend on the output of the previous frame.
A flat structure is very flexible. When a frame is added or deleted, it will resize automatically. We can change a flat sequence to a stacked sequence. If we do that, all the input terminals of the frames will be moved to the first frame of the stacked sequence. When we change the stacked sequence to a flat sequence, we have to move the wires of the first frame to their original locations, i.e., individual frames.
In a stacked sequence structure, all the frames are stacked together to look like a single frame. So you can only see one frame at a time. It many reduces the space, so you will have more room on the block diagram. It starts the execution from frame 0. To pass data between the frames, we have to use sequence locals. It returns the output data after the last frame executes.
To rearrange the frames or to navigate through the frames, we have to use the sequence selector identifier. It always shows the currently executing frame and also the range of frames. The frame label in a stacked sequence structure contains frame number at the center with decrement and increment arrows on each side. When we add a frame to the stacked sequence structure, the frame label automatically adjusts the numbers.
An event structure contains one or more subdiagrams. When an event occurs, it handles the event and executes the appropriate case. The event structure waits for an event for a specific time, and it then time-outs. We have to wire a timeout terminal to the left of the event structure and specify the number of milliseconds for the event structure to wait for an event. The default timeout value is -1, which indicates never to timeout.
As an event structure can have multiple cases or subdiagrams, only one case can occur at a time. If you want to handle multiple events, place the event structure in a While loop. A case in an event structure cannot handle both notify and filter events.
A timed structure can contain one or more subdiagrams (or frames) that execute sequentially based on an internal or external timing source. It executes a frame only once and does not repeat iterations. When we want to design a VI that executes only once at a precise time or execution feedback, we can use a timed sequence structure.
Each frame in a timed structure contains input nodes, output nodes, and data nodes on the left and right sides of the frame. The nodes of the timed structure do not show the input and output terminals by default. We have to resize the frame to take a look at node terminals.
A diagram disable structure is used to disable a section of the diagram that we don't want to execute. It's like commenting out a piece of code in a text-based programming language. Place the diagram disable structure around the subdiagram that we want to disable. Once the structure is added, we can add, duplicate, rearrange, or delete the subdiagrams.
There will be a selector label through which we can scroll through the subdiagrams in the diagram disable structure. We can also remove the structure without removing the subdiagrams in it.
When we have some subdiagrams to execute depending on a condition, we can use a conditional disable structure. We can disable a subdiagram on the block diagram, so it executes based on a user-defined condition. Place a conditional disable structure on the block diagram, and add a subdiagram to it. Right-click on the border of the structure and select the 'Edit Condition For This Subdiagram' option.
We will get a configure condition dialog box where we can configure conditions. It also provides pre-defined symbols to configure conditions. We will have a selector label to scroll through the available subdiagrams in the structure. When we delete the structure, the subdiagrams won't get deleted.
In this post, we have explained in detail about all the structures in LabVIEW. Using structures will make the programming easy for developers. LabVIEW has introduced them, so the developers can execute the subdiagrams according to their needs. Try out different structures in the development of VI in LabVIEW.
Batch starts on 20th Apr 2021, Weekday batch
Batch starts on 24th Apr 2021, Weekend batch
Batch starts on 28th Apr 2021, Weekday batch