You are on page 1of 199

VIRTUAL INSTRUMENTATION

Lab 1
Data Acquisition
with cDAQ while
Getting Familiar
with LabVIEW
Section 1 – Data Acquisition with cDAQ while Getting
Familiar with LabVIEW
---------------------------------------------------------------------------  2
Part 1 – Configuring Hardware
---------------------------------------------------------------------------  3
Part 2 – Using LabVIEW Express VIs
---------------------------------------------------------------------------  4
Part 3 – Using Low Level DAQmx VIs
---------------------------------------------------------------------------  5
Data Acquisition with cDAQ while Getting Familiar with LabVIEW | Laboratory 1

Section 1
Data Acquisition with cDAQ
while Getting Familiar with
LabVIEW
In this lab, you will start your temperature monitoring program. The first step that you will
take is measuring the voltage across the thermistor. Thermistors are a type of resistor which
have different resistances at different temperatures. By building a voltage divider, we can
measure the voltage across the thermistor. Then we will use a pre-built program to calculate
the resistance and convert that to a temperature.

You will then explore the LabVIEW environment through data acquisition by contrasting
Express VIs with Low Level DAQmx VIs.

Parts List:
The following equipment is required for this
experiment:

-- 1 10kΩ resistor
-- 1 10kΩ thermistor, EPCOS B57164K103J
-- 1 100nF capacitor
-- Breadboard
-- Wires

Virtual Instrumentation 2
Data Acquisition with cDAQ while Getting Familiar with LabVIEW | Laboratory 1

Procedure
Part 1 – Configuring Hardware
1) Use the Getting Started: How to Configure Your System document to ensure that your
system is ready to use.

2) Build the following circuit in order +5V


to measure the thermistor.

3) From the cDAQ Analoq Input card,


connect input channel 1 across the AI1+
thermistor. Connect AI1 + and AI1 - RT
to the two end of the thermistor.

4) If you don’t have a 5V output line,


AI1-
you can use an analog output line
and output a voltage of 5V. C R
0.1µF 10kΩ

GND

Virtual Instrumentation 3
Data Acquisition with cDAQ while Getting Familiar with LabVIEW | Laboratory 1

Part 2 – Using LabVIEW Express VIs


1) Open LabVIEW and select File>>New to open a blank VI.

2) Right-click on the Block Diagram to access the Functions Palette.

3) Navigate to Measurement I/O, and pin down the palette by clicking the pushpin icon at the
top of the Functions Palette.

4) Notice that the Measurement I/O Palette contains sub-palettes for DAQmx.

5) Click on the DAQmx icon on the Measurement I/O palette and locate the DAQ Assistant
Express VI. Drag the DAQ Assistant onto the Block Diagram.

6) When the configuration window opens, choose Acquire Signals>>Analog Input>>Voltage.

7) Choose Channel AI1 of the cDAQ Analog Input card.

8) Take note of the default settings of the DAQ Assistant and select OK.

9) Right-click the Data output terminal of the DAQ Assistant and select Create>>Graph
Indicator.

10) Ensure that your code matches the


image shown here, and click the run
arrow.

Notice that the graph on the Front


Panel displays voltage measure-
ments from the thermistor, similar
to the image shown here.

Virtual Instrumentation 4
Data Acquisition with cDAQ while Getting Familiar with LabVIEW | Laboratory 1

Part 3 – Using Low Level DAQmx VIs


1) Open a blank VI.

2) Access the DAQmx Palette located on the Measurement I/O Palette.

3) Place the Create Channel, Timing, Read, and Clear Task VIs on the Block Diagram.

4) Ensure that the Create Channel VI is configured for AI Voltage.

5) Right-click on the Physical Channels input to the VI and select Create>>Constant. Select AI1
of your cDAQ Analog Input card.

6) Wire the Error Out and Task Out terminals of the Create Channel VI to the Error In and Task In
terminals of the Timing VI respectively.

7) Create a constant for the rate on the Timing VI and set it to 1000.

8) Create a constant for Samples per Channel and set it to 100.

9) Create a constant for Sample Mode and set it to Finite Samples.

10) Wire the Error Out and Task Out terminals of the Timing VI to the Error In and Task In
terminals of the Read VI respectively.

11) Click the down arrow on the Read VI and select Analog>>Single Channel>>Multiple
Samples>>Waveform.

12) Switch to the Front Panel and right click to access the Controls Palette. Locate the Graph
sub-palette under Programming and place a Waveform Graph on the Front Panel.

13) Return to the Block Diagram and wire the Data output terminal of the Read VI to the
Waveform Graph.

14) Wire the Error Out and Task Out terminals of the Read VI to the Error In and Task In terminals
of the Clear Task VI respectively.

Virtual Instrumentation 5
Data Acquisition with cDAQ while Getting Familiar with LabVIEW | Laboratory 1

15) Ensure that your code matches the


image shown here.

16) Run the VI and notice that it


measures data which is similar to
before.

17) Stop the LabVIEW code when done.

18) Save the VI as Data Acquisition with


cDAQ.vi. We will build on this code
in subsequent labs.

Virtual Instrumentation 6
Data Acquisition with cDAQ while Getting Familiar with LabVIEW | Laboratory 1

Questions
1) Outline the general idea of how analog input data acquisition works in hardware.
What do the data acquisition VIs do?

2) Outline the similarities and differences between using the Express VI and the low level
DAQmx VIs

3) Explore the DAQmx palette and look for features that you can access with the low level
DAQ VIs. What could be possible benefits of using the low level DAQmx VIs?

4) One application of the simple code made in this lab, instead of measuring the voltage
across a thermistor, would be testing a battery to determine if it is fully charged.
Using this code, the voltage of the battery could be read and compared to what is expected.
What are three other applications you can think of for this code?

Virtual Instrumentation 7
VIRTUAL INSTRUMENTATION

Lab 1
Data Acquisition
with ELVIS while
Getting Familiar
with LabVIEW
Section 1 – Data Acquisition with ELVIS while Getting
Familiar with LabVIEW
---------------------------------------------------------------------------  2
Part 1 – Configuring Hardware
---------------------------------------------------------------------------  3
Part 2 – Using LabVIEW Express VIs
---------------------------------------------------------------------------  4
Part 3 – Using Low Level DAQmx VIs
---------------------------------------------------------------------------  5
Data Acquisition with ELVIS while Getting Familiar with LabVIEW | Laboratory 1

Section 1
Data Acquisition with ELVIS
while Getting Familiar with
LabVIEW
In this lab, you will start your temperature monitoring program. The first step that you will
take is measuring the voltage across the thermistor. Thermistors are a type of resistor which
have different resistances at different temperatures. By building a voltage divider, we can
measure the voltage across the thermistor. Then we will use a pre-built program to calculate
the resistance and convert that to a temperature.

You will then explore the LabVIEW environment through data acquisition by contrasting
Express VIs with Low Level DAQmx VIs.

Parts List:
The following equipment is required for this
experiment:

-- 1 10kΩ resistor
-- 1 10kΩ thermistor, EPCOS B57164K103J
-- 1 100nF capacitor
-- Breadboard
-- Wires

Virtual Instrumentation 2
Data Acquisition with ELVIS while Getting Familiar with LabVIEW | Laboratory 1

Procedure
Part 1 – Configuring Hardware
1) Use the Getting Started: How to Configure Your System document to ensure that your
system is ready to use.

2) Build the following circuit in order +5V


to measure the thermistor.

3) From the NI ELVIS, connect input


channel 1 across the thermistor. AI1+
Connect AI1 + and AI1 - to the two RT
end of the thermistor.

AI1-
C R
0.1µF 10kΩ

GND

Virtual Instrumentation 3
Data Acquisition with ELVIS while Getting Familiar with LabVIEW | Laboratory 1

Part 2 – Using LabVIEW Express VIs


1) Open LabVIEW and select File>>New to open a blank VI.

2) Right-click on the Block Diagram to access the Functions Palette.

3) Navigate to Measurement I/O, and pin down the palette by clicking the pushpin icon at the
top of the Functions Palette.

4) Notice that the Measurement I/O Palette contains sub-palettes for DAQmx.

5) Click on the DAQmx icon on the Measurement I/O palette and locate the DAQ Assistant
Express VI. Drag the DAQ Assistant onto the Block Diagram.

6) When the configuration window opens, choose Acquire Signals>>Analog Input>>Voltage.

7) Choose Channel AI1 of the NI ELVIS.

8) Take note of the default settings of the DAQ Assistant and select OK.

9) Right-click the Data output terminal of the DAQ Assistant and select Create>>Graph
Indicator.

10) Ensure that your code matches the


image shown here, and click the run
arrow.

Notice that the graph on the Front


Panel displays voltage measure-
ments from the thermistor, similar
to the image shown here.

Virtual Instrumentation 4
Data Acquisition with ELVIS while Getting Familiar with LabVIEW | Laboratory 1

Part 3 – Using Low Level DAQmx VIs


1) Open a blank VI.

2) Access the DAQmx Palette located on the Measurement I/O Palette.

3) Place the Create Channel, Timing, Read, and Clear Task VIs on the Block Diagram.

4) Ensure that the Create Channel VI is configured for AI Voltage.

5) Right-click on the Physical Channels input to the VI and select Create>>Constant. Select AI1
of your NI ELVIS.

6) Wire the Error Out and Task Out terminals of the Create Channel VI to the Error In and Task In
terminals of the Timing VI respectively.

7) Create a constant for the rate on the Timing VI and set it to 1000.

8) Create a constant for Samples per Channel and set it to 100.

9) Create a constant for Sample Mode and set it to Finite Samples.

10) Wire the Error Out and Task Out terminals of the Timing VI to the Error In and Task In
terminals of the Read VI respectively.

11) Click the down arrow on the Read VI and select Analog>>Single Channel>>Multiple
Samples>>Waveform.

12) Switch to the Front Panel and right click to access the Controls Palette. Locate the Graph
sub-palette under Programming and place a Waveform Graph on the Front Panel.

13) Return to the Block Diagram and wire the Data output terminal of the Read VI to the
Waveform Graph.

14) Wire the Error Out and Task Out terminals of the Read VI to the Error In and Task In terminals
of the Clear Task VI respectively.

Virtual Instrumentation 5
Data Acquisition with ELVIS while Getting Familiar with LabVIEW | Laboratory 1

15) Ensure that your code matches the


image shown here.

16) Run the VI and notice that it


measures data which is similar to
before.

17) Stop the LabVIEW code when done.

18) Save the VI as Data Acquisition with


ELVIS.vi. We will build on this code
in subsequent labs.

Virtual Instrumentation 6
Data Acquisition with ELVIS while Getting Familiar with LabVIEW | Laboratory 1

Questions
1) Outline the general idea of how analog input data acquisition works in hardware.
What do the data acquisition VIs do?

2) Outline the similarities and differences between using the Express VI and the low level
DAQmx VIs

3) Explore the DAQmx palette and look for features that you can access with the low level
DAQ VIs. What could be possible benefits of using the low level DAQmx VIs?

4) One application of the simple code made in this lab, instead of measuring the voltage
across a thermistor, would be testing a battery to determine if it is fully charged.
Using this code, the voltage of the battery could be read and compared to what is expected.
What are three other applications you can think of for this code?

Virtual Instrumentation 7
VIRTUAL INSTRUMENTATION

Lab 2
Applying Signal
Conditioning to
a Thermistor
Measurement
Section 1 - Applying Signal Conditioning to a
Thermistor Measurement
---------------------------------------------------------------------------  2
Creating Signal Conditioning
---------------------------------------------------------------------------  3
Applying Signal Conditioning to a Thermistor Measurement | Laboratory 2

Section 1
Applying Signal Conditioning
to a Thermistor Measurement
In this lab, you will take the voltage measured in lab 1 and convert it to a temperature. In
typical data acquisition programs, the data is measured as raw voltages or currents. Typically,
the sensor that is being measured will have a specification which indicates how that sensor
converts from voltages into engineering units. For example, a range sensor might output a
range from 0 volts to +5 volts, which corresponds to engineering units of 0 centimeters to 100
centimeters.

In your program, you will need to make that conversion between volts and engineering units.
This is one of the stages of a process called signal conditioning.
In this lab, you will use a pre-built program to calculate the resistance of the thermistor and
convert that value to a temperature.

Parts List:
The following equipment is required for this
experiment:

-- Digital Multimeter (same as lab 1)


-- 1 10kΩ resistor
-- 1 10kΩ thermistor, EPCOS B57164K103J
-- 1 100nF capacitor
-- Breadboard
-- Wires

Virtual Instrumentation 2
Applying Signal Conditioning to a Thermistor Measurement | Laboratory 2

Procedure
Creating Signal Conditioning
1) The conversion from a voltage measurement to a temperature measurement is dependent
on the exact resistance of the 10k resistor. For this reason, you’ll need to measure the
resistance and note the result before continuing.

2) Open the Data Acquisition with cDAQ.vi file from the previous lab.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

3) Browse to the block diagram by pressing <Ctrl+E>.

4) Right-click the block diagram to open the Functions Palette.

5) Click the Search button at the top right of the Functions Palette.

6) In the Search window, search for


“thermistor”.

7) Double-click “Convert Thermistor


Reading.vi”.

8) Drag the “Convert Thermistor Reading”


onto the block diagram to the right of the Waveform Graph.

9) Connect the Voltage input of the Convert Thermistor Reading function to the Waveform
wire.

10) Delete the wire to the Waveform Graph, move the Waveform Graph terminal to the right of
the Convert Thermistor Reading function, and wire the Temperature output of the function
to the terminal.

Virtual Instrumentation 3
Applying Signal Conditioning to a Thermistor Measurement | Laboratory 2

11) Right-click the Voltage Reference


input of the Convert Thermistor
Reading function and select
Create>>Constant. Set the value to 5.

12) Create constants for the R1, Type of


Excitation, and Temperature Units
(C) inputs.

13) You can drag the constants around


on the block diagram to organize
them more cleanly, if desired.

14) Set the R1 value to the resistance of


the 10k resistor that you measured,
in Ohms. We’ve set it to 9,756Ω, in
our example.

15) Leave the other two constants with


values of Voltage Reference and
Celsius.

16) Run the VI and notice that the


measurements are now displayed in
units of Celsius, close to values of 20
degrees.

17) If you put your fingers on the


thermistor and run the program
again, you will notice that the
temperature increased.

18) Save the VI as Data Acquisition with


cDAQ - Signal Conditioning.vi. We
will build on this code in subsequent
labs.

Virtual Instrumentation 4
Applying Signal Conditioning to a Thermistor Measurement | Laboratory 2

Questions
1) Why is it important to convert a measured signal from raw measurements to engineering
units?

2) How could you easily convert the temperature to degrees Fahrenheit?

3) Why is it important to set the measured resistance of the 10k resistor?

Virtual Instrumentation 5
VIRTUAL INSTRUMENTATION

Lab 2
Applying Signal
Conditioning to
a Thermistor
Measurement
Section 1 - Applying Signal Conditioning to a
Thermistor Measurement
---------------------------------------------------------------------------  2
Creating Signal Conditioning
---------------------------------------------------------------------------  3
Applying Signal Conditioning to a Thermistor Measurement | Laboratory 2

Section 1
Applying Signal Conditioning
to a Thermistor Measurement
In this lab, you will take the voltage measured in lab 1 and convert it to a temperature. In
typical data acquisition programs, the data is measured as raw voltages or currents. Typically,
the sensor that is being measured will have a specification which indicates how that sensor
converts from voltages into engineering units. For example, a range sensor might output a
range from 0 volts to +5 volts, which corresponds to engineering units of 0 centimeters to 100
centimeters.

In your program, you will need to make that conversion between volts and engineering units.
This is one of the stages of a process called signal conditioning.
In this lab, you will use a pre-built program to calculate the resistance of the thermistor and
convert that value to a temperature.

Parts List:
The following equipment is required for this
experiment:

-- Digital Multimeter (same as lab 1)


-- 1 10kΩ resistor
-- 1 10kΩ thermistor, EPCOS B57164K103J
-- 1 100nF capacitor
-- Breadboard
-- Wires

Virtual Instrumentation 2
Applying Signal Conditioning to a Thermistor Measurement | Laboratory 2

Procedure
Creating Signal Conditioning
1) The conversion from a voltage measurement to a temperature measurement is dependent
on the exact resistance of the 10k resistor. For this reason, you’ll need to measure the
resistance and note the result before continuing.

2) Open the Data Acquisition with ELVIS.vi file from the previous lab.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

