2. Graphical Programming
In a graphical programming language such as NI LabVIEW, the mouse is the main way to interact with the programming environment. That said, the mouse pointer must be able to accomplish many different tasks, such as selecting, wiring, highlighting text, and so on. This module examines the many functions that the mouse can accomplish in LabVIEW.
LabVIEW follows a dataflow model for running VIs. A block diagram node executes when it receives all required inputs. When a node executes, it produces output data and passes the data to the next node in the dataflow path. The movement of data through the nodes determines the execution order of the VIs and functions on the block diagram.
For a dataflow programming example, consider a block diagram that adds two numbers and then subtracts 50.00 from the result of the addition, as shown in Figure 1. In this case, the block diagram executes from left to right, not because the objects are placed in that order, but because the Subtract function cannot execute until the Add function finishes executing and passes the data to the Subtract function. Remember that a node executes only when data is available at all of its input terminals and supplies data to the output terminals only when the node finishes execution.
Figure 1. Dataflow Programming Example
In Figure 2, consider which code segment would execute first – the Add, Random Number, or Divide function. You cannot know because inputs to the Add and Divide functions are available at the same time, and the Random Number function has no inputs. In a situation where one code segment must execute before another, and no data dependency exists between the functions, use other programming methods, such as sequence structures or error clusters, to force the order of execution.
Figure 2. Dataflow Example for Multiple Code Segments
You transfer data among block diagram objects through wires. In figures 1 and 2, wires connect the control and indicator terminals to the Add and Subtract function. Each wire has a single data source, but you can wire it to many VIs and functions that read the data. Wires are different colors, styles, and thicknesses, depending on their data types.
Figure 3. Broken Wire Example
A broken wire appears as a dashed black line with a red X in the middle, as shown in Figure 3. Broken wires occur for a variety of reasons, such as when you try to wire two objects with incompatible data types. Table 1 shows the most common wire types.
Table 1. Common Wire Types
In LabVIEW, you use wires to connect multiple terminals together to pass data in a VI. You must connect the wires to inputs and outputs that are compatible with the data that is transferred with the wire. For example, you cannot wire an array output to a numeric input. In addition, the direction of the wires must be correct. You must connect the wires to only one input and at least one output. For example, you cannot wire two indicators together. The components that determine wiring compatibility include the data type of the control and/or the indicator and the data type of the terminal.
As you move a selected object close to other objects on the block diagram, LabVIEW draws temporary wires to show you valid connections. When you release the mouse button to place the object on the block diagram, LabVIEW automatically connects the wires. You also can automatically wire objects already on the block diagram. LabVIEW connects the terminals that best match and does not connect the terminals that do not match.
By default, automatic wiring is enabled when you select an object from the Functions palette or when you copy an object already on the block diagram by pressing the <Ctrl> key and dragging the object. Automatic wiring is disabled by default when you use the Positioning tool to move an object already on the block diagram.
You can adjust the automatic wiring settings by selecting Tools»Options and selecting Block Diagram from the Category list.
When you pass the Wiring tool over a terminal, a tip strip appears with the name of the terminal. In addition, the terminal blinks in the Context Help window and on the icon to help you verify that you are wiring to the correct terminal. To wire objects together, pass the Wiring tool over the first terminal, click, pass the cursor over the second terminal, and click again.
Take the short quiz below to evaluate your understanding of the concepts taught in the LabVIEW Graphical Programming video and detailed explanation.