You are on page 1of 25

LECTURE 5

JCB30304
DATA ACQUISITION SYSTEM
CHAPTER 2 : BASIC PROGRAMMING
MISS NUR FAZIRA HARIS
CHAPTER 2
 Boolean
 Array
 String
 Enum
Booleans
 LabVIEW stores Boolean data as 8-bit values. A Boolean can be used in
LabVIEW to represent a 0 or 1, or a TRUE or FALSE.
 If the 8-bit value is zero, the Boolean value is FALSE. Any nonzero value
represents TRUE.
 Common applications for Boolean data include representing digital data
and serving as a front panel control that acts as a switch that has a
mechanical action often used to control an execution structure such as a
Case structure.
 A Boolean control is typically used as the conditional statement to exit a
While Loop. In LabVIEW, the color green represents Boolean data.
Boolean Function
Comparison Functions
Example 5
LabVIEW provides a Select function that will perform one of two
actions depending on Boolean value. The function is available in either
of two groups on the Functions
Palette:
 Functions Palette / Express Group / Arithmetic & Comparison Group /
 Express Comparison Group / Select
 Functions Palette / Programming Group / Comparison Group / Select
For practice using the Select function, create a VI that will display
either the natural logarithm of a value, or the base 10 logarithm
depending on the position of a toggle switch.
Solution

The block diagram for this problem is shown on the left.


Notice that both logarithms are calculated, the Select
function is used to determine which value is displayed. The
toggle switch sends a Boolean value into the Select
function.
When the switch sends a True, the upper path of the Select function is used and the natural logarithm is passed to the
Result indicator.
When the switch sends a False, the lower path of the Select function is used and the base 10 logarithm is passed to the
Result indicator.
Exercise
 Problem 2.11
 Problem 2.12
 Exercise no 14
Array
 Until now, we've dealt with scalar numbers only (a scalar is simply a data type that
contains a single value, or "non-array"), and now it's time to move onto something
more powerful and compound.
 A LabVIEW array is a collection of data elements that are all the same type, just
like in traditional programming languages.
 An array can have one or more dimensions, and up to 231-1 elements per dimension
(memory permitting, of course). An array data element can have any type except
another array, a chart, or a graph.
 An array consists of elements and dimensions. Elements are the data that make up
the array. A dimension is the length, height, or depth of an array.
 You can build arrays of numeric, Boolean, path, string, waveform, and cluster data
types. Consider using arrays when you work with a collection of similar data and
when you perform repetitive computations.
Array
 Arrays are ideal for storing data you collect from waveforms or data
generated in loops, where each iteration of a loop produces one element
of the array.
 Array elements are accessed by their indices; each element's index is in the
range 0 to N-1, where N is the total number of elements in the array.
 The one-dimensional (1D) array shown here illustrates this structure. Notice
that the first element has index 0, the second element has index 1, and so
on.
Arrays
 On the Front Panel using the Control palette we can create an array
as follows (Array, Matrix & Cluster subpalette):

Array Shell

 Drag and drop the empty Array on the Front Panel, next you find a
Control or Indicator (Numeric, String, Boolean, etc,) and drag it into
the empty Array.
Arrays
 You can create an Array of (almost)any kind of
Control or Indicator.

Front panel showing an empty array shell (A) and three populated array shells (B)
Arrays
 2D or multidimensional Array?
Just drag the mouse in the
Index display to the left and
increase the dimension.

 On the Block Diagram we


have the following Array
palette available from the
Functions palette in LabVIEW.
Arrays
 Use the Array functions to create and manipulate arrays.
 The most useful Array functions are:

 All these functions are basic (but very useful) array functions
you will probably be using in all your applications and Vis.
Polymorphism
 All LabVIEW arithmetic functions are polymorphic.
 This means that the inputs to these functions can be different data
structures such as scalar values and arrays.
 By definition polymorphism is said to be the ability of a numeric
function to adjust to input data of different data structures.
 For example, the Add function can be used in the following ways.
1. Scalar + Scalar = Scalar addition.
2. Scalar + Array = The scalar is added to each element of array.
3. Array + Array = Each element of one array is added to the corresponding
element of other array.
Polymorphism
(a) Adding two scalar values

(b) adding a scalar value with an array


Polymorphism
(c) adding two arrays of the same size

(d) adding two arrays of different sizes


Polymorphism
 Polymorphism does not perform matrix arithmetic
when inputs are two-dimensional arrays (for
example, two two-dimensional array inputs to a
multiply function do element by element
multiplication, not matrix multiplication).
 Polymorphism is the ability of a function to adjust to
input data of different data structures.
Example 6
 Page 106
1. Problem 5.1
2. Problem 5.3
3. Problem 5.9
Strings
 A string is a sequence of displayable or non displayable ASCII characters.
 Strings provide a platform-independent format for information and data. Some of the more
common applications of strings include the following:
 Creating simple text messages.
 Controlling instruments by sending text commands to the instrument and returning data values in the
form of either ASCII or binary strings, which you then convert to numeric values.
 Storing numeric data to disk. To store numeric data in an ASCII file, you must first convert numeric data
to strings before writing the data to a disk file.
 Instructing or prompting the user with dialog boxes.
 On the front panel, strings appear as tables, text entry boxes, and labels. LabVIEW includes
built-in VIs and functions you can use to manipulate strings, including formatting strings, parsing
strings, and other editing.
 LabVIEW represents string data with the color pink.
Example 7
1. Page 44 problem 2.13
Enum
 An enum (enumerated control, constant or indicator) is a
combination of data types.
 An enum represents a pair of values, a string and a numeric,
where the enum can be one of a list of values.
 For example, if you created an enum type called Month, the
possible value pairs for a Month variable are January-0,
February-1, and so on through December-11.
 Figure 6 shows an example of these data pairs in the
Properties dialog box for an enumerated control.
Enum

Figure 6: Properties for the Month Enumerated Control


Enum
 Enums are useful because
it is easier to manipulate
numbers on the block
diagram than strings.
 Figure 7 shows the Month
enumerated control, the
selection of a data pair in
the enumerated control,
and the corresponding Figure 7: Month Enumerated Control
block diagram terminal.
THANK YOU

You might also like