3) Browse to the block diagram by pressing <Ctrl+E>.

4) Right-click the block diagram to open the Functions Palette.

5) Click the Search button at the top right of the Functions Palette.

6) In the Search window, search for


“thermistor”.

7) Double-click “Convert Thermistor


Reading.vi”.

8) Drag the “Convert Thermistor Reading”


onto the block diagram to the right of the Waveform Graph.

9) Connect the Voltage input of the Convert Thermistor Reading function to the Waveform
wire.

10) Delete the wire to the Waveform Graph, move the Waveform Graph terminal to the right of
the Convert Thermistor Reading function, and wire the Temperature output of the function
to the terminal.

Virtual Instrumentation 3
Applying Signal Conditioning to a Thermistor Measurement | Laboratory 2

11) Right-click the Voltage Reference


input of the Convert Thermistor
Reading function and select
Create>>Constant. Set the value to 5.

12) Create constants for the R1, Type of


Excitation, and Temperature Units
(C) inputs.

13) You can drag the constants around


on the block diagram to organize
them more cleanly, if desired.

14) Set the R1 value to the resistance of


the 10k resistor that you measured,
in Ohms. We’ve set it to 9,756Ω, in
our example.

15) Leave the other two constants with


values of Voltage Reference and
Celsius.

16) Run the VI and notice that the


measurements are now displayed in
units of Celsius, close to values of 20
degrees.

17) If you put your fingers on the


thermistor and run the program
again, you will notice that the
temperature increased.

18) Save the VI as Data Acquisition with


ELVIS - Signal Conditioning.vi. We
will build on this code in subsequent
labs.

Virtual Instrumentation 4
Applying Signal Conditioning to a Thermistor Measurement | Laboratory 2

Questions
1) Why is it important to convert a measured signal from raw measurements to engineering
units?

2) How could you easily convert the temperature to degrees Fahrenheit?

3) Why is it important to set the measured resistance of the 10k resistor?

Virtual Instrumentation 5
VIRTUAL INSTRUMENTATION

Lab 3
Loops, Case
Structures,
and Timing

Section 1 - Loops, Case Structures, and Timing


---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Part A
---------------------------------------------------------------------------  3
Part B
---------------------------------------------------------------------------  4
Loops, Case Structures, and Timing | Laboratory 3

Section 1
Loops, Case Structures, and
Timing
In this lab, you will expand upon the code you created in Lab 2 in order to continuously measure
temperature with the thermistor. The application that we’re trying to build is implementing a
temperature monitor. Monitoring applications need to continuously read data from the sensor
that they’re monitoring, therefore we will need to continuously monitor the temperature.

To do this, you will explore While Loops, For Loops and Case Structures. By the end of this lab,
you should understand the functionality of each type of loop or structure and how they are
different. You should also understand the effects of implementing timing in a VI.

Pre-Lab Questions:
1) Based on your classroom understanding of While Loops, For Loops, and Case Structures, if
we stated that we wanted to do a continuous acquisition, what loop or structure would we
choose?

2) Where in the code shown would you


place the loop or structure that you
think is most appropriate to create a
continuous acquisition?

Virtual Instrumentation 2
Loops, Case Structures, and Timing | Laboratory 3

Procedure
Configuring Hardware
1) Keep the same wiring configuration as in Lab 1 and 2.

Part A
1) Open the VI that you created in Lab 2, Data Acquisition with cDAQ - Signal Conditioning.vi.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Copy and paste the code from Lab 2 into a new VI.

3) Close the code from Lab 2.

4) On the Timing VI, change the Sample Mode to be Continuous.

5) Change the Rate to 500 and leave the Samples per Channel at 100. This modifies the
settings of the buffer that data is written to.

6) Drag the Close VI so that it is to the right of the Waveform graph.

7) Place a While Loop around the Read VI, the Convert Thermistor Reading VI and the
Waveform Graph indicator.

8) Create a Stop Control for the Loop Condition Terminal of the While Loop by right-clicking on
the input to the Loop Condition Terminal and selecting Create>>Control.

9) Change the Waveform Graph to a Waveform Chart by right-clicking on the graph on the
Front Panel and choosing Replace. Navigate to the Graph palette and choose a Waveform
Chart.

10) On the Front Panel, right-click on the Waveform Chart and select Properties.

11) On the Scales tab, uncheck Auto-Scale for the x-axis and change the minimum to 0 and the
maximum to 0.1.

12) Click Ok to close.

Virtual Instrumentation 3
Loops, Case Structures, and Timing | Laboratory 3

13) Stop the VI and add a 250ms Wait


(ms) function to the While Loop.
Ensure that your code matches the
image shown.

14) Run the VI and note the change in


the behavior of the waveform.

15) Stop the VI when you’re done.

Part B
1) Wire AI2 + of the Analog Input card to the +5V Supply and wire AI2- to Ground.

2) Put a Case Structure around the Create Channel VI and its corresponding terminals.

3) Navigate to the False Case and add a new Create Channel VI to the Case Structure. Choose
Channel AI2 of your device for this case.

4) Wire the Error Out and Task Out of the new Create Channel VI to the Task and Error terminals
on the right side of the Case Structure.

5) Wire a Boolean Control to the Case Selector of the Case Structure by right-clicking the input
terminal of the Case Selector and selecting Create>>Control.

6) Ensure that your code matches the


image shown.

Virtual Instrumentation 4
Loops, Case Structures, and Timing | Laboratory 3

7) Click the Boolean Control on the Front Panel so that it is in the True state. Run the VI. Notice
that the same waveform is created as in Part A of this Lab.

8) Stop the VI and click the Boolean Control on the Front Panel so that it is in the False state.

9) Run the VI and notice that a constant 5V signal is produced.

10) Explore changing the scale of the waveform chart to zoom in on the signal.

11) Stop the VI.

12) Save the VI as Structures.vi.

Virtual Instrumentation 5
Loops, Case Structures, and Timing | Laboratory 3

Questions
1) What are three differences between a While Loop and a For Loop?

2) Comparing Lab 1 and Lab 3, why do you suppose we do not typically use for loops for data
acquisition?

3) What is the output of the For Loop


shown?

4) Comparing Lab 1 and Lab 3, why do you suppose we do not typically use for loops for data
acquisition?

Virtual Instrumentation 6
Loops, Case Structures, and Timing | Laboratory 3

5) What was the effect of putting the Wait in the While Loop, and why is it good to use waits?

6) Why does clicking the True/False control on the Front Panel not have any effect while the VI
is running?

7) What is another type of control that could have been wired to the Case Structure Selector
Terminal that would have given the ability to associate a title with each case that could be
selected on the Front Panel?

Virtual Instrumentation 7
VIRTUAL INSTRUMENTATION

Lab 3
Loops, Case
Structures,
and Timing

Section 1 - Loops, Case Structures, and Timing


---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Part A
---------------------------------------------------------------------------  3
Part B
---------------------------------------------------------------------------  4
Loops, Case Structures, and Timing | Laboratory 3

Section 1
Loops, Case Structures, and
Timing
In this lab, you will expand upon the code you created in Lab 2 in order to continuously measure
temperature with the thermistor. The application that we’re trying to build is implementing a
temperature monitor. Monitoring applications need to continuously read data from the sensor
that they’re monitoring, therefore we will need to continuously monitor the temperature.

To do this, you will explore While Loops, For Loops and Case Structures. By the end of this lab,
you should understand the functionality of each type of loop or structure and how they are
different. You should also understand the effects of implementing timing in a VI.

Pre-Lab Questions:
1) Based on your classroom understanding of While Loops, For Loops, and Case Structures, if
we stated that we wanted to do a continuous acquisition, what loop or structure would we
choose?

2) Where in the code shown would you


place the loop or structure that you
think is most appropriate to create a
continuous acquisition?

Virtual Instrumentation 2
Loops, Case Structures, and Timing | Laboratory 3

Procedure
Configuring Hardware
1) Keep the same wiring configuration as in Lab 1 and 2.

Part A
1) Open the VI that you created in Lab 2, Data Acquisition with ELVIS - Signal Conditioning.vi.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Copy and paste the code from Lab 2 into a new VI.

3) Close the code from Lab 2.

4) On the Timing VI, change the Sample Mode to be Continuous.

5) Change the Rate to 500 and leave the Samples per Channel at 100. This modifies the
settings of the buffer that data is written to.

6) Drag the Close VI so that it is to the right of the Waveform graph.

7) Place a While Loop around the Read VI, the Convert Thermistor Reading VI and the
Waveform Graph indicator.

8) Create a Stop Control for the Loop Condition Terminal of the While Loop by right-clicking on
the input to the Loop Condition Terminal and selecting Create>>Control.

9) Change the Waveform Graph to a Waveform Chart by right-clicking on the graph on the
Front Panel and choosing Replace. Navigate to the Graph palette and choose a Waveform
Chart.

10) On the Front Panel, right-click on the Waveform Chart and select Properties.

11) On the Scales tab, uncheck Auto-Scale for the x-axis and change the minimum to 0 and the
maximum to 0.1.

12) Click Ok to close.

Virtual Instrumentation 3
Loops, Case Structures, and Timing | Laboratory 3

13) Stop the VI and add a 250ms Wait


(ms) function to the While Loop.
Ensure that your code matches the
image shown.

14) Run the VI and note the change in


the behavior of the waveform.

15) Stop the VI when you’re done.

Part B
1) Wire AI2 + of the NI ELVIS to the +5V Supply and wire AI2- to Ground.

2) Put a Case Structure around the Create Channel VI and its corresponding terminals.

3) Navigate to the False Case and add a new Create Channel VI to the Case Structure. Choose
Channel AI2 of your device for this case.

4) Wire the Error Out and Task Out of the new Create Channel VI to the Task and Error terminals
on the right side of the Case Structure.

5) Wire a Boolean Control to the Case Selector of the Case Structure by right-clicking the input
terminal of the Case Selector and selecting Create>>Control.

6) Ensure that your code matches the


image shown.

Virtual Instrumentation 4
Loops, Case Structures, and Timing | Laboratory 3

7) Click the Boolean Control on the Front Panel so that it is in the True state. Run the VI. Notice
that the same waveform is created as in Part A of this Lab.

8) Stop the VI and click the Boolean Control on the Front Panel so that it is in the False state.

9) Run the VI and notice that a constant 5V signal is produced.

10) Explore changing the scale of the waveform chart to zoom in on the signal.

11) Stop the VI.

12) Save the VI as Structures - ELVIS.vi.

Virtual Instrumentation 5
Loops, Case Structures, and Timing | Laboratory 3

Questions
1) What are three differences between a While Loop and a For Loop?

2) Comparing Lab 1 and Lab 3, why do you suppose we do not typically use for loops for data
acquisition?

3) What is the output of the For Loop


shown?

4) Comparing Lab 1 and Lab 3, why do you suppose we do not typically use for loops for data
acquisition?

Virtual Instrumentation 6
Loops, Case Structures, and Timing | Laboratory 3

5) What was the effect of putting the Wait in the While Loop, and why is it good to use waits?

6) Why does clicking the True/False control on the Front Panel not have any effect while the VI
is running?

7) What is another type of control that could have been wired to the Case Structure Selector
Terminal that would have given the ability to associate a title with each case that could be
selected on the Front Panel?

Virtual Instrumentation 7
VIRTUAL INSTRUMENTATION

Lab 4
Arrays, Clusters,
and Type Definitions

Section 1 - Arrays, Clusters, and Type Definitions


---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Part A – Arrays
---------------------------------------------------------------------------  3
Part B – Clusters
---------------------------------------------------------------------------  4
Part C – Type Definitions
---------------------------------------------------------------------------  6
Arrays, Clusters, and Type Definitions | Laboratory 4

Section 1
Arrays, Clusters, and Type
Definitions
In this lab, you will expand upon the DAQmx code you created in Lab 2 to explore Arrays,
Clusters, and Type Definitions.

The temperature monitoring application will be taking continuous measurement. You’ll explore
how large sets of similar data can be grouped into arrays and sets of dissimilar data can be
grouped into clusters.

By the end of this lab, you should have a good understanding of the functionality and
limitations (if any) of arrays and clusters, as well as when each is appropriate to use.

Pre-Lab Questions:
1) In the code shown, what do you
suppose has an array component
and what do you suppose uses a
cluster?

2) What function(s) could be used in order to break the cluster into its individual components?

Virtual Instrumentation 2
Arrays, Clusters, and Type Definitions | Laboratory 4

Procedure
Configuring Hardware
1) Keep the same wiring configuration as in Lab 3.

Part A – Arrays
1) Open the VI that you created in Lab 3, Structures.vi.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Copy and paste the Lab 3 code into a new VI.

3) Close the Lab 3 code.

4) Outside of the While Loop on the right side, place the Get Waveform Components function.

5) Right-click the Get Waveform Components function and select Add Element.

6) Repeat the previous step so that there are three outputs from the Get Waveform
Components function.

7) Right-click the second output and select Select Item>>t0.

8) Right-click the third output and select Select Item>>dt.

9) Wire a branch from the Waveform wire to the Get Waveform Components Function outside
of the While Loop.

10) Create indicators for each of the outputs of the Get Waveform Components Function so that
the ‘Y’ data, ‘t0’ data, and ‘dt’ data is displayed on the Front Panel.

11) Wire the “Number of Samples per Channel” input of the Read VI to a constant of 125.

Virtual Instrumentation 3
Arrays, Clusters, and Type Definitions | Laboratory 4

12) Ensure that your code matches the image shown.

13) Run the VI to get a sample of data, and then stop it.

14) Expand the array indicator on the Front Panel so that you can see 10 to 15 values. Notice
the difference in the values when different cases of the Case Structure are chosen.

15) Identify which indicator is an array and how you know. Also, record why it makes sense
that the indicator you chose as the array is the only array and why it makes sense that the
other two indicators are not.

Part B – Clusters
1) Inside of the While Loop, place an Unbundle by Name function.

2) Wire the error wire coming out of the Read VI into the Unbundle by Name function.

3) Wire the output of the Unbundle by Name to a Boolean “Or” from the Boolean Palette.

4) Wire the Stop Button to the other “Or” input and wire the output of the “Or” to the Loop
Condition Terminal.

5) Ensure that your code matches the image shown.

Virtual Instrumentation 4
Arrays, Clusters, and Type Definitions | Laboratory 4

6) Run your VI for a few seconds and then stop it.

7) Record the possible benefit of unbundling the error wire and using the “Or” function. What
is a possible use case?

8) Change the Rate input of the Timing VI from 500 to 3 million. Run the VI. Record the
behavior and click Stop on the error message.

9) Expand the Unbundle by Name to show “Status,” “Code,” and “Source” and make
indicators for each as shown.

10) Run the VI and observe what is displayed in the three new indicators that you created after
clicking Stop on the error message.

11) Why are these three components contained in an Error Cluster and what are the data types
of each. Why do these data types make sense?

12) Change the Rate back to 500.

Virtual Instrumentation 5
Arrays, Clusters, and Type Definitions | Laboratory 4

Part C – Type Definitions


There are two ways to create Custom Controls, Type Definitions, and Strict Type Definitions.

Method 1: Modifying an Existing Control


1) Right-click the Stop Control on the Front Panel and choose Advanced>>Customize.

2) Notice that the default at the top of the new window is “Control.” In this instance you will
create a Custom Control.

3) Change the cosmetic properties of the control. Think about ways to make the stop button
more apparent to potential users. For instance, make it larger and change the color.

4) Save the Custom Control and close the window.

5) Allow LabVIEW to replace your existing control with the new, modified Custom Control.

6) The Custom Control can also be accessed by right-clicking on the Front Panel and choosing
Select a Control from the Controls Palette. Here you can choose your control.

Method 2: Creating a New Custom Control


1) At the top of your VI, select Project>>Create Project.

2) Select Blank Project and click Finish.

3) When the pop-up window appears, choose Add. This adds your VI to a project.

4) To add a new Custom Control to the project, right-click on My Computer>>New>>Control.


Note: Notice that the same window appears as in Method 1 where you can create a Custom
Control; however, instead of already having a control selected which appears in the
window, now you have the ability to create the control from scratch. By doing this, you do
not automatically add a new control to the Front Panel as in Method 1, but instead add it to
the project which gives you the ability to use it easily anywhere you want, even in multiple
VIs.

5) Create any control that you want and change its properties, etc to be customized. Save the
control and close the window. Observe that the Custom Control is now added to the project
along with the custom control you made using Method 1.

