You are on page 1of 12

Appendix E: LabView Basic Instructions

1. VIRTUAL INSTRUMENTS

LabVIEW works on a data flow model in which information within a LabVIEW program, called
a virtual instrument (VI), flows from data sources to data sinks connected by wires. The data can
be modified as it is passed from source to sink by other VIs. LabVIEW supports two types of
VIs--internal VIs and user created VIs. Internal VIs are packaged with LabVIEW and perform
simple functions like adding numbers or opening files. User created VIs consist of both a
graphical user interface called the front panel and a code pipeline called the block diagram.
These VIs tend to be much more complex considering that they can contain any number of
internal or user created VIs in an endless number of configurations.

Consider a simplistic LabVIEW program which takes a single number from the user and
multiplies it by 10. Analyzing such a program reveals the following data flow structure:

2. The user inputs a number (data source).


3. The program executes an addition VI taking the user's number and the number 10 as its
inputs (data sink).
4. The addition VI returns the result of the addition operation (data source).
5. The result is displayed on the screen (data sink).

While this example is simplistic, it exemplifies how all LabVIEW VIs work. Data always flows
from data sources to data sinks according to the block diagram, much like how water flows
through a pipe.

1. FRONT PANEL

Every user created VI has a front panel that contains the graphical interface with which a user
interacts. The front panel can house various graphical objects ranging from simple buttons to
complex graphs. Various options are available for changing the look and feel of the objects on
the front panel to match the needs of any application.

2. BLOCK DIAGRAM

Nearly every VI has a block diagram containing some kind of program logic that serves to
modify data as it flows from sources to sinks. The block diagram houses a pipeline structure of
sources, sinks, VIs, and structures wired together in order to define this program logic. Most
importantly, every data source and sink from the front panel has its analog source and sink on the
block diagram. This representation allows the input values from the user to be accessed from the
block diagram. Likewise, new output values can be shown on the front panel by code executed in
the block diagram.
3. CONTROLS

The most common form of a data source in LabVIEW is a control. This element appears as some
type of graphical element on the front panel of a VI that can receive input from a user or even
another VI. As stated previously, any data source also has an analog symbol that appears on the
block diagram so that its value can be read and used in the code pipeline. Controls make no
exception to this rule.

Every control has an associated data type that determines what kind of data flows from it on the
block diagram. Every data type also has an associated color shown on the block diagram.

Figure 1: Typical controls and their associated data types.

In general, any control can be turned into an indicator and vice-versa.


4. INDICATORS

The most common form of a data sink in LabVIEW is an indicator. This element appears as
some type of graphical element on the front panel of a VI that can display output to a user or
even another VI. As stated previously, any data sink in LabVIEW also has an analog symbol that
appears on the block diagram so that its value can be updated in the code pipeline. Indicators
make no exception to this rule.

Every indicator also has an associated data type that determines what kind of data can be written
to it on the block diagram.
Figure 2: Typical indicators and their associated data types.

In general, any control can be turned into an indicator and vice-versa.

Figure 3: The front panel and block diagram for the simple number plus ten example given above.
It should be noted that the number control and answer indicator have their similarly named
analogs on the block diagram.
5. PALETTES

Front panel controls and indicators as well as block diagram VIs are available from a palettes
visible depending on what window is currently active in the LabVIEW environment. These
palettes have their contents separated into sub-categories containing controls, indicators, and VIs.
Figure 4: Typical top-level block diagram and front panel palettes.

6. STRUCTURES

In addition to controls, indicators, and VIs, the block diagram can also contain a number of
programming structures that modify the sequence of data flow on the block diagram. These
structures perform traditional functions like looping or case-selection, but many also provide
services that have no clear counterparts in text based programming languages. LabVIEW
currently supports six different structures: while-loops, case structures, event structures, for-
loops, sequence structures, and formula nodes.

1. While-loops

One of the most common structures encountered on a block diagram is the while-loop. Much like
in text-based languages, the LabVIEW while-loop continually executes until a given boolean
condition is met. Unlike in text-based languages, the LabVIEW while contains its own loop
counter that provides the current loop iteration starting at zero.
Figure 5: Three different ways of using a while-loop.

The first loop continues forever because the loop conditional never becomes false. The second
loop continues until a button on the front panel is pressed, sending a value of true to the loop
conditional thereby stopping the loop. The third loop also continues forever, but also displays the
current loop counter value in an indicator on the front panel. (It is important to note that these
three loops will execute in parallel because their inputs are not dependent on each other.)