6) Drag the control from the project onto your Front Panel. Notice that you can make multiple
instances of your custom control on your Front Panel by dragging the custom control from
the project onto the Front Panel.

Virtual Instrumentation 6
Arrays, Clusters, and Type Definitions | Laboratory 4

7) Delete the controls you just added in Step 5.

8) Double-click the Custom Control created in Method 2 in the project menu tree and change the
instance from Control to Type Def.

9) Save the change and close the window.

10) Drag the Type Def from the Project to the Front Panel.

11) Reopen the Type Def Front Panel to edit the Type Def.

12) Right-click on the control in the Type Def window. Select Replace>>Numeric control.

13) Save the Type Def and close the window.

14) Record what happens to the Type Def that was previously placed on the Front Panel.

15) Delete the Type Def from the Front Panel.

16) Double click on the Type Def in the Project and change the instance to Strict Type Def.

17) Save the changes and close the window.

18) Drag the Strict Type Def from the project to the Front Panel.

19) Reopen the Strict Type Def Front Panel to edit the Strict Type Def.

20) Right-click on the numeric control and choose Replace>>Stop Button.

21) Change the color and size of the control and save. Close the window and record the behavior
you observe on the Front Panel.

22) Delete the Stop Button you previously had wired into the “Or” function on your Block
Diagram and replace it with your new customized Strict Type Def.

23) Now that you have begun to make your Front Panel more user-friendly, finish it by using the
Alignment, Distribute, and Resize buttons at the top of the Front Panel. Also, use decorations
from the Control Palette to arrange controls and indicators so that they are easy for the user
to use and understand.

24) Save the VI as Data Acquisition with cDAQ – Clusters.vi and the Project as Data Acquisition
with cDAQ.lvproj.

Virtual Instrumentation 7
Arrays, Clusters, and Type Definitions | Laboratory 4

Questions
1) Can you make an array of an array? Can you make an array have multiple data types?

2) Can you make an array of clusters? What is the benefit of a cluster?

3) Describe the progression from Custom Control to Type Def. to Strict Type Def.
What can you customize in a Strict Type Def that cannot be customized in a Type Def?

Virtual Instrumentation 8
VIRTUAL INSTRUMENTATION

Lab 4
Arrays, Clusters,
and Type Definitions

Section 1 - Arrays, Clusters, and Type Definitions


---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Part A – Arrays
---------------------------------------------------------------------------  3
Part B – Clusters
---------------------------------------------------------------------------  4
Part C – Type Definitions
---------------------------------------------------------------------------  6
Arrays, Clusters, and Type Definitions | Laboratory 4

Section 1
Arrays, Clusters, and Type
Definitions
In this lab, you will expand upon the DAQmx code you created in Lab 2 to explore Arrays,
Clusters, and Type Definitions.

The temperature monitoring application will be taking continuous measurement. You’ll explore
how large sets of similar data can be grouped into arrays and sets of dissimilar data can be
grouped into clusters.

By the end of this lab, you should have a good understanding of the functionality and
limitations (if any) of arrays and clusters, as well as when each is appropriate to use.

Pre-Lab Questions:
1) In the code shown, what do you
suppose has an array component
and what do you suppose uses a
cluster?

2) What function(s) could be used in order to break the cluster into its individual components?

Virtual Instrumentation 2
Arrays, Clusters, and Type Definitions | Laboratory 4

Procedure
Configuring Hardware
1) Keep the same wiring configuration as in Lab 3.

Part A – Arrays
1) Open the VI that you created in Lab 3, Structures - ELVIS.vi.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Copy and paste the Lab 3 code into a new VI.

3) Close the Lab 3 code.

4) Outside of the While Loop on the right side, place the Get Waveform Components function.

5) Right-click the Get Waveform Components function and select Add Element.

6) Repeat the previous step so that there are three outputs from the Get Waveform
Components function.

7) Right-click the second output and select Select Item>>t0.

8) Right-click the third output and select Select Item>>dt.

9) Wire a branch from the Waveform wire to the Get Waveform Components Function outside
of the While Loop.

10) Create indicators for each of the outputs of the Get Waveform Components Function so that
the ‘Y’ data, ‘t0’ data, and ‘dt’ data is displayed on the Front Panel.

11) Wire the “Number of Samples per Channel” input of the Read VI to a constant of 125.

Virtual Instrumentation 3
Arrays, Clusters, and Type Definitions | Laboratory 4

12) Ensure that your code matches the image shown.

13) Run the VI to get a sample of data, and then stop it.

14) Expand the array indicator on the Front Panel so that you can see 10 to 15 values. Notice
the difference in the values when different cases of the Case Structure are chosen.

15) Identify which indicator is an array and how you know. Also, record why it makes sense
that the indicator you chose as the array is the only array and why it makes sense that the
other two indicators are not.

Part B – Clusters
1) Inside of the While Loop, place an Unbundle by Name function.

2) Wire the error wire coming out of the Read VI into the Unbundle by Name function.

3) Wire the output of the Unbundle by Name to a Boolean “Or” from the Boolean Palette.

4) Wire the Stop Button to the other “Or” input and wire the output of the “Or” to the Loop
Condition Terminal.

5) Ensure that your code matches the image shown.

Virtual Instrumentation 4
Arrays, Clusters, and Type Definitions | Laboratory 4

6) Run your VI for a few seconds and then stop it.

7) Record the possible benefit of unbundling the error wire and using the “Or” function. What
is a possible use case?

8) Change the Rate input of the Timing VI from 500 to 3 million. Run the VI. Record the
behavior and click Stop on the error message.

9) Expand the Unbundle by Name to show “Status,” “Code,” and “Source” and make
indicators for each as shown.

10) Run the VI and observe what is displayed in the three new indicators that you created after
clicking Stop on the error message.

11) Why are these three components contained in an Error Cluster and what are the data types
of each. Why do these data types make sense?

12) Change the Rate back to 500.

Virtual Instrumentation 5
Arrays, Clusters, and Type Definitions | Laboratory 4

Part C – Type Definitions


There are two ways to create Custom Controls, Type Definitions, and Strict Type Definitions.

Method 1: Modifying an Existing Control


1) Right-click the Stop Control on the Front Panel and choose Advanced>>Customize.

2) Notice that the default at the top of the new window is “Control.” In this instance you will
create a Custom Control.

3) Change the cosmetic properties of the control. Think about ways to make the stop button
more apparent to potential users. For instance, make it larger and change the color.

4) Save the Custom Control and close the window.

5) Allow LabVIEW to replace your existing control with the new, modified Custom Control.

6) The Custom Control can also be accessed by right-clicking on the Front Panel and choosing
Select a Control from the Controls Palette. Here you can choose your control.

Method 2: Creating a New Custom Control


1) At the top of your VI, select Project>>Create Project.

2) Select Blank Project and click Finish.

3) When the pop-up window appears, choose Add. This adds your VI to a project.

4) To add a new Custom Control to the project, right-click on My Computer>>New>>Control.


Note: Notice that the same window appears as in Method 1 where you can create a Custom
Control; however, instead of already having a control selected which appears in the
window, now you have the ability to create the control from scratch. By doing this, you do
not automatically add a new control to the Front Panel as in Method 1, but instead add it to
the project which gives you the ability to use it easily anywhere you want, even in multiple
VIs.

5) Create any control that you want and change its properties, etc to be customized. Save the
control and close the window. Observe that the Custom Control is now added to the project
along with the custom control you made using Method 1.

6) Drag the control from the project onto your Front Panel. Notice that you can make multiple
instances of your custom control on your Front Panel by dragging the custom control from
the project onto the Front Panel.
Virtual Instrumentation 6
Arrays, Clusters, and Type Definitions | Laboratory 4

7) Delete the controls you just added in Step 5.

8) Double-click the Custom Control created in Method 2 in the project menu tree and change the
instance from Control to Type Def.

9) Save the change and close the window.

10) Drag the Type Def from the Project to the Front Panel.

11) Reopen the Type Def Front Panel to edit the Type Def.

12) Right-click on the control in the Type Def window. Select Replace>>Numeric control.

13) Save the Type Def and close the window.

14) Record what happens to the Type Def that was previously placed on the Front Panel.

15) Delete the Type Def from the Front Panel.

16) Double click on the Type Def in the Project and change the instance to Strict Type Def.

17) Save the changes and close the window.

18) Drag the Strict Type Def from the project to the Front Panel.

19) Reopen the Strict Type Def Front Panel to edit the Strict Type Def.

20) Right-click on the numeric control and choose Replace>>Stop Button.

21) Change the color and size of the control and save. Close the window and record the behavior
you observe on the Front Panel.

22) Delete the Stop Button you previously had wired into the “Or” function on your Block
Diagram and replace it with your new customized Strict Type Def.

23) Now that you have begun to make your Front Panel more user-friendly, finish it by using the
Alignment, Distribute, and Resize buttons at the top of the Front Panel. Also, use decorations
from the Control Palette to arrange controls and indicators so that they are easy for the user
to use and understand.

24) Save the VI as Data Acquisition with ELVIS – Clusters.vi and the Project as Data Acquisition

Virtual Instrumentation 7
Arrays, Clusters, and Type Definitions | Laboratory 4

with ELVIS.lvproj.

Virtual Instrumentation 8
Arrays, Clusters, and Type Definitions | Laboratory 4

Questions
1) Can you make an array of an array? Can you make an array have multiple data types?

2) Can you make an array of clusters? What is the benefit of a cluster?

3) Describe the progression from Custom Control to Type Def. to Strict Type Def.
What can you customize in a Strict Type Def that cannot be customized in a Type Def?

Virtual Instrumentation 9
VIRTUAL INSTRUMENTATION

Lab 5
File I/O

Section 1 - File I/O


---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Part A – Express VIs
---------------------------------------------------------------------------  3
Part B – TDMS
---------------------------------------------------------------------------  5
File I/O | Laboratory 5

Section 1
File I/O
In this lab, you will expand upon the DAQmx code you created in Lab 3 in order to explore File
I/O.

Monitoring applications often run for an extended period of time. In order to save the data that
is gathered, you’re going to setup your temperature monitor to log the data to a file.

You will first observe how easy it is to use Express VIs for File I/O and will later explore using
TDMS.

Pre-lab Questions:
1) What kind of information would you want included in a data log?

2) In the VI we made in Lab 4, what would be relevant information to log and why?

Virtual Instrumentation 2
File I/O | Laboratory 5

Procedure
Configuring Hardware
1) Keep the same wiring configuration as in Lab 4.

Part A – Express VIs


1) Open the VI that you created in Lab 4, Data Acquisition with cDAQ – Clusters.vi.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Copy and paste the Lab 4 code into a new VI.

3) Close the code from Lab 4.

4) Locate the File I/O Palette on the Functions Palette.

5) Place the Write to Measurement File Express VI on the Block Diagram outside of the While
Loop.

6) When the window opens, set the Filename to save as “Test” on your desktop.

7) Set the File Format to Microsoft Excel (.xlsx).

8) Click Ok to use these settings and close the window.

9) Wire the waveform data out of the While Loop to the input of the Write to Measurement File
Express VI.

10) Wire the error wires appropriately.

Virtual Instrumentation 3
File I/O | Laboratory 5

11) Ensure that your code matches the image shown.

12) Run the VI. Stop the VI after a few seconds with the Stop button that you created.

13) Navigate to the “Test” file you created on your desktop and open it with Excel. Observe that
your data has been logged.

14) Returning to the Block Diagram, double-click the Write to Measurement File Express VI
and notice some of the settings you can change such as “Action”, “If a File Already Exists,”
“Segment Headers,” and “X Value Columns.” Change each one of these and record what the
result is.

Virtual Instrumentation 4
File I/O | Laboratory 5

Part B – TDMS
1) Delete the Write to Measurement File Express VI.

2) On the Block Diagram, locate the TDMS Streaming Palette within the File I/O Palette.

3) Outside of the while loop place a TDMS Open and TDMS Close. Inside the while loop, place
a TDMS Write.

4) Wire the File Wires and Error Wires so that all three VIs are wired together.

5) Wire the Waveform data to the Data Input of the TDMS Write.

6) Create a control for the File Path input of the TDMS Open.

7) Right-click the File Path Control on the Front Panel and choose Browse Options.

8) Select New or Existing as the Selection Mode and close the window by clicking Ok.

9) Create a constant for the Operation input of the TDMS Open and set the constant to Create
or Replace.

10) Make sure that your code matches the image shown.

11) Enter a file path in the control on the Front Panel that points to a file called “test.tdms” on
your desktop.

12) Run the VI. Stop the VI after a few seconds.

13) Ensure that “test.tdms” is now on your desktop.

Virtual Instrumentation 5
File I/O | Laboratory 5

14) Create a new VI and place the TDMS File Viewer VI on the Block Diagram.

15) Create a File Path Control input to the TDMS File Viewer.

16) In the control on the Front Panel of the new VI, select the “test.tdms” file on your desktop and
run the VI.

17) Notice that the TDMS File Viewer opens. Explore the File Viewer.

18) Returning to the original VI, notice that the TDMS Write has inputs for Channel Name and
Group Name.

19) Wire a String Constant with the text “Data Acquisition” to the Group Name input.

20) Wire a String Constant with the text “5V Channel” to the Channel Name input.

21) Run the 5V case of the case structure with the Function Generator Running. Stop the VI after a
few seconds.

22) The “test.tdms” file is overwritten with the new changes.

23) Run the VI you created with the TDMS File Viewer VI.

24) When the File Viewer opens, click on “test.tdms” under File Contents to update the File
Viewer. Expand the File Contents tree and record the changes that occurred after including a
Group Name and Channel Name.

25) Close the File Viewer.

26) Save the File Viewer VI and save this VI as Data Acquisition with cDAQ – Data Logging. VI.

Virtual Instrumentation 6
File I/O | Laboratory 5

Questions
1) What are benefits of using the Express VI?

2) What are the benefits of the TDMS VIs?

3) When would it be appropriate to use each one?

4) What is then underlying file format of all other file formats?

5) Which type of file is also known as a text file?

Virtual Instrumentation 7
VIRTUAL INSTRUMENTATION

Lab 5
File I/O

Section 1 - File I/O


---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Part A – Express VIs
---------------------------------------------------------------------------  3
Part B – TDMS
---------------------------------------------------------------------------  5
File I/O | Laboratory 5

Section 1
File I/O
In this lab, you will expand upon the DAQmx code you created in Lab 3 in order to explore File
I/O.

Monitoring applications often run for an extended period of time. In order to save the data that
is gathered, you’re going to setup your temperature monitor to log the data to a file.

You will first observe how easy it is to use Express VIs for File I/O and will later explore using
TDMS.

Pre-lab Questions:
1) What kind of information would you want included in a data log?

2) In the VI we made in Lab 4, what would be relevant information to log and why?

Virtual Instrumentation 2
File I/O | Laboratory 5

Procedure
Configuring Hardware
1) Keep the same wiring configuration as in Lab 4.

Part A – Express VIs


1) Open the VI that you created in Lab 4, Data Acquisition with ELVIS – Clusters.vi.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Copy and paste the Lab 4 code into a new VI.

3) Close the code from Lab 4.

4) Locate the File I/O Palette on the Functions Palette.

5) Place the Write to Measurement File Express VI on the Block Diagram outside of the While
Loop.

6) When the window opens, set the Filename to save as “Test” on your desktop.

7) Set the File Format to Microsoft Excel (.xlsx).

8) Click Ok to use these settings and close the window.

9) Wire the waveform data out of the While Loop to the input of the Write to Measurement File
Express VI.

10) Wire the error wires appropriately.

Virtual Instrumentation 3
File I/O | Laboratory 5

11) Ensure that your code matches the image shown.

12) Run the VI. Stop the VI after a few seconds with the Stop button that you created.

13) Navigate to the “Test” file you created on your desktop and open it with Excel. Observe that
your data has been logged.

14) Returning to the Block Diagram, double-click the Write to Measurement File Express VI
and notice some of the settings you can change such as “Action”, “If a File Already Exists,”
“Segment Headers,” and “X Value Columns.” Change each one of these and record what the
result is.

Virtual Instrumentation 4
File I/O | Laboratory 5

Part B – TDMS
1) Delete the Write to Measurement File Express VI.

2) On the Block Diagram, locate the TDMS Streaming Palette within the File I/O Palette.

3) Outside of the while loop place a TDMS Open and TDMS Close. Inside the while loop, place
a TDMS Write.

4) Wire the File Wires and Error Wires so that all three VIs are wired together.

5) Wire the Waveform data to the Data Input of the TDMS Write.

6) Create a control for the File Path input of the TDMS Open.

7) Right-click the File Path Control on the Front Panel and choose Browse Options.

8) Select New or Existing as the Selection Mode and close the window by clicking Ok.

9) Create a constant for the Operation input of the TDMS Open and set the constant to Create
or Replace.

10) Make sure that your code matches the image shown.

11) Enter a file path in the control on the Front Panel that points to a file called “test.tdms” on
your desktop.

12) Run the VI. Stop the VI after a few seconds.

13) Ensure that “test.tdms” is now on your desktop.

Virtual Instrumentation 5
File I/O | Laboratory 5

14) Create a new VI and place the TDMS File Viewer VI on the Block Diagram.

15) Create a File Path Control input to the TDMS File Viewer.

16) In the control on the Front Panel of the new VI, select the “test.tdms” file on your desktop and
run the VI.

17) Notice that the TDMS File Viewer opens. Explore the File Viewer.

18) Returning to the original VI, notice that the TDMS Write has inputs for Channel Name and
Group Name.

19) Wire a String Constant with the text “Data Acquisition” to the Group Name input.

20) Wire a String Constant with the text “5V Channel” to the Channel Name input.

21) Run the 5V case of the case structure with the Function Generator Running. Stop the VI after a
few seconds.

22) The “test.tdms” file is overwritten with the new changes.

23) Run the VI you created with the TDMS File Viewer VI.

24) When the File Viewer opens, click on “test.tdms” under File Contents to update the File
Viewer. Expand the File Contents tree and record the changes that occurred after including a
Group Name and Channel Name.

25) Close the File Viewer.

26) Save the File Viewer VI and save this VI as Data Acquisition with ELVIS – Data Logging. VI.

Virtual Instrumentation 6
File I/O | Laboratory 5

Questions
1) What are benefits of using the Express VI?

2) What are the benefits of the TDMS VIs?

3) When would it be appropriate to use each one?

4) What is then underlying file format of all other file formats?

5) Which type of file is also known as a text file?

Virtual Instrumentation 7
VIRTUAL INSTRUMENTATION

Lab 6
Modularity

Section 1 – Modularity
---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Creating SubVIs
---------------------------------------------------------------------------  3
Method 1: Converting Existing Code into a SubVI
---------------------------------------------------------------------------  3
Method 2: Creating a New SubVI
---------------------------------------------------------------------------  4
Modularity | Laboratory 6

Section 1
Modularity
In this lab, you will expand upon the DAQmx code you created in Lab 5 in order to learn modularity
and to ultimately create a SubVI and understand its use.

Within all applications, modularity gives the ability to easily make changes in a single place and
have that change carried out in multiple places in the code.

Pre-Lab Questions:
1) What is modularity?

2) Consider a light bulb. Why is a light bulb a good example of modularity?

3) When is the best time to make a SubVI?

Virtual Instrumentation 2
Modularity | Laboratory 6

Lab Procedure
Configuring Hardware
1) Keep the same wiring configuration as in Lab 5.

Creating SubVIs
There are two ways to create SubVI’s.

Method 1: Converting Existing Code into a SubVI

1) Open the TDMS code from Lab 5, Data Acquisition with cDAQ – Data Logging.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Copy and paste the code from Lab 5 into a new VI.

3) Close the code from Lab 5.

4) Highlight the Get Waveform Components VI and the three indicators associated with it.

5) Under the Edit menu, select Create SubVI.

6) Notice that the Get Waveform Components VI is now replaced by a different icon.

7) Double click on this new icon and record what you observe on the Block Diagram of the
new VI that opens. Save the SubVI as Waveform Components.vi.

8) On the Front Panel of the SubVI add an Error In and Error Out cluster from the Array, Matrix,
and Cluster Palette.

9) Right-click on the icon in the upper right corner and select Show Connector.

10) Right-click again and select


Patterns.

11) Choose the 4x2x2x4 pattern.

Virtual Instrumentation 3
Modularity | Laboratory 6

12) Right-click the pattern and select Disconnect All Terminals.

13) To connect a pattern n to a front panel object, first click the pattern terminal and then click
the object that you would like to link it to.

14) Link the top-left terminal to the Temperature cluster.

15) Link the bottom-left terminal to the error in cluster.

16) Link the 4 terminals along the right side to the Y array, t0 timestamp, dt numeric, and error
out cluster, from top to bottom.

17) Notice that the colors of the terminals change when they are linked.

18) The new color corresponds to the color associated with the data type for the object that it is
linked to. For example, the error in and out clusters are yellow.

19) Right-click the icon and select Edit Icon.

20) Use the Icon Editor to create an icon that reminds you of what this subVI does.

21) Save the VI when you’re done.

22) Close the subVI and notice that the icon you made is now the icon being used on your
original VI.

23) Because you edited the Connector Pane of the subVI to include terminals for Error In and
Error Out, right click the subVI icon in the main VI and choose Relink to SubVI.

24) Save the main VI as Data Acquisition with cDAQ - SubVIs.vi.

Method 2: Creating a New SubVI

1) Open a new VI and place a multiply function on the Block Diagram.

2) Wire controls to the two inputs and an indicator to the output.

3) On the Front Panel add Error In and Error Out Cluster as in Method 1.

4) Right-click on the icon in the upper right corner.

5) Right-click the connector and select Patterns.

Virtual Instrumentation 4
Modularity | Laboratory 6

6) Choose the 4x2x2x4 pattern again.

7) Click the first input on the Connector Pane and then click one of the control inputs on the Front
Panel.

8) Do the same for all other controls and indicators.

9) Right-click the icon and choose Edit Icon.

10) Create an icon that reflects multiplication.

11) Save the VI as Multiply.

12) Close this VI window.

13) Return to your original VI (Data Acquisition with cDAQ - SubVIs.vi) and right-click on the Block
Diagram.

14) Choose Select a VI on the Functions Palette and choose the Multiply.vi you just made.

15) Wire the ‘Y’ output of the Waveform components VI you made to the input of an Index Array
function.

16) Wire the output of the Index Array Function to an input of the Multiply SubVI you just made.

17) Wire a constant of 5 to the other input.

18) Create an indicator for the output of the Multiply VI.

19) Ensure that your code matches the image shown.

Virtual Instrumentation 5
Modularity | Laboratory 6

20) Run the VI for a couple seconds and


then click the Stop button.
21) When the VI stops, the x*y indicator should show a value that is 5 times the current
temperature measured by the temperature monitor.

22) Save the VI as Data Acquisition with cDAQ – SubVIs 2.vi.

23) Close the VI.

Virtual Instrumentation 6
Modularity | Laboratory 6

Questions
1) What are some benefits of using subVIs when your Block Diagram begins to get cluttered?

2) What are some benefits of using subVIs specifically with data acquisition?

3) What is the purpose of wiring the Connector Pane?

4) What is the output of the Index Array function that you used?

Virtual Instrumentation 7
VIRTUAL INSTRUMENTATION

Lab 6
Modularity

Section 1 – Modularity
---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Creating SubVIs
---------------------------------------------------------------------------  3
Method 1: Converting Existing Code into a SubVI
---------------------------------------------------------------------------  3
Method 2: Creating a New SubVI
---------------------------------------------------------------------------  4
Modularity | Laboratory 6

Section 1
Modularity
In this lab, you will expand upon the DAQmx code you created in Lab 5 in order to learn modularity
and to ultimately create a SubVI and understand its use.

Within all applications, modularity gives the ability to easily make changes in a single place and
have that change carried out in multiple places in the code.

Pre-Lab Questions:
1) What is modularity?

2) Consider a light bulb. Why is a light bulb a good example of modularity?

3) When is the best time to make a SubVI?

Virtual Instrumentation 2
Modularity | Laboratory 6

Lab Procedure
Configuring Hardware
1) Keep the same wiring configuration as in Lab 5.

Creating SubVIs
There are two ways to create SubVI’s.

Method 1: Converting Existing Code into a SubVI

1) Open the TDMS code from Lab 5, Data Acquisition with ELVIS – Data Logging.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Copy and paste the code from Lab 5 into a new VI.

3) Close the code from Lab 5.

4) Highlight the Get Waveform Components VI and the three indicators associated with it.

5) Under the Edit menu, select Create SubVI.

6) Notice that the Get Waveform Components VI is now replaced by a different icon.

7) Double click on this new icon and record what you observe on the Block Diagram of the
new VI that opens. Save the SubVI as Waveform Components.vi.

8) On the Front Panel of the SubVI add an Error In and Error Out cluster from the Array, Matrix,
and Cluster Palette.

9) Right-click on the icon in the upper right corner and select Show Connector.

10) Right-click again and select


Patterns.

11) Choose the 4x2x2x4 pattern.

Virtual Instrumentation 3
Modularity | Laboratory 6

12) Right-click the pattern and select Disconnect All Terminals.

13) To connect a pattern n to a front panel object, first click the pattern terminal and then click
the object that you would like to link it to.

14) Link the top-left terminal to the Temperature cluster.

15) Link the bottom-left terminal to the error in cluster.

16) Link the 4 terminals along the right side to the Y array, t0 timestamp, dt numeric, and error
out cluster, from top to bottom.

17) Notice that the colors of the terminals change when they are linked.

18) The new color corresponds to the color associated with the data type for the object that it is
linked to. For example, the error in and out clusters are yellow.

19) Right-click the icon and select Edit Icon.

20) Use the Icon Editor to create an icon that reminds you of what this subVI does.

21) Save the VI when you’re done.

22) Close the subVI and notice that the icon you made is now the icon being used on your
original VI.

23) Because you edited the Connector Pane of the subVI to include terminals for Error In and
Error Out, right click the subVI icon in the main VI and choose Relink to SubVI.

24) Save the main VI as Data Acquisition with ELVIS - SubVIs.vi.

Method 2: Creating a New SubVI

1) Open a new VI and place a multiply function on the Block Diagram.

2) Wire controls to the two inputs and an indicator to the output.

3) On the Front Panel add Error In and Error Out Cluster as in Method 1.

4) Right-click on the icon in the upper right corner.

5) Right-click the connector and select Patterns.

Virtual Instrumentation 4
Modularity | Laboratory 6

6) Choose the 4x2x2x4 pattern again.

7) Click the first input on the Connector Pane and then click one of the control inputs on the Front
Panel.

8) Do the same for all other controls and indicators.

9) Right-click the icon and choose Edit Icon.

10) Create an icon that reflects multiplication.

11) Save the VI as Multiply.

12) Close this VI window.

13) Return to your original VI (Data Acquisition with ELVIS - SubVIs.vi) and right-click on the Block
Diagram.

14) Choose Select a VI on the Functions Palette and choose the Multiply.vi you just made.

15) Wire the ‘Y’ output of the Waveform components VI you made to the input of an Index Array
function.

16) Wire the output of the Index Array Function to an input of the Multiply SubVI you just made.

17) Wire a constant of 5 to the other input.

18) Create an indicator for the output of the Multiply VI.

19) Ensure that your code matches the image shown.

Virtual Instrumentation 5
Modularity | Laboratory 6

20) Run the VI for a couple seconds and


then click the Stop button.
21) When the VI stops, the x*y indicator should show a value that is 5 times the current
temperature measured by the temperature monitor.

22) Save the VI as Data Acquisition with ELVIS – SubVIs 2.vi.

23) Close the VI.

Virtual Instrumentation 6
Modularity | Laboratory 6

Questions
1) What are some benefits of using subVIs when your Block Diagram begins to get cluttered?

2) What are some benefits of using subVIs specifically with data acquisition?

3) What is the purpose of wiring the Connector Pane?

4) What is the output of the Index Array function that you used?

Virtual Instrumentation 7
VIRTUAL INSTRUMENTATION

Lab 7
Data Acquisition

Section 1 – Data Acquisition


---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Part A – The Analog Case
---------------------------------------------------------------------------  3
Part B – The Digital Case
---------------------------------------------------------------------------  5
Data Acquisition | Laboratory 7

Section 1
Data Acquisition
In this lab you will explore more deeply the idea of data acquisition by utilizing more functionality of
the cDAQ and LabVIEW. You will use a case structure to observe different types of data acquisition.

As a monitoring application, it’s common to need to signal when certain conditions are met. In this
temperature monitoring application, you’ll use a digital signal to turn on and off an LED. In later
exercises, you will determine the conditions to turn the digital signal on or off.

Parts List:
The following equipment is required for this experiment:

-- 1 220Ω resistor
-- 1 LED
-- Wires

Pre-Lab Questions:
1) Signals are either analog or digital. What is the difference between the two?

2) Based on the analog code that you have written in Labs 1 through 6, what modifications
need to be made to write a digital logic high?

3) What is one application that would use an analog signal and one that would use a digital
signal?


Virtual Instrumentation 2
Data Acquisition | Laboratory 7

Lab Procedure
Configuring Hardware
1) Keep the same wiring configuration as in Lab 6. You’re going to add a connection to the
Digital Input/Output card.

2) Build the following circuit in order


to turn on or off an LED.

3) From the cDAQ Digital Input/Output card, connect output channel 0 to the anode of the LED.
The anode is usually the longer lead of the LED.

4) Connect the digital ground line to the resistor.

Part A – The Analog Case


1) Open the code made in Lab 3, Structures.vi.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Copy and paste the Lab 3 code into a new VI.

3) Close the Lab 3 code.

4) Amend your code to match the code shown.

5) To remove the Case Structure and keep the code that is inside of it, make sure the True case
is visible, and then right-click the Case Structure and select Remove Case Structure.

Virtual Instrumentation 3
Data Acquisition | Laboratory 7

6) Delete the code that isn’t needed and add the code that’s missing so that it matches the
image shown.

7) Place a Case Structure around the entire code.

8) On the Front Panel, place an Enumerated Control. Right-click on the control and choose
Edit Items.

9) Insert items “Analog” and “Digital” making sure that “Analog” is item 0 and “Digital” is
item 1.

10) Move back to the Block Diagram and wire the Enum to the Case Selector of the Case
Structure.

11) Make sure that the current code is in the default “Analog” case. If it is not, right-click on the
case structure and choose Make this Case “Analog”, Default.

12) Edit the label of the stop button to be Analog.

13) Your code should match the code shown.

Virtual Instrumentation 4
Data Acquisition | Laboratory 7

Part B – The Digital Case


1) Navigate to the “Digital” case of the Case Structure.

2) Place down a DAQmx Create Channel, Write, and Clear Task.

3) Configure the Create Channel for Digital Out and the DAQmx Write for Digital>>Single
Channel>>Single Sample>>Boolean (1 line).

4) Wire the task and error wires.

5) Create a constant for the “Lines” input of the Create Channel and select cDAQ1Mod2/port0/
line0.

6) Create a control for the “data” input of the Write function.

7) Place a While Loop around the Write function as shown.

8) Make a Stop Button for the While Loop and label it Digital.

9) Confirm that the hardware is setup as defined in the Configuring Hardware section.

10) Ensure your code matches the code shown.

11) On the front panel, select Digital from the Enum control.

12) Run the VI.

13) Toggle the value in the data control.

Virtual Instrumentation 5
Data Acquisition | Laboratory 7

14) Confirm the LED turns on and off.

15) Stop the VI when you’re done.

16) Save the VI as Analog and Digital.vi.

Virtual Instrumentation 6
Data Acquisition | Laboratory 7

Questions
1) Describe the behavior of each case.

2) Why does changing the Enum while the code is running have no effect on the VI?

3) In the digital case, what happens if the digital line is set high (i.e. the LED is illuminated)
and the VI is stopped? Why is this?

Virtual Instrumentation 7
VIRTUAL INSTRUMENTATION

Lab 7
Data Acquisition

Section 1 – Data Acquisition


---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Part A – The Analog Case
---------------------------------------------------------------------------  3
Part B – The Digital Case
---------------------------------------------------------------------------  5
Data Acquisition | Laboratory 7

Section 1
Data Acquisition
In this lab you will explore more deeply the idea of data acquisition by utilizing more functionality of
the NI ELVIS and LabVIEW. You will use a case structure to observe different types of data acquisition.

As a monitoring application, it’s common to need to signal when certain conditions are met. In this
temperature monitoring application, you’ll use a digital signal to turn on and off an LED. In later
exercises, you will determine the conditions to turn the digital signal on or off.

Parts List:
The following equipment is required for this experiment:

-- 1 220Ω resistor
-- 1 LED
-- Wires

Pre-Lab Questions:
1) Signals are either analog or digital. What is the difference between the two?