The while-loop is typically used in LabVIEW to continue some operation until either the user or
some code event indicates that the operation should stop. Normally, some kind of millisecond
delay is also inserted into the loop so that it doesn't occupy all of the computer's CPU time.

Figure 6: while-loop
In the figure above there is a While Loop that will stop when the loop iterator passes 1000 or
when the user presses the stop button. A loop delay is also used to ensure that the loop operation
doesn't occupy all of the CPU time.

Nearly all structures in LabVIEW, including while-loops, can have inputs and outputs. Wires
that pass into and out of while-loops form small connection points called tunnels on the structure.
Various, powerful options are available for shaping data flowing through tunnels.

Figure 7: Input and output loop tunnels.

The while loops takes a numeric value through an input tunnel and multiplies it times its current
iteration value. When the loop is stopped, the value of the last multiplication is passed through an
output tunnel and displayed in another indicator.

2. For-loops

Another common looping structure encountered on a block diagram is the for-loop. Much like in
text-based languages, the LabVIEW for-loop continually executes until a given count is reached.
Unlike in text-based languages, the LabVIEW for-loop can only step towards the final count by
increasing the loop counter by one each iteration. To make larger steps or to step in the negative
direction, while-loops with shift registers must be used.

Figure 8: For-loop counter.


The loop runs from zero to ninety-nine and increases the loop counter by one each iteration.

This use of a for-loop is very common in most text-based languages, mainly because it is used to
traverse arrays. Surprisingly, this for-loop configuration is hardly ever encountered in LabVIEW,
not only because of its lack of stepping options, but also because there are more powerful
methods available for array traversal.

7. ARRAYS

In addition to many of the common data types discussed in the first lesson, LabVIEW also
supports array data structures. Like in text-based languages, LabVIEW arrays are n-dimensional
blocks of a single type of data indexed by numbers. Unlike in text-based languages, LabVIEW
arrays are dynamically resized to fit their data.

Figure 9: Three array controls.

In order from left to right, the arrays are a one-dimensional array of numerics, a two-dimensional
array of booleans, and a three-dimensional array of strings.

A variety of VIs are available for performing both simple and complex array operations. These
operations include, but are not limited to retrieving array elements, determining array size,
building arrays, sorting arrays, searching arrays, and reversing arrays.
Figure 10: Array searching.

The code searches the name array for the target and reports if the target is found as well as its
position in the array.

Many LabVIEW VIs, such as ones that perform arithmetic operations or compare values, are
polymorphic in that they can operate on many types of data, including arrays. For instance, not
only can the add VI find the sum of two numeric inputs, it can also find the individual sums of
elements in two arrays. This feature offers shortcuts to many operations that are traditionally
performed using loops in text-based languages.

Figure 11: Array addition.

In this case, the add VI adds each element in the first array to its counterpart in the second array.
8. CLUSTERS

Cluster data types are somewhat unique to LabVIEW and act as containers capable of storing a
number of variables of different data types. LabVIEW clusters have their analog in other text-
based languages in the form of simple objects like structs. In the simplest sense, clusters can be
thought of as a group of data values that are bundled together to form a more complex, and often
more meaningful, data type. From an object oriented perspective, clusters can be thought of as
primitive objects with a number of properties without any methods to acts on them.

Figure 12: A cluster with a number of elements.

This cluster can be thought of representing a set of properties of a college course that can flow as
a single object through the wires on the block diagram.
A number of operations exist for clusters, the most important of which are the bundling and
unbundling operations. Individual pieces of data flowing through different wires can be bundled
together to form a cluster that flows through a single wire. Likewise, a cluster flowing through a
single wire can be unbundled so that its elements can flow through their own wires.

Figure 13: Cluster bundling and unbundling.

The person cluster is unbundled to reveal its elements so that the age element can be increased
by one. The data is then bundled again to create a new cluster with the updated values. Notice
that the cluster elements are given by namer here.

Clustering is commonly used for two purposes. First, clusters help to logically group related data
values together, thus supporting the object oriented idea of encapsulation. Second, clusters help
to minimize the number of wires on the block diagram that flow into VIs. If clusters did not
exist, VIs with cluster inputs would have to receive all of their data through separate wires
leading to drastic decreases in readability.

9. CHARTS AND GRAPHS