2) Based on the analog code that you have written in Labs 1 through 6, what modifications
need to be made to write a digital logic high?

3) What is one application that would use an analog signal and one that would use a digital
signal?


Virtual Instrumentation 2
Data Acquisition | Laboratory 7

Lab Procedure
Configuring Hardware
1) Keep the same wiring configuration as in Lab 6. You’re going to add a connection to the
Digital Input/Output.

2) Build the following circuit in order


to turn on or off an LED.

3) From the NI ELVIS, connect output channel 0 to the anode of the LED. The anode is usually
the longer lead of the LED.

4) Connect the digital ground line to the resistor.

Part A – The Analog Case


1) Open the code made in Lab 3, Structures - ELVIS.vi.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Copy and paste the Lab 3 code into a new VI.

3) Close the Lab 3 code.

4) Amend your code to match the code shown.

5) To remove the Case Structure and keep the code that is inside of it, make sure the True case
is visible, and then right-click the Case Structure and select Remove Case Structure.

Virtual Instrumentation 3
Data Acquisition | Laboratory 7

6) Delete the code that isn’t needed and add the code that’s missing so that it matches the
image shown.

7) Place a Case Structure around the entire code.

8) On the Front Panel, place an Enumerated Control. Right-click on the control and choose
Edit Items.

9) Insert items “Analog” and “Digital” making sure that “Analog” is item 0 and “Digital” is
item 1.

10) Move back to the Block Diagram and wire the Enum to the Case Selector of the Case
Structure.

11) Make sure that the current code is in the default “Analog” case. If it is not, right-click on the
case structure and choose Make this Case “Analog”, Default.

12) Edit the label of the stop button to be Analog.

13) Your code should match the code shown.

Virtual Instrumentation 4
Data Acquisition | Laboratory 7

Part B – The Digital Case


1) Navigate to the “Digital” case of the Case Structure.

2) Place down a DAQmx Create Channel, Write, and Clear Task.

3) Configure the Create Channel for Digital Out and the DAQmx Write for Digital>>Single
Channel>>Single Sample>>Boolean (1 line).

4) Wire the task and error wires.

5) Create a constant for the “Lines” input of the Create Channel and select Dev1/port0/line0 .

6) Create a control for the “data” input of the Write function.

7) Place a While Loop around the Write function as shown.

8) Make a Stop Button for the While Loop and label it Digital.

9) Confirm that the hardware is setup as defined in the Configuring Hardware section.

10) Ensure your code matches the code shown.

11) On the front panel, select Digital from the Enum control.

12) Run the VI.

13) Toggle the value in the data control.

Virtual Instrumentation 5
Data Acquisition | Laboratory 7

14) Confirm the LED turns on and off.

15) Stop the VI when you’re done.

16) Save the VI as Analog and Digital - ELVIS.vi.

Virtual Instrumentation 6
Data Acquisition | Laboratory 7

Questions
1) Describe the behavior of each case.

2) Why does changing the Enum while the code is running have no effect on the VI?

3) In the digital case, what happens if the digital line is set high (i.e. the LED is illuminated)
and the VI is stopped? Why is this?

Virtual Instrumentation 7
VIRTUAL INSTRUMENTATION

Lab 8
Common Design
Architectures

Section 1 – Common Design Architectures


---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Configuring the Cases
---------------------------------------------------------------------------  3
Configuring the States
---------------------------------------------------------------------------  5
Common Design Architectures | Laboratory 8

Section 1
Common Design Architectures
Using a collection of LabVIEW skills covered previously, a State Machine will be implemented using
the two states defined in Lab 7 (analog and digital).

In the temperature monitoring application, there are a few different states that the program can be
in. It’s often beneficial to separate a program into different states so that you can organize your code
more cleanly. Additionally, using a State Machine, you can define different conditions for when to
send your program into each state. In this way, your program can run a different sequence of code
depending on the results of a previous sequence.

This is an incredibly powerful capability, and will be necessary for the temperature monitor. Most
of the time, the temperature monitor will simply be in a state of acquiring temperature data. That
temperature data is going to determine if and when the program should go into a different state to
change the value of our status indicator LED.

We’ll learn more about how to use conditions to change the order of execution of our states in the
next lab. In this lab, we’ll focus on the structure of a State Machine.

Pre-Lab Questions:
1) What were some of the limitations of the code in Lab 7?

2) What is a Type Definition and why would it be used?

3) What is the purpose of pre-defined design architectures?


Virtual Instrumentation 2
Common Design Architectures | Laboratory 8

Lab Procedure
Configuring Hardware
1) Keep the same hardware configuration as was used in Lab 7.

Configuring the Cases


1) Open the code from Lab 7, Analog and Digital.vi.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Copy and paste the Lab 7 code into a new VI.

3) Close the Lab 7 code.

4) Highlight the Enumerated control on the Front Panel and select Edit>>Customize Control.

5) Change the control to a Type Definition.

6) Edit the items of the Enum so that Stop is item 0, Analog is item 1, Digital is item 2, and Idle
is item 3.

7) Save the Control as State Machine States.ctl.

8) Close the Type Definition window, and allow the original Enum that was placed on the Front
Panel to be replaced with the Type Definition.

9) On the Block Diagram, place a While Loop around the Case Structure.

10) Right-click on the Enum on the Block Diagram and change it to a constant.

11) Place the constant to the left of the While Loop and wire it through the While Loop to the
case selector of the Case Structure.

12) Right-click on the Case Structure and add a case for every value of the Case Structure.

13) Select the “Idle” case. Right-click the Case Structure and select Make This The Default Case.

Virtual Instrumentation 3
Common Design Architectures | Laboratory 8

14) Right-click on the tunnel going into the While Loop from the Enum constant and select
Replace with Shift Registers.

Virtual Instrumentation 4
Common Design Architectures | Laboratory 8

Configuring the States


1) Create buttons on the Front Panel for Analog, Digital, and Stop.

2) Create the code as shown. Notice that an array of Enum constants is wired to the Index Array.

3) For the analog and digital cases, copy and paste the code from their respective cases in Lab 7.
Make the minor modifications seen in the images shown.

Virtual Instrumentation 5
Common Design Architectures | Laboratory 8

4) Configure the Stop case as shown.

5) Run the code and experiment with clicking the different buttons on the Front Panel.

6) Record the behavior associated with each button and if there is any indication on the cDAQ
that corresponds with a certain case.

7) Stop the code when done.

8) Save the VI as Data Acquisition with cDAQ - State Machine.vi.

Virtual Instrumentation 6
Common Design Architectures | Laboratory 8

Questions
1) What are the basic components of a State Machine? (i.e. what components must be present
in order for this architecture to be implemented?)

2) Describe how the Idle Case works.


Hint: Use the Context Help to understand the behavior of the array functions.

3) Describe the role of the For Loop in the digital case.

4) How does the code allow the state machine to stop?

Virtual Instrumentation 7
VIRTUAL INSTRUMENTATION

Lab 8
Common Design
Architectures

Section 1 – Common Design Architectures


---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Configuring the Cases
---------------------------------------------------------------------------  3
Configuring the States
---------------------------------------------------------------------------  5
Common Design Architectures | Laboratory 8

Section 1
Common Design Architectures
Using a collection of LabVIEW skills covered previously, a State Machine will be implemented using
the two states defined in Lab 7 (analog and digital).

In the temperature monitoring application, there are a few different states that the program can be
in. It’s often beneficial to separate a program into different states so that you can organize your code
more cleanly. Additionally, using a State Machine, you can define different conditions for when to
send your program into each state. In this way, your program can run a different sequence of code
depending on the results of a previous sequence.

This is an incredibly powerful capability, and will be necessary for the temperature monitor. Most
of the time, the temperature monitor will simply be in a state of acquiring temperature data. That
temperature data is going to determine if and when the program should go into a different state to
change the value of our status indicator LED.

We’ll learn more about how to use conditions to change the order of execution of our states in the
next lab. In this lab, we’ll focus on the structure of a State Machine.

Pre-Lab Questions:
1) What were some of the limitations of the code in Lab 7?

2) What is a Type Definition and why would it be used?

3) What is the purpose of pre-defined design architectures?


Virtual Instrumentation 2
Common Design Architectures | Laboratory 8

Lab Procedure
Configuring Hardware
1) Keep the same hardware configuration as was used in Lab 7.

Configuring the Cases


1) Open the code from Lab 7, Analog and Digital - ELVIS.vi.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Copy and paste the Lab 7 code into a new VI.

3) Close the Lab 7 code.

4) Highlight the Enumerated control on the Front Panel and select Edit>>Customize Control.

5) Change the control to a Type Definition.

6) Edit the items of the Enum so that Stop is item 0, Analog is item 1, Digital is item 2, and Idle
is item 3.

7) Save the Control as State Machine States.ctl.

8) Close the Type Definition window, and allow the original Enum that was placed on the Front
Panel to be replaced with the Type Definition.

9) On the Block Diagram, place a While Loop around the Case Structure.

10) Right-click on the Enum on the Block Diagram and change it to a constant.

11) Place the constant to the left of the While Loop and wire it through the While Loop to the
case selector of the Case Structure.

12) Right-click on the Case Structure and add a case for every value of the Case Structure.

13) Select the “Idle” case. Right-click the Case Structure and select Make This The Default Case.

Virtual Instrumentation 3
Common Design Architectures | Laboratory 8

14) Right-click on the tunnel going into the While Loop from the Enum constant and select
Replace with Shift Registers.

Virtual Instrumentation 4
Common Design Architectures | Laboratory 8

Configuring the States


1) Create buttons on the Front Panel for Analog, Digital, and Stop.

2) Create the code as shown. Notice that an array of Enum constants is wired to the Index Array.

3) For the analog and digital cases, copy and paste the code from their respective cases in Lab 7.
Make the minor modifications seen in the images shown.

Virtual Instrumentation 5
Common Design Architectures | Laboratory 8

4) Configure the Stop case as shown.

5) Run the code and experiment with clicking the different buttons on the Front Panel.

6) Record the behavior associated with each button and if there is any indication on the ELVIS
that corresponds with a certain case.

7) Stop the code when done.

8) Save the VI as Data Acquisition with ELVIS - State Machine.vi.

Virtual Instrumentation 6
Common Design Architectures | Laboratory 8

Questions
1) What are the basic components of a State Machine? (i.e. what components must be present
in order for this architecture to be implemented?)

2) Describe how the Idle Case works.


Hint: Use the Context Help to understand the behavior of the array functions.

3) Describe the role of the For Loop in the digital case.

4) How does the code allow the state machine to stop?

Virtual Instrumentation 7
VIRTUAL INSTRUMENTATION

Lab 9
Programmatic
Decision Making

Section 1 – Programmatic Decision Making


---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Defining a Condition
---------------------------------------------------------------------------  3
Changing the LED Status
---------------------------------------------------------------------------  4
Configuring the Other Cases
---------------------------------------------------------------------------  5
Programmatic Decision Making | Laboratory 9

Section 1
Programmatic Decision Making
Using a collection of LabVIEW skills covered previously, students will implement decision making
within their State Machine.

In the previous lab, the State Machine waited for the user to click a button before choosing which
state to go to.

With a temperature monitoring application it is usually a requirement to do something if the


temperature goes outside the defined conditions. In this application, the temperature monitor will
turn on an LED if the measured value is outside of a specified range.

Pre-Lab Questions:
1) What were some of the limitations of the State Machine implemented in Lab 8?

2) What are some examples of when a program will need to do a different order of actions,
depending on the results of one of the actions?

Virtual Instrumentation 2
Programmatic Decision Making | Laboratory 9

Lab Procedure
Configuring Hardware
1) Keep the same hardware configuration as was used in Lab 8.

Defining a Condition
1) Open the code from Lab 8, Data Acquisition with cDAQ - State Machine.vi.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Copy and paste the Lab 8 code into a new VI.

3) Close the Lab 8 code.

4) In the Analog case, select Select a VI from the functions palette and find the Check For
Temperature Condition VI that is provided.

5) Wire in the Y component of the waveform.

6) Create controls for Upper Temperature Limit and Lower Temperature Limit.

7) Use an Or function to determine if either of the temperature conditions have been met.

8) Right-click the While Loop and select Add Shift Register.

9) Wire the output of the Or function to the right input of the Shift Register.

10) On the left input of the Shift Register, create a False constant. This will initialize the shift
register with a value of False.

11) Place an Equal function, and compare whether the current temperature condition is equal
to the temperature condition on the previous iteration.

12) If the condition is the same, send the State Machine to the Idle Case. If the condition is
different, send the State Machine to the Digital state. In the Digital state, you’ll update the
status of the LED.

Virtual Instrumentation 3
Programmatic Decision Making | Laboratory 9

13) Your code should match the code shown.

Changing the LED Status


1) Select the Digital Case.
2) Right-click the For Loop and select Remove For Loop.

3) Delete the array of Boolean values and wire the value from the Shift Register into the Write
function.

4) Delete the Wait function.

5) Your code should match the code shown.

Virtual Instrumentation 4
Programmatic Decision Making | Laboratory 9

Configuring the Other Cases


1) Select the Idle Case.

2) Delete the Digital and Analog buttons.

3) Replace the existing code which builds and searches an array with a simple Select function.

4) Wire the value from the left side of the Shift Register through the Idle case to the right side of
the Shift Register.

5) Repeat step 4 for the Stop case.

6) Compare to the images shown.

7) Save the VI as Data Acquisition with cDAQ – Decision Making.vi.

Virtual Instrumentation 5
Programmatic Decision Making | Laboratory 9

Questions
1) Describe what the new shift register is doing. How is this used to determine when to turn
on or off the LED?

2) Open the Check For Temperature Condition VI that is provided. Describe what this VI is
doing.

3) What would happen if the data in the shift register was not wired through the Idle case, and
was instead overwritten with a True or False constant?

4) What is the flow of execution of the states now?

Virtual Instrumentation 6
Programmatic Decision Making | Laboratory 9

5) What is the purpose of the Idle state?

Virtual Instrumentation 7
VIRTUAL INSTRUMENTATION

Lab 9
Programmatic
Decision Making

Section 1 – Programmatic Decision Making


---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Defining a Condition
---------------------------------------------------------------------------  3
Changing the LED Status
---------------------------------------------------------------------------  4
Configuring the Other Cases
---------------------------------------------------------------------------  5
Programmatic Decision Making | Laboratory 9

Section 1
Programmatic Decision Making
Using a collection of LabVIEW skills covered previously, students will implement decision making
within their State Machine.

In the previous lab, the State Machine waited for the user to click a button before choosing which
state to go to.

With a temperature monitoring application it is usually a requirement to do something if the


temperature goes outside the defined conditions. In this application, the temperature monitor will
turn on an LED if the measured value is outside of a specified range.

Pre-Lab Questions:
1) What were some of the limitations of the State Machine implemented in Lab 8?

2) What are some examples of when a program will need to do a different order of actions,
depending on the results of one of the actions?

Virtual Instrumentation 2
Programmatic Decision Making | Laboratory 9

Lab Procedure
Configuring Hardware
1) Keep the same hardware configuration as was used in Lab 8.

Defining a Condition
1) Open the code from Lab 8, Data Acquisition with ELVIS - State Machine.vi.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Copy and paste the Lab 8 code into a new VI.

3) Close the Lab 8 code.

4) In the Analog case, select Select a VI from the functions palette and find the Check For
Temperature Condition VI that is provided.

5) Wire in the Y component of the waveform.

6) Create controls for Upper Temperature Limit and Lower Temperature Limit.

7) Use an Or function to determine if either of the temperature conditions have been met.

8) Right-click the While Loop and select Add Shift Register.

9) Wire the output of the Or function to the right input of the Shift Register.

10) On the left input of the Shift Register, create a False constant. This will initialize the shift
register with a value of False.

11) Place an Equal function, and compare whether the current temperature condition is equal
to the temperature condition on the previous iteration.

12) If the condition is the same, send the State Machine to the Idle Case. If the condition is
different, send the State Machine to the Digital state. In the Digital state, you’ll update the
status of the LED.

Virtual Instrumentation 3
Programmatic Decision Making | Laboratory 9

13) Your code should match the code shown.

Changing the LED Status


14) Select the Digital Case.

15) Right-click the For Loop and select Remove For Loop.

16) Delete the array of Boolean values and wire the value from the Shift Register into the Write
function.

17) Delete the Wait function.

18) Your code should match the code shown.

Virtual Instrumentation 4
Programmatic Decision Making | Laboratory 9

Configuring the Other Cases


1) Select the Idle Case.