LabVIEW has a number of advanced indicators that are capable of displaying numeric data in a
more visual manner than simply as numbers. The waveform chart and waveform graph indicators
are the most commonly used front panel elements for plotting numeric data collected from an
external source or generated through code. Both of these indicators have an overwhelming
number of options--including cursor tools, different plot types, and scaling options--only the
most basic of which are discussed here.

The waveform chart can be used a number of ways on the block diagram depending on the
desired result. First, the waveform chart can simply receive a single numeric value that is
appended to the data already plotted on the chart. Second, the waveform chart can receive an
array of values which are appended to the current plot. Third, the waveform chart can receive a
cluster of values which are plotted as different plots but within the same chart indicator. Fourth,
the waveform chart can be wired to a two-dimensional array of values, the rows of which are
plotted as separate plots within the same chart.
Figure 14: Three chart indicators front panel.

The indicators are wired in different configurations so that they plot the data slightly differently.
The graph at the top left draws a single plot one point at a time. The graph at the top right plots
an array of ten points for each point plotted on the other graphs. The bottom graph draws two
plots within the same indicator one point at a time each.

Figure 15: Three chart indicators block diagram.

Each chart receives data in a different format.

Waveform charts are typically used to show raw data collected from an external source or
generated programmatically because they easily plot data in real-time. However, waveform
charts do provide any information about timing when used in the four configurations shown
above. The charts only plot collected data values versus their number in the data collection
sequence. For example, if a single data point is collected from a source every second for ten
seconds, then the waveform chart will show the data points plotted as y-axis magnitudes x-axis
values running from zero to ten. If a single data point is collected from a source every hour for
ten hours, the chart will again show the exact same plot.

Timing information can be added to a waveform chart by using it in a fifth configuration. Wiring
a waveform data type to it, thereby specifying an array of data values, a time step, and an initial
time, causes the chart to use its x-axis to display timing information. This approach does yield a
more accurate description of the collected data by providing a proper scaling along the x-axis in
terms of time instead of in terms of simply data point numbers, but, often this extra information
is simply unnecessary for plotting raw data. A second indicator, a waveform graph, can be used
after the completion of the data collection process to show all of the data values along with the
proper timing information.

Figure 16: Chart with timing.


A waveform data type is repeatedly updated and sent to the chart so that timing information is
displayed along with the data values.

The waveform graph indicator differs from the chart indicator in the way it displays data wired to
it on the block diagram. Instead of appending data values to the end of the current plot, it erases
the current plot and displays the new data values as an entirely new plot. Clearly, this makes the
graph much more suitable to displaying data only after an entire collection process has
completed.

The waveform graph can also be used a number of ways on the block diagram depending on the
desired result. First, the graph can receive an array of values which are appended to the current
plot. Second, the waveform chart can be wired to a two-dimensional array of values, the rows of
which are plotted separately within the same indicator. Third, the waveform graph can be wired
to a waveform data type to include both timing and data values in the plot.
Figure 17: Three graph indicators front panel.

The indicators are wired in different configurations so that they plot the data slightly differently.
The graph at the top left plots a one-dimensional array of data points. The graph at the top right
plots a two-dimensional array of data points yielding two graphs. The bottom graph plots the
data values versus timing information instead of sequence numbers.

Figure 18: Three graph indicators block diagram.

Each chart receives data in a different format.

It is a standard practice to use waveform charts in conjunction with waveform graphs to display
data during data collection and during later analysis. Typically, charts are used in data collection
loops to allow a user to observe the data being collected in a clean, visual format. Once data
collection is complete, graphs are normally used to display the data to the user all at once and to
allow the user to manipulate and analyze the data using various tools built into the VI.
10. DOCUMENTATION

Full documentation can be created for any VI that can be later accessed by a user through the
context help window. This extremely helpful dialog shows all of the connections that can be
made to a VI and provides all of the VI's documentation. The context help window can be
accessed through the Help menu or by pressing Ctrl-H or Apple-H as appropriate.

Figure 19: The context help window.

The possible connections of the VI and its documentation are both given here. In many cases,
additional documentation is also provided through a link.

Documentation can be created for a VI by right clicking on the icon of the VI in the top right
corner of the front panel and selecting Properties. A number of options for configuring VIs are
available in this section, but the one of interest in this section can be selected as Documentation
from the drop down box. Anything typed into this text box is displayed in the context help
window when a user hover the mouse cursor over the icon of the VI either in the block diagram
or in the functions palette. Additionally, LabVIEW can automatically generate HTML
documentation for a number of VIs if documentation information has been entered here.

You might also like