2) Delete the Digital and Analog buttons.

3) Replace the existing code which builds and searches an array with a simple Select function.

4) Wire the value from the left side of the Shift Register through the Idle case to the right side of
the Shift Register.

5) Repeat step 4 for the Stop case.

6) Compare to the images shown.

7) Save the VI as Data Acquisition with ELVIS – Decision Making.vi.

Virtual Instrumentation 5
Programmatic Decision Making | Laboratory 9

Questions
1) Describe what the new shift register is doing. How is this used to determine when to turn
on or off the LED?

2) Open the Check For Temperature Condition VI that is provided. Describe what this VI is
doing.

3) What would happen if the data in the shift register was not wired through the Idle case, and
was instead overwritten with a True or False constant?

4) What is the flow of execution of the states now?

Virtual Instrumentation 6
Programmatic Decision Making | Laboratory 9

5) What is the purpose of the Idle state?

Virtual Instrumentation 7
VIRTUAL INSTRUMENTATION

Lab 10
Communicating
Among Multiple
Loops with Queues
Section 1 – Communicating Among Multiple Loops with
Queues
---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  4
Implementing the Producer/Consumer Architecture
---------------------------------------------------------------------------  4
The Top Loop
---------------------------------------------------------------------------  4
The Bottom Loop
---------------------------------------------------------------------------  7
Communicating Among Multiple Loops with Queues | Laboratory 10

Section 1
Communicating Among
Multiple Loops with Queues
The objective of this lab is to understand multiple ways of communicating between multiple
loops. Queues will be implemented in this lab, but through discussion questions, queues will be
contrasted to notifiers and variables.

In a temperature monitoring application, it is often important to log the data that is acquired. In this
application, temperature data will be logged to a TDMS file.

Often data logging is done in a loop that runs in parallel to the data acquisition loop. In this way, the
time it takes to save data to a file will not affect the timing of acquiring data.

You will explore these parallel loops and communication between them in this lab.

Pre-Lab Questions:
1) Will the loops below run in parallel or one after the other? If so, which will run first?

Virtual Instrumentation 2
Communicating Among Multiple Loops with Queues | Laboratory 10

2) What is a potential modification that could be made to the code in question 1 so that both
loops run continuously until a single stop button is clicked?

3) What is a main difference between queues and notifiers?

Virtual Instrumentation 3
Communicating Among Multiple Loops with Queues | Laboratory 10

Lab Procedure
Configuring Hardware
1) Keep the same hardware configuration as was used in Lab 9.

Implementing the Producer/Consumer Architecture


1) Open the VI built in Lab 9, Data Acquisition with cDAQ – Decision Making.vi.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Copy and paste the Lab 9 code into a new VI.

3) Close the Lab 9 code.

4) In LabVIEW, select File>>New. Open the Producer/Consumer Design Pattern (Data) under
VI>>From Template>>Frameworks>>Design Patterns. Use this design pattern as an example
for implementing the design pattern into the state machine code.

The Top Loop


1) Only data from the “Analog Case” will be sent to the bottom loop for processing, so the
“Enqueue Element” should only appear in this case. All other cases should have the
“Queue Out” wire wired straight through.

2) Remember that the “Obtain Queue” needs to have the data type defined for the element
being stored in the queue. In this case, the waveform data from the analog case will be
passed through the queue. In order to define this data type, make a copy of the waveform
chart indicator and change it to a constant. Wire this constant to the “Obtain Queue.”

Virtual Instrumentation 4
Communicating Among Multiple Loops with Queues | Laboratory 10

3) Configure the “Idle Case,” “Digital Case,” and “Stop Cases” as shown.

Virtual Instrumentation 5
Communicating Among Multiple Loops with Queues | Laboratory 10

4) Include the “Enqueue Element” in the Analog Case and configure it as shown.

Virtual Instrumentation 6
Communicating Among Multiple Loops with Queues | Laboratory 10

The Bottom Loop


1) In the bottom loop, implement code to write to a TDMS file as was done in Lab 5. Leave the
error case blank.

2) Use a File Dialog Express VI to Create or Open a file. Set pattern (all files) to *.tdms.

3) Ensure your code matches the code


shown.

4) Specify a file path to save a .tdms file in the file path constant.

5) Run the code.

6) Define the range of the temperature warning to create a warning. Notice that the LED turns
on.

7) Define the range of the temperature warning so that the LED turns off.

8) Stop the VI when done.

9) Use the TDMS Viewer VI used in Lab 5 to view the Analog data.

10) Save the VI as Data Acquisition with cDAQ – Producer Consumer.vi.

Virtual Instrumentation 7
Communicating Among Multiple Loops with Queues | Laboratory 10

Questions
1) How does the code know to stop if there is no stop button wired to the bottom loop
condition terminal?

2) Why is it good practice to not have analysis and acquisition in the same loop?

3) Could this same idea be implemented with variables? If so, what are the pros and cons of
using variables in this application?

4) Could notifiers be used in this application? If so what are the pros and cons of using
notifiers?

5) Could semaphores be used directly in this application in the same manner that the queues
are used? Why or why not?

Virtual Instrumentation 8
VIRTUAL INSTRUMENTATION

Lab 10
Communicating
Among Multiple
Loops with Queues
Section 1 – Communicating Among Multiple Loops with
Queues
---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  4
Implementing the Producer/Consumer Architecture
---------------------------------------------------------------------------  4
The Top Loop
---------------------------------------------------------------------------  4
The Bottom Loop
---------------------------------------------------------------------------  7
Communicating Among Multiple Loops with Queues | Laboratory 10

Section 1
Communicating Among
Multiple Loops with Queues
The objective of this lab is to understand multiple ways of communicating between multiple
loops. Queues will be implemented in this lab, but through discussion questions, queues will be
contrasted to notifiers and variables.

In a temperature monitoring application, it is often important to log the data that is acquired. In this
application, temperature data will be logged to a TDMS file.

Often data logging is done in a loop that runs in parallel to the data acquisition loop. In this way, the
time it takes to save data to a file will not affect the timing of acquiring data.

You will explore these parallel loops and communication between them in this lab.

Pre-Lab Questions:
1) Will the loops below run in parallel or one after the other? If so, which will run first?

Virtual Instrumentation 2
Communicating Among Multiple Loops with Queues | Laboratory 10

2) What is a potential modification that could be made to the code in question 1 so that both
loops run continuously until a single stop button is clicked?

3) What is a main difference between queues and notifiers?

Virtual Instrumentation 3
Communicating Among Multiple Loops with Queues | Laboratory 10

Lab Procedure
Configuring Hardware
1) Keep the same hardware configuration as was used in Lab 9.

Implementing the Producer/Consumer Architecture


1) Open the VI built in Lab 9, Data Acquisition with ELVIS – Decision Making.vi.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Copy and paste the Lab 9 code into a new VI.

3) Close the Lab 9 code.

4) In LabVIEW, select File>>New. Open the Producer/Consumer Design Pattern (Data) under
VI>>From Template>>Frameworks>>Design Patterns. Use this design pattern as an example
for implementing the design pattern into the state machine code.

The Top Loop


1) Only data from the “Analog Case” will be sent to the bottom loop for processing, so the
“Enqueue Element” should only appear in this case. All other cases should have the
“Queue Out” wire wired straight through.

2) Remember that the “Obtain Queue” needs to have the data type defined for the element
being stored in the queue. In this case, the waveform data from the analog case will be
passed through the queue. In order to define this data type, make a copy of the waveform
chart indicator and change it to a constant. Wire this constant to the “Obtain Queue.”

Virtual Instrumentation 4
Communicating Among Multiple Loops with Queues | Laboratory 10

3) Configure the “Idle Case,” “Digital Case,” and “Stop Cases” as shown.

Virtual Instrumentation 5
Communicating Among Multiple Loops with Queues | Laboratory 10

4) Include the “Enqueue Element” in the Analog Case and configure it as shown.

Virtual Instrumentation 6
Communicating Among Multiple Loops with Queues | Laboratory 10

The Bottom Loop


1) In the bottom loop, implement code to write to a TDMS file as was done in Lab 5. Leave the
error case blank.

2) Use a File Dialog Express VI to Create or Open a file. Set pattern (all files) to *.tdms.

3) Ensure your code matches the code


shown.

4) Specify a file path to save a .tdms file in the file path constant.

5) Run the code.

6) Define the range of the temperature warning to create a warning. Notice that the LED turns
on.

7) Define the range of the temperature warning so that the LED turns off.

8) Stop the VI when done.

9) Use the TDMS Viewer VI used in Lab 5 to view the Analog data.

10) Save the VI as Data Acquisition with ELVIS – Producer Consumer.vi.

Virtual Instrumentation 7
Communicating Among Multiple Loops with Queues | Laboratory 10

Questions
1) How does the code know to stop if there is no stop button wired to the bottom loop
condition terminal?

2) Why is it good practice to not have analysis and acquisition in the same loop?

3) Could this same idea be implemented with variables? If so, what are the pros and cons of
using variables in this application?

4) Could notifiers be used in this application? If so what are the pros and cons of using
notifiers?

5) Could semaphores be used directly in this application in the same manner that the queues
are used? Why or why not?

Virtual Instrumentation 8
VIRTUAL INSTRUMENTATION

Lab 11
Event Programming
and Improving an
Existing VI
Section 1 – Event Programming and Improving an
Existing VI
---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Implementing Notify Events
---------------------------------------------------------------------------  3
Implementing Filter Events
---------------------------------------------------------------------------  5
Disregarding Errors
---------------------------------------------------------------------------  6
Event Programming and Improving an Existing VI | Laboratory 11

Section 1
Event Programming and
Improving an Existing VI
The objective of this lab is to understand how events can be used as a case structure and can offer
more options as to how a case is handled. This lab builds directly off of Lab 10 and teaches how to
use events instead of a case structure in the producer/consumer design pattern. The lab also briefly
touches on using local variables. Finally, the lab discusses improving an existing VI.

In our temperature monitoring application, it is important that the monitoring code runs at the
proper frequency, but we want the front panel to be responsive to user interaction. In this lab you
will explore one way to implement this.

Pre-Lab Questions:
1) What could be improved in the code
shown?


2) What is a benefit of using an Event Structure over a Case Structure?

3) Can the functionality of a state machine be implemented with events? Why or why not?


Virtual Instrumentation 2
Event Programming and Improving an Existing VI | Laboratory 11

Lab Procedure
Configuring Hardware
1) Keep the same hardware configuration as was used in Lab 10.

Implementing Notify Events


1) Open the Producer/Consumer Design Pattern (Events) to use as a template for this lab.

2) Open the VI created in Lab 10, Data Acquisition with cDAQ – Producer Consumer.vi, and
copy and paste it into a new VI.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

3) Close the code from Lab 10.

4) Place down an event structure inside of the case structure in the Idle case.

5) Right-click on the border of the event structure and select Add Event Case….

6) Configure the dialog box for a


Notify “Value Change” Event for
the Stop button under Controls, as
seen in the dialog box.

7) Select Ok when done.

8) Move the terminal for the Stop button into the Stop case.

9) Delete the Wait function from the Timeout case.

10) Wire a value of 250 into the Event Timeout terminal for the Event Structure.

Virtual Instrumentation 3
Event Programming and Improving an Existing VI | Laboratory 11

11) Make sure your code for the cases


matches the code shown.

12) Run the code. Notice that every 250 ms, the analog case is running.

13) The analog case will still trigger the digital case if a digital warning appears.

14) Click the Stop button.

15) Notice the program is very responsive and stops quickly.

Virtual Instrumentation 4
Event Programming and Improving an Existing VI | Laboratory 11

Implementing Filter Events


1) Add another event case to the Event
Structure and configure it as seen in
the dialog box.

2) Place a Two Button Dialog Box inside


this event case and configure it to
have a message of “Close Window?”
Wire the output of the Two Button
Dialog Box to a Boolean “not.”
Wire the output of the “not” to the
“Discard” terminal of the event case.

3) Ensure that your code matches the


code shown.

4) Run the code.

5) Experiment with closing the Front


Panel.

6) Stop the code when done.

7) Save the VI as Data Acquisition with


cDAQ – Events.vi.

Virtual Instrumentation 5
Event Programming and Improving an Existing VI | Laboratory 11

Disregarding Errors
1) Copy and paste Lab 9 Part 1 into a new VI.

2) Create a local variable from the stop button in the “Stop” event case. Do this by either right-
clicking the button and selecting Create>>Local Variable or by placing down a blank local
variable from the Structures Palette and assigning it to the stop button by right-clicking it and
selecting Select Item>>Stop. You can also left-click on a new local variable to populate the
Front Panel controls the variable can be linked to.

3) A local variable can be changed from read to write by right-clicking on the local variable and
selecting Change to Read. Change the new local variable to be reading.

4) In the bottom loop, delete the error wire going into the loop condition terminal and wire the
new local variable to the loop condition terminal instead.

5) On the Front Panel, right-click on the stop button and change its mechanical action to Switch
Until Released.

6) Ensure that your bottom loop


matches the image shown.

7) Run the code and notice that it runs the same as before. Stop the code when done.

8) Save the VI.

Virtual Instrumentation 6
Event Programming and Improving an Existing VI | Laboratory 11

Questions
1) What is the difference between a notify event and a filter event?

2) What happens if the Digital Button is clicked while the analog case is running? Will that
event be processed?

3) What is a potential application of using the local variable in the bottom loop instead of
wiring the error wire to the loop condition terminal?

4) What is the best way to handle code that is repeated multiple times in a VI?

Virtual Instrumentation 7
VIRTUAL INSTRUMENTATION

Lab 11
Event Programming
and Improving an
Existing VI
Section 1 – Event Programming and Improving an
Existing VI
---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Implementing Notify Events
---------------------------------------------------------------------------  3
Implementing Filter Events
---------------------------------------------------------------------------  5
Disregarding Errors
---------------------------------------------------------------------------  6
Event Programming and Improving an Existing VI | Laboratory 11

Section 1
Event Programming and
Improving an Existing VI
The objective of this lab is to understand how events can be used as a case structure and can offer
more options as to how a case is handled. This lab builds directly off of Lab 10 and teaches how to
use events instead of a case structure in the producer/consumer design pattern. The lab also briefly
touches on using local variables. Finally, the lab discusses improving an existing VI.

In our temperature monitoring application, it is important that the monitoring code runs at the
proper frequency, but we want the front panel to be responsive to user interaction. In this lab you
will explore one way to implement this.

Pre-Lab Questions:
1) What could be improved in the code
shown?


2) What is a benefit of using an Event Structure over a Case Structure?

3) Can the functionality of a state machine be implemented with events? Why or why not?


Virtual Instrumentation 2
Event Programming and Improving an Existing VI | Laboratory 11

Lab Procedure
Configuring Hardware
1) Keep the same hardware configuration as was used in Lab 10.

Implementing Notify Events


1) Open the Producer/Consumer Design Pattern (Events) to use as a template for this lab.

2) Open the VI created in Lab 10, Data Acquisition with ELVIS – Producer Consumer.vi, and
copy and paste it into a new VI.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

3) Close the code from Lab 10.

4) Place down an event structure inside of the case structure in the Idle case.

5) Right-click on the border of the event structure and select Add Event Case….

6) Configure the dialog box for a


Notify “Value Change” Event for
the Stop button under Controls, as
seen in the dialog box.

7) Select Ok when done.

8) Move the terminal for the Stop button into the Stop case.

9) Delete the Wait function from the Timeout case.

10) Wire a value of 250 into the Event Timeout terminal for the Event Structure.

Virtual Instrumentation 3
Event Programming and Improving an Existing VI | Laboratory 11

11) Make sure your code for the cases


matches the code shown.

12) Run the code. Notice that every 250 ms, the analog case is running.

13) The analog case will still trigger the digital case if a digital warning appears.

14) Click the Stop button.

15) Notice the program is very responsive and stops quickly.

Virtual Instrumentation 4
Event Programming and Improving an Existing VI | Laboratory 11

Implementing Filter Events


1) Add another event case to the Event
Structure and configure it as seen in
the dialog box.

2) Place a Two Button Dialog Box inside


this event case and configure it to
have a message of “Close Window?”
Wire the output of the Two Button
Dialog Box to a Boolean “not.”
Wire the output of the “not” to the
“Discard” terminal of the event case.

3) Ensure that your code matches the


code shown.

4) Run the code.

5) Experiment with closing the Front


Panel.

6) Stop the code when done.

7) Save the VI as Data Acquisition with


ELVIS – Events.vi.

Virtual Instrumentation 5
Event Programming and Improving an Existing VI | Laboratory 11

Disregarding Errors
1) Copy and paste Lab 9 Part 1 into a new VI.

2) Create a local variable from the stop button in the “Stop” event case. Do this by either right-
clicking the button and selecting Create>>Local Variable or by placing down a blank local
variable from the Structures Palette and assigning it to the stop button by right-clicking it and
selecting Select Item>>Stop. You can also left-click on a new local variable to populate the
Front Panel controls the variable can be linked to.

3) A local variable can be changed from read to write by right-clicking on the local variable and
selecting Change to Read. Change the new local variable to be reading.

4) In the bottom loop, delete the error wire going into the loop condition terminal and wire the
new local variable to the loop condition terminal instead.

5) On the Front Panel, right-click on the stop button and change its mechanical action to Switch
Until Released.

6) Ensure that your bottom loop


matches the image shown.

7) Run the code and notice that it runs the same as before. Stop the code when done.

8) Save the VI.

Virtual Instrumentation 6
Event Programming and Improving an Existing VI | Laboratory 11

Questions
1) What is the difference between a notify event and a filter event?

2) What happens if the Digital Button is clicked while the analog case is running? Will that
event be processed?

3) What is a potential application of using the local variable in the bottom loop instead of
wiring the error wire to the loop condition terminal?

4) What is the best way to handle code that is repeated multiple times in a VI?

Virtual Instrumentation 7
VIRTUAL INSTRUMENTATION

Lab 12
Controlling the
User Interface
Section 1 – Controlling the User Interface
---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Creating SubVIs
---------------------------------------------------------------------------  3
Implicitly Linked Property Nodes
---------------------------------------------------------------------------  5
Explicitly Linked Property Nodes
---------------------------------------------------------------------------  7
Explicitly Linked Invoke Nodes
---------------------------------------------------------------------------  9
Using VI Properties to Control the User Interface
-------------------------------------------------------------------------  10
Controlling the User Interface | Laboratory 12

Section 1
Controlling the User Interface
In this lab, you will learn how to programmatically control the user interface through Property
Nodes and Invoke Nodes as well as through VI Properties.

Programmatically controlling the user interface can be useful to visually indicate when something
important happens in a monitoring application. More generally, it is often useful to give the user
access to different properties of the front panel while the program is running.

Pre-Lab Questions:
1) What is a control reference?

2) Boolean is a sub-class of what class?

3) Within the Boolean subclass, a Stop Button would be considered a(n) ___________________ ?

4) What is a class?

5) What is the difference between methods and properties?

Virtual Instrumentation 2
Controlling the User Interface | Laboratory 12

Lab Procedure
Configuring Hardware
1) Keep the same hardware configuration as was used in Lab 11.

Creating SubVIs
1) Copy and paste the code from Lab 11, Data Acquisition with cDAQ – Events.vi, into a new
VI.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Close the code from Lab 11.

3) Creating subVIs can be a tool in simplifying the Block Diagram. Create subVIs for the code
in the Analog and Digital cases.

4) Edit the subVI icon for each subVI to be indicative of its function.

Virtual Instrumentation 3
Controlling the User Interface | Laboratory 12

5) Ensure that your Analog event case matches the first image and your Digital case matches
the second image.

Virtual Instrumentation 4
Controlling the User Interface | Laboratory 12

Implicitly Linked Property Nodes


There are two ways to create implicitly linked Property Nodes.

Method 1: Creating a Property Node from a Front Panel Object


1) Right-click the stop button on the Front Panel and select Create>>Property Node>>Blinking.
Notice that “blinking” is part of a list of all properties available for a Boolean control.

2) Place the Property Node and


constant outside of the top while
loop on the left side as shown.

3) Right-click the Property Node and


select Change All to Write.

4) Wire a “True” constant to the


Property Node.

5) Run the code.

6) Notice the effect of the Property Node on the Front Panel.

7) Stop the code when done.

Virtual Instrumentation 5
Controlling the User Interface | Laboratory 12

Method 2: Implicitly Linking a Blank Property Node


1) Delete the Property Node and constant created in Method 1.

2) On the Block Diagram, navigate to the Application Control Palette.

3) Place down a Property Node from the Application Control Palette.

4) Move the new Property Node to the same location on the Block Diagram used in Method 1.

5) Right-click the Property Node and select Link to>>Pane>>Stop. You should notice that you
have the ability to link the Property Node to any control on the Front Panel.

6) Right-click the Property Node again and select Change All to Write.

7) Left-click on the word “Property” to access a list of all properties available for a Boolean
control.

8) Select blinking.

9) Wire a “True” constant to the Property Node.

10) Run the code and observe the same effect noticed in Method 1.

11) Stop the code when done.

Virtual Instrumentation 6
Controlling the User Interface | Laboratory 12

Explicitly Linked Property Nodes


1) In the same space where the blinking Property Node is placed, place a new Property Node
from the Application Control Palette.

2) Also from the Application Control Palette, place a VI Server Reference.

3) Wire the VI Server Reference to the Reference input of the new Property Node.

4) Drag the bottom of the Property Node down to show three properties.

5) Right click on the Property Node and select Change All to Write.

6) Left-click the first property and select Front Panel Window>>Show Menu Bar.

7) Left-click the second property and select Front Panel Window>>Title Bar Visible.

8) Left-click the third property and select Tool Bar>>Visible.

9) Wire “False” constants to each property.

10) Wire the Error Out of the new Property Node to the Error In of the blinking Property Node.

11) Run the VI and record the effect of these properties on the Front Panel.

12) Stop the code when done.

13) Move to the Analog case.

14) Double-click on the Analog Case SubVI to access the subVI Block Diagram.

15) Place a new Property Node on the subVI Block Diagram from the Applications Control Palette.

16) Create a control for the reference input to the Property Node.

17) Right-click the reference control and select Select VI Server Class>>Generic>>GObject>>
Control>>GraphChart>>WaveformChart.

18) Right-click the Property Node and choose Change All to Write.

19) Left-click the word “Property,” and notice that a list of properties relevant for a waveform chart
is listed.

Virtual Instrumentation 7
Controlling the User Interface | Laboratory 12

20) Choose Plot>>Plot Color.

21) From the Dialog & User Interface Palette place down a Color Box Constant and wire it to the
input of the property.

22) Left-click on the color box and choose red.

23) Ensure that your code matches the code shown.

24) Switch to the Front Panel and notice that there is a reference control present on the Front
Panel.

25) Edit the icon Connector Pane for the subVI to create an input for the reference.

26) Save and close the subVI. Remember to relink the subVI in the main VI because the Connector
Pane was edited.

27) In the main VI, right-click on the waveform chart indicator and select Create>>Reference.

28) Wire the Waveform Chart Reference to the reference input you created for the subVI.

29) Ensure that your code matches the


code shown.

30) Run code and record the effect of the


new property on the graph.

31) Stop the code when done.

Virtual Instrumentation 8
Controlling the User Interface | Laboratory 12

Explicitly Linked Invoke Nodes


1) Add a new button to the Front Panel called “Center.”

2) Add a new Value Change event case for the “Center” button.

3) In the new event case, place an Invoke Node from the Application Control Palette.

4) Wire a VI Server Reference to the new Invoke Node.

5) Left-click on the word “Method” and choose Front Panel>>Center.

6) Ensure that your code matches the


code shown.

7) Run the code and observe the behavior of the Invoke Node.

8) Stop the code when done.

9) Save the VI as Data Acquisition with cDAQ - References.vi.

Virtual Instrumentation 9
Controlling the User Interface | Laboratory 12

Using VI Properties to Control the User Interface


1) Select File>>VI Properties.

2) Change the Category to Window Appearance.

3) Select Customize.

4) Deselect the boxes that show the horizontal and vertical toolbars.

5) Run the VI and observe the effects of these changes.

6) Stop the code when done.

7) Do not save these changes.

Virtual Instrumentation 10
Controlling the User Interface | Laboratory 12

Questions
1) Is it possible to create implicitly linked Invoke Nodes? If so, how?

2) Why does a subVI require a reference?

3) What does a VI Server Reference do?

4) How do configure one reference to allow properties to be configured that would affect
multiple different types of controls?

Virtual Instrumentation 11
VIRTUAL INSTRUMENTATION

Lab 12
Controlling the
User Interface

Section 1 – Controlling the User Interface


---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Creating SubVIs
---------------------------------------------------------------------------  3
Explicitly Linked Property Nodes
---------------------------------------------------------------------------  7
Explicitly Linked Invoke Nodes
---------------------------------------------------------------------------  9
Using VI Properties to Control the User Interface
-------------------------------------------------------------------------  10
Controlling the User Interface | Laboratory 12

Section 1
Controlling the User Interface
In this lab, you will learn how to programmatically control the user interface through Property
Nodes and Invoke Nodes as well as through VI Properties.

Programmatically controlling the user interface can be useful to visually indicate when something
important happens in a monitoring application. More generally, it is often useful to give the user
access to different properties of the front panel while the program is running.

Pre-Lab Questions:
1) What is a control reference?

2) Boolean is a sub-class of what class?

3) Within the Boolean subclass, a Stop Button would be considered a(n) ___________________ ?

4) What is a class?

5) What is the difference between methods and properties?

Virtual Instrumentation 2
Controlling the User Interface | Laboratory 12

Lab Procedure
Configuring Hardware
1) Keep the same hardware configuration as was used in Lab 11.

Creating SubVIs
1) Copy and paste the code from Lab 11, Data Acquisition with ELVIS – Events.vi, into a new
VI.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Close the code from Lab 11.

3) Creating subVIs can be a tool in simplifying the Block Diagram. Create subVIs for the code
in the Analog and Digital cases.

4) Edit the subVI icon for each subVI to be indicative of its function.

Virtual Instrumentation 3
Controlling the User Interface | Laboratory 12

5) Ensure that your Analog event case matches the first image and your Digital case matches
the second image.

Virtual Instrumentation 4
Controlling the User Interface | Laboratory 12

6) Implicitly Linked Property Nodes


There are two ways to create implicitly linked Property Nodes.

Method 1: Creating a Property Node from a Front Panel Object


1) Right-click the stop button on the Front Panel and select Create>>Property Node>>Blinking.
Notice that “blinking” is part of a list of all properties available for a Boolean control.

2) Place the Property Node and


constant outside of the top while
loop on the left side as shown.

3) Right-click the Property Node and


select Change All to Write.

4) Wire a “True” constant to the


Property Node.

5) Run the code.

6) Notice the effect of the Property Node on the Front Panel.

7) Stop the code when done.

Virtual Instrumentation 5
Controlling the User Interface | Laboratory 12

Method 2: Implicitly Linking a Blank Property Node


1) Delete the Property Node and constant created in Method 1.

2) On the Block Diagram, navigate to the Application Control Palette.

3) Place down a Property Node from the Application Control Palette.

4) Move the new Property Node to the same location on the Block Diagram used in Method 1.

5) Right-click the Property Node and select Link to>>Pane>>Stop. You should notice that you
have the ability to link the Property Node to any control on the Front Panel.

6) Right-click the Property Node again and select Change All to Write.

7) Left-click on the word “Property” to access a list of all properties available for a Boolean
control.

8) Select blinking.

9) Wire a “True” constant to the Property Node.

10) Run the code and observe the same effect noticed in Method 1.

11) Stop the code when done.

Virtual Instrumentation 6
Controlling the User Interface | Laboratory 12

Explicitly Linked Property Nodes


1) In the same space where the blinking Property Node is placed, place a new Property Node
from the Application Control Palette.

2) Also from the Application Control Palette, place a VI Server Reference.

3) Wire the VI Server Reference to the Reference input of the new Property Node.

4) Drag the bottom of the Property Node down to show three properties.

5) Right click on the Property Node and select Change All to Write.

6) Left-click the first property and select Front Panel Window>>Show Menu Bar.

7) Left-click the second property and select Front Panel Window>>Title Bar Visible.

8) Left-click the third property and select Tool Bar>>Visible.

9) Wire “False” constants to each property.

10) Wire the Error Out of the new Property Node to the Error In of the blinking Property Node.

11) Run the VI and record the effect of these properties on the Front Panel.

12) Stop the code when done.

13) Move to the Analog case.

14) Double-click on the Analog Case SubVI to access the subVI Block Diagram.

15) Place a new Property Node on the subVI Block Diagram from the Applications Control Palette.

16) Create a control for the reference input to the Property Node.

17) Right-click the reference control and select Select VI Server Class>>Generic>>GObject>>
Control>>GraphChart>>WaveformChart.

18) Right-click the Property Node and choose Change All to Write.

19) Left-click the word “Property,” and notice that a list of properties relevant for a waveform chart
is listed.

Virtual Instrumentation 7
Controlling the User Interface | Laboratory 12

20) Choose Plot>>Plot Color.

21) From the Dialog & User Interface Palette place down a Color Box Constant and wire it to the
input of the property.

22) Left-click on the color box and choose red.

23) Ensure that your code matches the code shown.

24) Switch to the Front Panel and notice that there is a reference control present on the Front
Panel.

25) Edit the icon Connector Pane for the subVI to create an input for the reference.

26) Save and close the subVI. Remember to relink the subVI in the main VI because the Connector
Pane was edited.

27) In the main VI, right-click on the waveform chart indicator and select Create>>Reference.

28) Wire the Waveform Chart Reference to the reference input you created for the subVI.

29) Ensure that your code matches the


code shown.

30) Run code and record the effect of the


new property on the graph.

31) Stop the code when done.

Virtual Instrumentation 8
Controlling the User Interface | Laboratory 12

Explicitly Linked Invoke Nodes


1) Add a new button to the Front Panel called “Center.”

2) Add a new Value Change event case for the “Center” button.

3) In the new event case, place an Invoke Node from the Application Control Palette.

4) Wire a VI Server Reference to the new Invoke Node.

5) Left-click on the word “Method” and choose Front Panel>>Center.

6) Ensure that your code matches the


code shown.

7) Run the code and observe the behavior of the Invoke Node.

8) Stop the code when done.

9) Save the VI as Data Acquisition with ELVIS - References.vi.

Virtual Instrumentation 9
Controlling the User Interface | Laboratory 12

Using VI Properties to Control the User Interface


1) Select File>>VI Properties.

2) Change the Category to Window Appearance.

3) Select Customize.

4) Deselect the boxes that show the horizontal and vertical toolbars.

5) Run the VI and observe the effects of these changes.

6) Stop the code when done.

7) Do not save these changes.

Virtual Instrumentation 10
Controlling the User Interface | Laboratory 12

Questions
1) Is it possible to create implicitly linked Invoke Nodes? If so, how?

2) Why does a subVI require a reference?

3) What does a VI Server Reference do?

4) How do configure one reference to allow properties to be configured that would affect
multiple different types of controls?

Virtual Instrumentation 11
VIRTUAL INSTRUMENTATION

Lab 13
Advanced File I/O
and Creating/Distrib-
uting an Application
Section 1 – Advanced File I/O and Creating/Distributing
an Application
---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Configuring the File/O
---------------------------------------------------------------------------  3
Creating an Application
---------------------------------------------------------------------------  8
Creating an Installer
---------------------------------------------------------------------------  8
Testing
---------------------------------------------------------------------------  9
Advanced File I/O and Creating/Distributing an Application | Laboratory 13

Section 1
Advanced File I/O and Creating/
Distributing an Application
In this lab, you will expand upon the code from Lab 12 by writing data from more than one source
to a TDMS file and using TDMS Set Properties to distinguish between data sources within the TDMS
file. The code will then be turned into an executable. The executable will then be included in an
installer so that it can be distributed to other machines without LabVIEW or the necessary drivers.

Be building an executable and installer, you can create a package that will allow your temperature
monitoring program to be deployed to computers that don’t have the LabVIEW development
environment installed.

This is usually the final step when building an application that will be used in the field.

Pre-Lab Questions:
1) True / False: Use ASCII if you need to perform random access reads or writes and if numeric
precision and fast File I/O are requirements.

Please provide what file type(s) fits the above criteria more appropriately if the statement is
false.

2) What type of file is a Datalog File and what is it used for?

3) What is TDMS and what are some benefits of this file type?

Virtual Instrumentation 2
Advanced File I/O and Creating/Distributing an Application | Laboratory 13

Lab Procedure
Configuring Hardware
1) Keep the connections that are currently in place.

2) If you have a function generator or a similar device or sensor, connect it to channel AI2
of the analog input card. We will use this signal to simulate a second source of data to be
saved to the TDMS file.

3) If you don’t have a device that can be used, channel AI2 can remain unconnected. In this
case, data measured on this channel will have a value close to 0V.

Configuring the File/O


1) Copy and paste the code from Lab 12, Data Acquisition with cDAQ - References.vi, into a
new VI.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Close the code from Lab 12.

3) Add a new button to the Front Panel called “Second Source.”

4) Add a new value change event case for the “Second Source” button.

5) Place the “Second Source” Boolean control inside of the new event case.

6) Within the new event case, add a DAQ Assistant Express VI from the DAQmx palette on the
Mesurement I/O Palette.

7) Select Acquire Signals>>Analog Input>>Voltage. Then choose channel ai2 of the analog
input card plugged into the cDAQ and click Finish.

8) Use the settings as they appear and select Ok.

9) Create a Waveform Graph Indicator for the Data output of the DAQmx Express VI.

10) Change the x-scale of the graph to range from 0 to 0.1.

11) Use a “Bundle” to bundle the output of the DAQmx Express VI with a string constant
containing the value “Second Source.”

Virtual Instrumentation 3
Advanced File I/O and Creating/Distributing an Application | Laboratory 13

12) Add a new Enqueue Element to this case.


13) Delete Queue and Error wires that run through the Idle case of the case structure.

14) Wire the Queue and Error wires into the Enqueue Element function.

15) Wire the Queue and Error wires out of the Enqueue Element function to the tunnels at the
right side of the Idle case.

16) You’ll now need to connect the Queue and Error wires through the Timeout, Stop, Panel
Close?, and Center cases of the Event Structure as well.

17) In the Second Source case, in order


to wire the new cluster coming
from the bundle to the Enqueue
Element, the data type of the queue
needs to be modified. In order to
modify the data type of the queue
appropriately, place the waveform
constant that is currently defining
the queue data type inside of a
cluster and add an empty string
constant to the cluster as shown.
Notice that the wire color of the
queue reference reflects the data
type change.

18) Wire the output of the Bundle within the Scope Event Case to the “Element” input of the
Enqueue Element as shown.

Virtual Instrumentation 4
Advanced File I/O and Creating/Distributing an Application | Laboratory 13

19) Move to the analog case and open the subVI.

20) Bundle the output of the Convert Thermistor Reading function with a string constant
containing the value “Analog.”

21) Notice that you cannot wire the new cluster to the Enqueue Element because the Enqueue
Element is referencing the old queue data type. To resolve this, create a control from the
queue reference wire within the main VI and copy it into the subVI.

22) Delete the control from the main VI.

23) Replace the existing Queue In control in the subVI with the new control. Notice that the data
type of the queue is now correct and the cluster can be wired to the “Element” input of the
Enqueue Element.

24) Create a new indicator for the queue out terminal of the Enqueue Element.

25) Edit the Connector Pane of the subVI so that the new queue control and indicator have
terminals on the subVI.

26) Ensure that your code matches the code shown, and save the subVI.

27) Within the Case structure in the bottom loop, create a new Case Structure around the current
File I/O code.

28) Place an “Unbundle” outside of the new case structure.

29) Wire the Element output terminal of the Dequeue Element to the cluster.

30) Wire the string output of the Unbundle to the Case Selector of the new case structure.

31) Label the “True” case to be “Analog” and the “False” case to be “Second Source”.

Virtual Instrumentation 5
Advanced File I/O and Creating/Distributing an Application | Laboratory 13

32) Wire the waveform output of the Unbundle to the data input of the TDMS Write.

33) Add a new case to the case structure and make it the default case. Leave this case empty, but
wire the TDMS and error wires through the case.
34) Within the Analog Case, add a TDMS Set Properties before the TDMS Write and wire them
together appropriately.

35) Create a constant for the “Property Names” terminal of the TDMS Set Properties.
36) Enter “Test Number” into the first value of the array.

37) Create a string array control on the Front Panel and wire it to the “Property Values” terminal of
the TDMS Set Properties.

38) Make constants for the group name and channel name and give them values of “Producer/
Consumer” and “Analog” respectively.

39) Create the same code in the Second Source case, but replace the “Analog” constants with
“Second Source”.

Virtual Instrumentation 6
Advanced File I/O and Creating/Distributing an Application | Laboratory 13

40) Ensure that your bottom loop code matches the code shown for each respective case.

Virtual Instrumentation 7
Advanced File I/O and Creating/Distributing an Application | Laboratory 13

Creating an Application
1) Save the VI as Data Acquisition with cDAQ – MainVI.vi and add it to a Project.

2) In the project, right-click on Build Specifications and choose New>> Application (EXE).

3) Save the Project as Data Acquisition with cDAQ - Installer, if prompted.

4) In the “Information” category name the application Data Acquisition with cDAQ.exe.

5) Take note of the “Destination Directory” as this is where the application will be saved on your
computer when the application is built.

6) In the “Source Files” category, move the VI for Lab 13 to “Startup VIs.”

7) These are all of the modifications that need to be made for this application build, but take
note of the options found in the other categories.

8) When ready, click Build.

9) Notice that your new application appears under “Build Specifications” in the project.

Creating an Installer
1) Right-click on Build Specifications and choose New>>Installer.

2) Name the installer under the “Product Information” category.

3) Under Source Files, move the Lab 13 executable to the “Destination View.” By default, it will
move to the Program Files folder.

4) In the Additional Installers Category, include the appropriate LabVIEW Run-Time Engine and
the NI-DAQmx Application Development Support.

5) Build the installer.

6) You may be prompted to locate the location that DAQmx is installed from on your computer.

Virtual Instrumentation 8
Advanced File I/O and Creating/Distributing an Application | Laboratory 13

Testing
1) Install the installer on a computer without LabVIEW if possible.

2) Run the executable.

3) Enter the number 1 into the “Property Values” array for “Analog” and for “Second Source” to
record this run as the first test.

4) Make sure to click the Second Source button to log some data.

5) Use the TDMS File Viewer on a computer with LabVIEW to view the logged file.

6) If you have extra time, you could create an executable that includes the TDMS File Viewer so
that the entire process could be run on a machine without LabVIEW.

Virtual Instrumentation 9
Advanced File I/O and Creating/Distributing an Application | Laboratory 13

Questions
1) What is the benefit of using TDMS?

2) If the executable created in this lab were distributed onto a computer without LabVIEW,
would it run? Why or why not?

3) What is the functionality of the Bundle and Unbundle functions?

4) Is it always necessary to create an installer to distribute an application? Why or why not?

5) Will any version of the LabVIEW Run-Time Engine installed on the target machine allow the
executable to run?

Virtual Instrumentation 10
VIRTUAL INSTRUMENTATION

Lab 13
Advanced File I/O
and Creating/Distrib-
uting an Application
Section 1 – Advanced File I/O and Creating/Distributing
an Application
---------------------------------------------------------------------------  2
Configuring Hardware
---------------------------------------------------------------------------  3
Configuring the File/O
---------------------------------------------------------------------------  3
Creating an Application
---------------------------------------------------------------------------  8
Creating an Installer
---------------------------------------------------------------------------  8
Testing
---------------------------------------------------------------------------  9
Advanced File I/O and Creating/Distributing an Application | Laboratory 13

Section 1
Advanced File I/O and Creating/
Distributing an Application
In this lab, you will expand upon the code from Lab 12 by writing data from more than one source
to a TDMS file and using TDMS Set Properties to distinguish between data sources within the TDMS
file. The code will then be turned into an executable. The executable will then be included in an
installer so that it can be distributed to other machines without LabVIEW or the necessary drivers.

Be building an executable and installer, you can create a package that will allow your temperature
monitoring program to be deployed to computers that don’t have the LabVIEW development
environment installed.

This is usually the final step when building an application that will be used in the field.

Pre-Lab Questions:
1) True / False: Use ASCII if you need to perform random access reads or writes and if numeric
precision and fast File I/O are requirements.

Please provide what file type(s) fits the above criteria more appropriately if the statement is
false.

2) What type of file is a Datalog File and what is it used for?

3) What is TDMS and what are some benefits of this file type?

Virtual Instrumentation 2
Advanced File I/O and Creating/Distributing an Application | Laboratory 13

Lab Procedure
Configuring Hardware
1) Keep the connections that are currently in place.

2) If you have a function generator or a similar device or sensor, connect it to channel AI2 of
the NI ELVIS. We will use this signal to simulate a second source of data to be saved to the
TDMS file.

3) If you don’t have a device that can be used, channel AI2 can remain unconnected. In this
case, data measured on this channel will have a value close to 0V.

Configuring the File/O


1) Copy and paste the code from Lab 12, Data Acquisition with ELVIS - References.vi, into a
new VI.
If you didn’t complete this VI, ask your instructor for access to a VI to use as the starting
point for this lab.

2) Close the code from Lab 12.

3) Add a new button to the Front Panel called “Second Source.”

4) Add a new value change event case for the “Second Source” button.

5) Place the “Second Source” Boolean control inside of the new event case.

6) Within the new event case, add a DAQ Assistant Express VI from the DAQmx palette on the
Mesurement I/O Palette.

7) Select Acquire Signals>>Analog Input>>Voltage. Then choose channel ai2 of the NI ELVIS
and click Finish.

8) Use the settings as they appear and select Ok.

9) Create a Waveform Graph Indicator for the Data output of the DAQmx Express VI.

10) Change the x-scale of the graph to range from 0 to 0.1.

11) Use a “Bundle” to bundle the output of the DAQmx Express VI with a string constant
containing the value “Second Source.”

Virtual Instrumentation 3
Advanced File I/O and Creating/Distributing an Application | Laboratory 13

12) Add a new Enqueue Element to this case.

13) Delete Queue and Error wires that run through the Idle case of the case structure.

14) Wire the Queue and Error wires into the Enqueue Element function.

15) Wire the Queue and Error wires out of the Enqueue Element function to the tunnels at the
right side of the Idle case.

16) You’ll now need to connect the Queue and Error wires through the Timeout, Stop, Panel
Close?, and Center cases of the Event Structure as well.

17) In the Second Source case, in order


to wire the new cluster coming
from the bundle to the Enqueue
Element, the data type of the queue
needs to be modified. In order to
modify the data type of the queue
appropriately, place the waveform
constant that is currently defining
the queue data type inside of a
cluster and add an empty string
constant to the cluster as shown.
Notice that the wire color of the
queue reference reflects the data
type change.

18) Wire the output of the Bundle within the Scope Event Case to the “Element” input of the
Enqueue Element as shown.

Virtual Instrumentation 4
Advanced File I/O and Creating/Distributing an Application | Laboratory 13

19) Move to the analog case and open


the subVI.
20) Bundle the output of the Convert Thermistor Reading function with a string constant
containing the value “Analog.”

21) Notice that you cannot wire the new cluster to the Enqueue Element because the Enqueue
Element is referencing the old queue data type. To resolve this, create a control from the
queue reference wire within the main VI and copy it into the subVI.

22) Delete the control from the main VI.

23) Replace the existing Queue In control in the subVI with the new control. Notice that the data
type of the queue is now correct and the cluster can be wired to the “Element” input of the
Enqueue Element.

24) Create a new indicator for the queue out terminal of the Enqueue Element.

25) Edit the Connector Pane of the subVI so that the new queue control and indicator have
terminals on the subVI.

26) Ensure that your code matches the code shown, and save the subVI.

27) Within the Case structure in the bottom loop, create a new Case Structure around the current
File I/O code.

28) Place an “Unbundle” outside of the new case structure.

29) Wire the Element output terminal of the Dequeue Element to the cluster.

30) Wire the string output of the Unbundle to the Case Selector of the new case structure.

31) Label the “True” case to be “Analog” and the “False” case to be “Second Source”.

Virtual Instrumentation 5
Advanced File I/O and Creating/Distributing an Application | Laboratory 13

32) Wire the waveform output of the Unbundle to the data input of the TDMS Write.

33) Add a new case to the case structure and make it the default case. Leave this case empty, but
wire the TDMS and error wires through the case.
34) Within the Analog Case, add a TDMS Set Properties before the TDMS Write and wire them
together appropriately.

35) Create a constant for the “Property Names” terminal of the TDMS Set Properties.
36) Enter “Test Number” into the first value of the array.

37) Create a string array control on the Front Panel and wire it to the “Property Values” terminal of
the TDMS Set Properties.

38) Make constants for the group name and channel name and give them values of “Producer/
Consumer” and “Analog” respectively.

39) Create the same code in the Second Source case, but replace the “Analog” constants with
“Second Source”.

Virtual Instrumentation 6
Advanced File I/O and Creating/Distributing an Application | Laboratory 13

40) Ensure that your bottom loop code matches the code shown for each respective case.

Virtual Instrumentation 7
Advanced File I/O and Creating/Distributing an Application | Laboratory 13

Creating an Application
1) Save the VI as Data Acquisition with ELVIS – MainVI.vi and add it to a Project.

2) In the project, right-click on Build Specifications and choose New>> Application (EXE).

3) Save the Project as Data Acquisition with ELVIS - Installer, if prompted.

4) In the “Information” category name the application Data Acquisition with ELVIS.exe.

5) Take note of the “Destination Directory” as this is where the application will be saved on your
computer when the application is built.

6) In the “Source Files” category, move the VI for Lab 13 to “Startup VIs.”

7) These are all of the modifications that need to be made for this application build, but take
note of the options found in the other categories.

8) When ready, click Build.

9) Notice that your new application appears under “Build Specifications” in the project.

Creating an Installer
1) Right-click on Build Specifications and choose New>>Installer.

2) Name the installer under the “Product Information” category.

3) Under Source Files, move the Lab 13 executable to the “Destination View.” By default, it will
move to the Program Files folder.

4) In the Additional Installers Category, include the appropriate LabVIEW Run-Time Engine and
the NI-DAQmx Application Development Support.

5) Build the installer.

6) You may be prompted to locate the location that DAQmx is installed from on your computer.

Virtual Instrumentation 8
Advanced File I/O and Creating/Distributing an Application | Laboratory 13

Testing
1) Install the installer on a computer without LabVIEW if possible.

2) Run the executable.

3) Enter the number 1 into the “Property Values” array for “Analog” and for “Second Source” to
record this run as the first test.

4) Make sure to click the Second Source button to log some data.

5) Use the TDMS File Viewer on a computer with LabVIEW to view the logged file.

6) If you have extra time, you could create an executable that includes the TDMS File Viewer so
that the entire process could be run on a machine without LabVIEW.

Virtual Instrumentation 9
Advanced File I/O and Creating/Distributing an Application | Laboratory 13

Questions
1) What is the benefit of using TDMS?

2) If the executable created in this lab were distributed onto a computer without LabVIEW,
would it run? Why or why not?

3) What is the functionality of the Bundle and Unbundle functions?

4) Is it always necessary to create an installer to distribute an application? Why or why not?

5) Will any version of the LabVIEW Run-Time Engine installed on the target machine allow the
executable to run?

Virtual Instrumentation 10
VIRTUAL INSTRUMENTATION

Getting Started
How to Configure
Your System

Working with the NI ELVIS Platform


---------------------------------------------------------------------------  2
Working with the cDAQ Platform
---------------------------------------------------------------------------  2
How to Configure Your System | Getting Started

How to Configure Your System


Working with the NI ELVIS Platform
1) Ensure that the NI ELVISmx driver is installed after installing LabVIEW. The NI ELVISmx
driver is included with the shipment of the NI ELVIS II and II+ and is also available at
ni.com.

2) Connect the power supply to the back of the NI ELVIS unit and to the wall.

3) Connect the USB cable to the back of the NI ELVIS unit and to an available USB port on
your computer.

4) Turn on the switch on the back of the NI ELVIS unit to provide power to the unit, and then
turn on the switch on top of the NI ELVIS unit to provide power to the protoboard. The
switch on top of the NI ELVIS unit allows you to turn off power to the protoboard and switch
protoboards without having to power down the entire unit.

5) The NI ELVIS should automatically


be recognized by the driver and will
appear under Devices and
Interfaces in the Measurement and
Automation Explorer Configuration
Menu. When this is completed, the
device is ready to use.

Working with the cDAQ Platform


1) Plug in the power supply and connect it to the power input on the front of the cDAQ
chassis.

2) Ensure that the c-series module cards are plugged into the cDAQ chassis.

3) The cDAQ should automatically be recognized by the PC and will appear under Devices and
Interfaces in the Measurement and Automation Explorer Configuration Menu. When this is
completed, the device is ready to use.

Virtual Instrumentation 2

You might also like