Lucid LabVIEW Fundamentals II - Exercise Manual
Lucid LabVIEW Fundamentals II - Exercise Manual
Fundamentals II
Exercise Manual
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Our Goal
Our goal is to give you the best possible LabVIEW learning experience. We’ve put our years of
experience as engineers, computer scientists, and instructors together to build this course with that in
mind. We sincerely hope and believe you will find this manual and the other rich content provided to be
valuable resources as you learn LabVIEW in our Fundamentals series.
“Wire the Numeric control Limit to the Multiply function’s top terminal on the Block
Diagram.”
2
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Fundamentals 2 Exercises
If you’ve taken Fundamentals I with us, you’ll notice that exercise instructions became increasingly
composed of general instructions designed to promote thinking and learning. First thinking about the
challenge posed in the exercise and how to solve it in LabVIEW will significantly increase your ability to
program in LabVIEW – we know this from personal experience and have validated this principle in
instruction.
Fundamentals 2 Project
We will be developing a full-scale LabVIEW application over the course of several exercises
incorporating all of our Fundamentals 2 topics. Because each exercise depends on the functionality of
the previous exercise, our instructions are detailed enough to promote thinking and learning while
ensuring that essential application considerations are addressed and that exercises conform to the
design practices needed to develop a robust and reliable application.
Project Integration
We know your time is valuable. The very fact that you are taking a self-paced LabVIEW course indicates
that you very likely have other projects and responsibilities to balance with learning LabVIEW. The
exercises in Fundamentals 2 have been designed to optimize your effective use of time. Each exercise
focuses on the lesson that precedes it and each of these completed exercises is finally integrated into
the Fundamentals 2 project. The most time consuming part is the final integration of the exercises into
the completed project. For that reason, we give you two options:
1. You could choose to do all of the exercises in this manual, gaining a firm knowledge of the
essential LabVIEW concepts in Fundamentals 2 and understanding the myriad considerations
and techniques that come into play developing a full-scale LabVIEW application.
2. You could choose to do all the exercises leading up to the Project Integration exercise and then
let us do the project integration work for you. You will just run and explore the completed
solution, saving time but still gaining a firm knowledge of the essential LabVIEW concepts in
Fundamentals 2.
Manual Errata
If you find errors in this manual – we want to know! Simply login to sixclear.com as you do for this
course and tell us. We are dedicated to updating and evolving this manual and all of our products to
provide the best, most fluid learning experience possible, and we sincerely appreciate your help in that
regard.
Thank You!
Thank you for choosing Sixclear for your LabVIEW learning. We hope you’ll come back to us for future
LabVIEW learning and services – we eat, sleep, and breathe LabVIEW (not really, but we do program
quite a bit) in order to deliver the absolute best possible experience and solution for your LabVIEW
learning and service needs.
3
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Unit 1
Advanced Programming in
LabVIEW
4
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
User Interface
Requirements
1. The application will be event driven
2. The first time the user passes the mouse over “Waveform File Path”, a dialog box will instruct
the user to browse to the appropriate waveform
ii. If the user clicks the “X” in the upper right to exit
3. When the user clicks on “Run Demo”, a dialog box will appear displaying the selected waveform
containing a noisy analog signal in phase with a clean square wave
5
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
4. If the user attempts to exit the application while running, a dialog box will ask the user if they
are sure they would like to exit
Programming Instructions
1. Create a VI named “Main User Interface” in a project named “Events” in the
<root>\Exercises\Exercise - F2.1.2 Events directory
2. Create the user interface shown in Figure 1 consisting of a file path control and two latch-action
Boolean buttons (Ok and Stop)
3. On the Block Diagram, create an event structure in a while loop and create the following events
in separate event cases:
Event Source Event Event Type
“Waveform File Path” control Mouse Enter Notify
This VI Panel Close? Filter
“demo” button Value Change Notify
“stop” button Value Change Notify
5. Test “Main User Interface.vi” to make sure that it runs and stops when the “stop” button is
pressed
a. Pressing “demo” or mousing over “Waveform File Path” should not have any observable
behavior
6
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
6. Create the subVI “Instructions to User.vi” which will instruct the user to browse to a waveform
file
a. Create free label instructions on the Front Panel that say: “Browse to the waveform you
would like to run in the demo”
7. Place an event structure on the block diagram of “Instructions to User.vi” with the following
event cases configured:
Event Source Event Event Type
Pane Mouse Down Notify
This VI Panel Close Notify
Application Timeout Notify
Ordinarily an event structure is placed inside of a while loop so that, after an event occurs, the
while loop will iterate and rearm the event structure to be prepared for the next event, as we see
on the Block Diagram of “Main User Interface.vi”. However, “Instructions to User.vi” is only
intended to handle one event before it closes, for this reason we will not put a while loop around
the event structure.
“Instructions to User.vi” should close if the user clicks anywhere on the front panel or the “X” in
the upper right to exit. For this reason, we need a separate event to handle each situation. If we
did not have the Panel Close event, then the calling vi, “Main User Interface.vi” would hang when
the user clicked the “X” in the upper right of “Instructions to User.vi” because “Instructions to
User.vi” would still be running and waiting for one of the registered events to end it.
9. Set “Instructions to User.vi” to have a dialog box behavior and to open in the center of the
screen when called
7
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Do not run “Main User Interface.vi” while the Front Panel to “Instructions to User.vi” is open,
make sure the Front Panel is closed. Otherwise, “Instructions to User.vi” will not close its own
Front Panel when called by “Main User Interface.vi” and LabVIEW will hang.
If we were to run “Main User Interface.vi” now, then “Instructions to User.vi” would pop up each
time the user moused over “Waveform File Path”, this could get very annoying and could prevent
the user from selecting the file. For this reason, we will program “Instructions to User.vi” to only
execute the first time it’s called
8
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
11. Using the LabVIEW function: “First Call”, program “Instructions to User.vi” to run only the first
time the user mouses over “Waveform File Path”
12. Create the subVI, “Demo.vi”, which will display the signals to the user in a dialog box
a. Give “Demo.vi” a meaningful icon (use the appropriate icon in the …\Exercises\icons
folder if you wish)
13. From “Demo.vi”, call the file, “waveform to read”, in the <root>\Exercises\Exercise - F2.1.2
Events directory using the Read Waveform From File VI and display the retrieved waveform on a
9
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
15. Put the instruction “Click Anywhere to Finish Demo” on the Front Panel of “Demo.vi”
16. Program “Demo.vi” to allow a calling VI to pass the path to the selected waveform that Read
Waveform From File will read
17. Set “Demo.vi” to have a dialog box behavior and to open in the center of the screen when called
18. Program “Main User Interface.vi” to call “Demo.vi” whenever the “Run Demo” button is clicked
and pass the path from “Waveform File Path” to “Demo.vi”
Do not run “Main User Interface.vi” while the Front Panel to “Demo.vi” is open, make sure the
Front Panel is closed. Otherwise, “Demo.vi” will not close its own Front Panel when called by
“Main User Interface.vi” and LabVIEW will hang.
19. When the user attempts to exit “Main User Interface.vi” while the VI is running, pop up a dialog
box that asks the user if they are sure they want to exit
10
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
a. If the user decides they do not want to exit then discard the action
If you would like, examine “write waveform.vi” to understand how “waveform to read” was
created. Experiment with changing the waveform being written to the file.
END OF EXERCISE
11
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Project Diagram
12
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
User Interface
Requirements
1. The application will be event driven in a state machine architecture
2. The application will simulate receiving and processing data from the DUT
a. Simulated data from the DUT will be composed of two noisy sine waves of different
amplitude and frequency simulating two channels being read from the DUT
c. Both time and frequency domain will be displayed on waveform graphs contained in
separate tabs on the Front Panel
3. A switch action Boolean will connect and disconnect the circuit to isolation
a. When isolation is connected, simulated data on one channel of the DUT will have an
amplitude of 1000 to simulate a greater amount of power coming from the power
supply, when isolation is disconnected, simulated data on the same channel will have an
amplitude of 20
4. Latch action Booleans will turn the power supply on and off and stop the application
13
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Programming Instructions
1. Create a VI named “Device Test Main” in a project named “Device Test” in the
<root>\Exercises\Device Test directory
a. A switch action Boolean with the “Isolate” label and latch action Booleans for the other
three buttons with the following labels (Note: the Boolean text is different than the
label, the label is how the terminal will be labeled on the Block Diagram):
i. Power ON
iii. Stop
i. Name the graph in the first tab “Time Domain” and the graph in the second tab
“Power Spectrum”
iii. Turn off autoscaling on the X axis on the graph in the second tab
b. Create a Type Defined enum constant called “States” with two items: “Idle” and
“Acquire Data”
c. Wire the “States.ctl” constant to the input of the left shift register and wire the output
of the left shift register to the case selector of the state machine
5. Configure three Value Change cases in the event structure for the following booleans:
a. Isolate
b. Power ON
c. Stop
14
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
6. Configure the state machine to stop when the stop button is pressed
7. Configure the state machine to advance to the “Acquire Data” state when the “Power ON”
Boolean is pressed
8. Configure the state machine to return to the “Idle” state when the Isolate button is pressed
One of the functional requirements for this exercise is that we produce a simulated waveform
with an amplitude of either 1000 or 20, depending on whether or not we have added isolation to
the circuit. Since we are planning on producing the waveform in the “Acquire Data” state, we
need a way for that state to “remember” if we’ve added isolation in a previous state (the “Idle”
state). We will do this by passing the isolation value through a shift register.
15
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
9. Write the value of the “Isolate” button to a shift register when “Isolate” is clicked
10. If you would like, you can test the design at this point. To do so, ensure the VI can run by
supplying inputs to all hollow tunnels in the “Acquire Data” state (wire the isolate wire
across the case, use the “States.ctl” constant to advance to the “Idle” state from the
“Acquire Data” state, and wire a false constant to the stop tunnel). Run the VI and
observe the expected behavior when you:
b. click on the isolate button (Hint: use a probe to view the value of the shift
register just before it enters or exits the shift register)
c. click the “Power ON” Boolean (Hint: We haven’t configured anything in the
“Acquire Data” state, so clicking “Power ON” should take us to that state and
then back to the idle state. Use the One Button Dialog function in the “Acquire
Data” state to indicate to the user that the state has been successfully reached)
11. Nothing should happen when you click the “Power OFF” Boolean
12. When you have finished verifying that the design works, remove everything from the
“Acquire Data” state, making the tunnels hollow again
13. In the “Acquire Data” state, create the simulated waveform by using two instances of the
LabVIEW VI: Sine Waveform
a. The first instance will have a frequency of 10Hz and the amplitude will be 1000 if
isolation has previously been added to the circuit, and 20 if it has not
16
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
14. Add noise to each waveform with the LabVIEW VI: Gaussian White Noise Waveform (default
values for this VI will be used)
The Add function is polymorphic, if we wire waveforms to the inputs, the function automatically
adds the waveforms together. This is an excellent way to add noise to a waveform.
15. Display the waveforms with noise added to each as separate plots on the Waveform Graph in
the first tab of the Tab Control (Hint: use a build array function)
16. Perform a Power Spectrum operation on both waveforms with the Spectral Measurements
Express VI
a. Convert the array of waveforms to the Dynamic Data type before inputting to the
Spectral Measurements Express VI
17
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
17. Display the Power Spectrum output on the Waveform Graph in the second tab of the Tab
Control
The Signals terminal input of the Spectral Measurements Express VI will accept the 1D array of
waveforms without being transferred to the Dynamic Data type first. If we don’t transfer to the
Dynamic Data type, we notice that the Waveform Graph terminal will turn pink, indicating that
the graph is displaying a cluster. This cluster contains power spectrum information. Displaying the
power spectrum in this manner would normally be fine. However, we will later be wiring the
Power Spectrum output to a TDMS file which cannot accept the power spectrum cluster.
Therefore, for our purposes we will change the 1D array of waveforms to the Dynamic Data type.
18. Use the error cluster to stop the application if an error occurs
19. Use the “Power OFF” Boolean to determine the next state
a. If the Boolean is pressed, move back to the idle state, if it not pressed, stay in the Turn
Power ON state
The Isolate button may still be depressed when the user stops the application, for this reason we
will want to reset the button when the application begins
20. Create a local variable of the “Isolate” button and pass a false constant to it
18
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
a. Place the local variable and constant inside a sequence frame that executes before the
state machine begins
i. Two displayed waveforms should show in both graphs, one with an amplitude of
1000 and a frequency of 10Hz, the other with an amplitude of 5 and frequency
of 100Hz
b. Press “Power OFF”, press “Isolate” again, then press “Power ON”
i. The graphs should now display the same two waveforms, except that the 10Hz
waveform will have an amplitude of 20
19
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Pressing the Booleans out of order can cause LabVIEW to hang, for instance if the power is on and
I hit the stop button. Why? Because the stop event is registered with LabVIEW and front panel
locking has been turned on. The VI is thus waiting to return to the event structure to handle the
stop case before it handles any other button click. However, if the power is on, you are in the
“Acquire Data” state, so LabVIEW will not be able to return to the “Idle” state and handle the
event. You can turn off front panel locking, which will allow the user to click on “Power OFF”,
returning the application to the “Idle” state. At which point LabVIEW will execute the “stop” event
and end the application. This may seem to solve the problem but raises a usability concern: The
user will not know that “Power OFF” will return the application to the correct state to handle the
event and will perceive that the VI is broken. We will see in the next exercise that we can disable
and grey out the buttons that the user should not push, improving usability.
END OF EXERCISE
20
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
User Interface
Requirements
1. When the application begins, the “Power OFF” button should be disabled and grayed
2. When the user clicks on the “Power ON” button, all other buttons except “Power OFF” should
be disabled and grayed
Programming Instructions
1. First, we need to create two additional states to handle disabling and enabling. Add the items:
“Turn Power On” and “Turn Power Off” to “States.ctl”
21
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
2. Program the “Idle” case so that the state machine moves to the “Turn Power On” state when
the “Power ON” button is pressed
3. Program the “Acquire Data” case so that the state machine moves to the “Turn Power Off” state
when the “Power OFF” button is pressed
5. Create a property node from the “Isolate” Boolean to access the Disabled property
6. Program the “Turn Power On” case to disable and gray the “Isolate”, “Power ON”, and “stop”
button and enable the “Power OFF” button
Use the Context Help window to find what needs to be wired to the Disabled property node to
disable and gray the buttons.
22
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
7. Program the “Turn Power On” case to advance to the “Acquire Data” state when it completes
Right-clicking on the border of the event case and selecting “Duplicate Case” will copy the current
case and assign it to the next item in “States.ctl” that does not have a case assigned.
9. Program the property nodes in the “Turn Power Off” state to disable and gray the “Power OFF”
button and enable the “Isolate”, “Power ON” and “stop” buttons
10. Program the “Turn Power OFF” case to advance to the “Idle” state when it completes
We now need to decide how to initialize the disabled property of the buttons in the application. If
we assume that the user will always end the application by pressing the stop button, then we
would not need to do any special initialization because when the application started again, the
“Power OFF” button would be appropriately disabled from the previous run. However, if the
previous user aborted execution when the power was on, then we would have the wrong buttons
disabled when we started the application again. For this reason, it is always good programming
practice to initialize an application at the beginning to a known state. We already did this in the
last exercise when we used the local variable to set “Isolate” to false at the beginning of the
application.
23
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
11. Use a copy of the property nodes to enable the “Isolate”, “Power ON”, and “stop” buttons while
disabling the “Power OFF” button at the beginning of the application
If you highlight, and then Ctrl+drag the property nodes, you will have the correct property nodes.
If you use Ctrl+C and then Ctrl+V you will see the pasted property node is now a generic property
node and is no longer implicitly linked to the control. We will discuss implicit linking later.
The method we used certainly works but it can be tedious to create and copy property nodes on
every control we would like to enable/disable across different states. We will learn a more
efficient way of programming this when we discuss implicit linking and references later.
END OF EXERCISE
24
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
User Interface
Requirements
1. An image of the waveform graph plot currently being viewed on the Front Panel will be written
as an image file to disk when the user clicks on the “Snapshot” button
Programming Instructions
1. Add the “Snapshot” Boolean and “Image path” file path control as shown in the user interface
2. We will be adding the additional functionality to the “Acquire Data” state, where we will be
polling the “Snapshot” button to see if it has been pressed
25
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
3. We want to write the image to file of the waveform graph being displayed, either the Time
Domain or the Power Spectrum
a. Nested within the case structure you just made, create a case structure with the tab
control determining the case to execute
4. Create an invoke node for each waveform graph to operate on the Export Image method and
place them in the appropriate case
a. Choose bitmap as the file type, file as the target, use “Image path” to control the path
input, don’t display the graph, and always overwrite
5. Test the Requirements, make sure to change the name of the file being written when you
change the graph being displayed
26
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
It would make sense to disable the “Snapshot” button until the power to the circuit has been
turned on, since that is the only time we will have a display in the graph and polling the
“Snapshot” button. We could use another property node on the “Snapshot” button to do this and
place the property node in the appropriate cases, but we will see in the next exercise an easier
way to enable and disable multiple controls.
END OF EXERCISE
27
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
User Interface
28
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Requirements
1. The functionality of the application will not change, we will simply be changing the programming
method to address the same requirements
2. Incorporate a subVI that will enable and disable controls and expand the maintainability of the
application
Programming Instructions
1. Use “Disable.vi” that was created in Demo - F2.1.5 SubVI Property Nodes, copy it to the
<root>\Exercises\Device Test directory
2. Give the VI a meaningful icon (use the appropriate icon in the …\Exercises\icons folder if you
wish)
a. Create a Front Panel enum control with the items Enable and Disable
29
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
b. Program the enum to command a case structure with two cases: one to disable and one
to enable the control references in the array
Many times in a subVI we will use the error cluster wired to a case structure to determine if
the VI should execute its normal functionality or just pass an error along if an error occurs in a
previously executed VI.
4. On the Front Panel of “Disable.vi” place an error in and error out cluster
a. Wire the error in cluster to the error out cluster on the Block Diagram
30
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
i. This will allow the VI that calls “Disable.vi” to control the programming flow
5. Make the appropriate Connector Pane assignments to the Front Panel objects
6. On “Device Test Main.vi” we need to create the array of references to pass to “Disable.vi”
b. Use the Build Array function to group the references into sets that will be disabled and
enabled together
Use two Build Array functions, one will build an array of references of the “Isolate”, “Power ON”,
and “stop” buttons, the other will build an array of the “Power OFF” and “Snapshot” buttons.
You should have two instances of “Disable.vi” in each of the three places where the property
nodes once executed: the “Turn Power On” state,
the “Turn Power Off” state, and before the state machine executes. One instance will enable
controls and the other instance will disable controls.
8. Test the application to ensure that execution behaves as it did with the property nodes
END OF EXERCISE
31
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
User Interface
Requirements
1. When the subVI is called, it will show its Front Panel in the center of the screen
2. The Front Panel should be 15% transparent until the user clicks on it, at which point it will turn
opaque
3. When the subVI finishes executing, the Front Panel will close
Programming Instructions
1. Create a new VI named “Transparent Sub.vi” in the <root>\Exercises\ Exercise - F2.1.5 VI Server
Classes directory
32
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
There are several requirements that can be met by editing the VI properties: opening the Front
Panel when the VI is called, closing the Front Panel when the VI finishes execution, centering the
Front Panel on the screen, and changing the transparency of the VI. We can change all of these
properties by going to File>>VI Properties during Edit Mode. We can also use property nodes to
edit these properties during Run Mode. So which should we use? If we plan on changing a
property while the VI is running, then we should use property nodes. If not, we should set the
properties with the VI Properties menu. The same principle applies to Front Panel objects. Of all
the properties we need to edit, only our requirement to set the transparency of the Front Panel
will be edited during runtime (when the user clicks on the Front Panel), so we will use a property
node to edit this property.
3. On the Block Diagram, place a property node exposing the FP: RunTransparently property on the
VI class
4. Using events, program the VI to be fully opaque when the user clicks on the Front Panel
5. Using events, program the VI to stop if the user clicks the stop button or exits the VI
7. Program Transparent Sub.vi to open its Front Panel in the center of the screen when it is called
8. Program Transparent Sub.vi to open its Front Panel when called and close it when it finishes
executing
33
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
You could use the dialog box setting in the VI Properties Window Appearance menu, but this
removes the abort button. During development, it’s generally a good idea to keep the abort
button available in case a VI goes into an infinite loop. You would usually remove these abort
buttons when the finished application is ready to be used in production and/or made into an
executable.
9. Now we will create a VI to call Transparent Sub.vi to mimic the behavior of the top level VI in
the application
10. Place an Ok button named Launch and a Stop Button on the Front Panel of Calling.vi
11. On the Block Diagram of Calling.vi create an event structure that executes on the value change
of Launch
12. Pass an empty error cluster constant out of the event structure and to the input of Transparent
Sub.vi
13. Pass the error cluster out of Transparent Sub.vi to a tunnel on a While Loop
a. Note: you will not use the contents of the error cluster in the While Loop, it is just used
to control program flow
14. Program the stop Boolean terminal to terminate the While Loop when it is pressed
Make sure that Transparent Sub.vi is closed before you run Calling.vi
15. Run Calling.vi and ensure that it launches Transparent Sub.vi as a dialog box and it behaves
according the Requirements
END OF EXERCISE
34
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
2. Take the # Records to Write input from the operator. This is the number that would correspond
to the number of devices or tests in the batch.
4. Indicates whether the run is a calibration run (every first run is a calibration run)
Steps to Run
1. Open Binary File APIs Writer.vi in Binary File APIs.lvproj
2. Select the path where you would like to write the file
3. Select the appropriate tabs to create a 1D or 2D array of doubles or I32s, a Datalog file, or a
TDMS file
a. When creating a 1D array, you can select the number of elements to write
b. When creating a 2D array, you can select the size of rows and columns and whether to
allow LabVIEW to create the binary header
c. In the Various Datatypes tab, you can create a Datalog or TDMS file that logs data to file
from the simulated application
5. Select the path where you would like to read the file and read the file(s) you created
6. After creating a TDMS file, view the file with the TDMS File Viewer.vi
35
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Points to Consider
1. Note that, for 2D arrays, we can select whether LabVIEW will create our file header or we will
manually create it. Explore how this is done.
2. We have only done random access reads for 1D arrays, Datalog and TDMS files. We can actually
think of the records and channel groups in Datalog and TDMS files respectively as a 1D array of
data. Random access is possible with multi-dimensional arrays (such as 2D arrays) but we would
have to manually build the array after reading. This is more complicated, but can be done.
3. Experiment with changing the byte order (big and little endian) when writing and reading binary
files. Make them different and see what happens.
END OF EXERCISE
36
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
User Interface
37
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Requirements
1. When the VI is run, the incoming data will be written to a TDMS file with the following structure:
1. Ch0
2. Ch1
1. Ch0
2. Ch1
a. NI_ExpXDimension
38
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
b. wf_xname
c. wf_xunit_string
Programming Instructions
1. Create Log Data.vi and add it to Device Test.lvproj in the <root>\Exercises\Device Path directory
a. Notice that, when Log Data.vi is hovered over, Context Help shows that the Power
Spectrum input expects the Dynamic Data type
4. Give the VI a meaningful icon (use the appropriate icon in the …\Exercises\icons folder if you
wish)
5. On the Block Diagram, use the TDMS file API to create the file structure described in the
Requirements
• NI_ExpXDimension
• wf_xname
39
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
• wf_xunit_string
c. Use the TDMS Set Properties function to write the Isolated property at the file level
using the Isolated Boolean input
d. Use TDMS Write twice, once to write the Time Domain data and once for the Power
Spectrum data
6. Test the VI by placing it in the Block Diagram of Device Test Main.vi in the “Acquire Data” state
b. If you do not wire a path to the Log Data Path input, make sure that you have saved a
default value on the Front Panel Log Data Path control of Log Data.vi
c. Run the application, making sure to turn on and off the power before ending so that the
“Acquire Data” state runs
7. Create a new VI named TDMS File Viewer.vi in the …\Device Test folder
8. On the Block Diagram of TDMS File Viewer.vi place the LabVIEW VI, TDMS File Viewer
40
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
9. Run TDMS File Viewer.vi, browse to the TDMS file you created and view it
a. Notice that some of the labels on axes do not show up correctly when viewing the
graph, especially the Power Spectrum graph
b. We will go back and add the necessary properties so that these show up correctly
10. On Log Data.vi, write the following properties and values at the channel level:
a. Use TDMS Set Properties after writing to each channel and pass the group name value
from TDMS Write to TDMS Set Properties
Since we are setting three properties for each channel (Ch0 and Ch1) in the channel group, we will
use For Loops with an auto indexed input coming from the 1D array of two string constants (Ch0
and Ch1) that we wired to the Channel Names in input of TDMS Write. The scalar wire coming
into the For Loop will then be passed to the Channel Name input of TDMS Set Properties. See the
discussion in the video capture of the solution for a complete explanation.
11. Save Log Data.vi, run Device Test Main.vi again, and then view the resulting TDMS file with
TDMS File Viewer.vi
12. Using TDMS functions, create a VI named Read TDMS File.vi in the …\Device Test directory to
read the values out of the TDMS file
a. Use a TDMS Open, TDMS Get Properties (to read the Isolated property), two instances
of TDMS Read (one for each channel group), and TDMS Close
41
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
We will not need to read out the channel level properties that we just wrote since they are only
used by graphs to properly label display data.
13. Use Read TDMS File.vi to read the TDMS file that we created earlier
a. We will be creating a separate “Log Data” state in the final application in a future
exercise
END OF EXERCISE
42
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
User Interface
43
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Requirements
1. Write Config File.vi will write a Boolean to a configuration file indicating whether isolation has
been added to the circuit in the Device Test application
In the final application, we will be writing and reading more configuration information with the
same VIs we are creating now
2. Read Config File.vi will show its Front Panel in the center of the screen when called
a. It will show as 15% transparent until it is clicked on by the user, at which point it will
turn opaque
3. If the user clicks Yes, configuration data will be loaded and output from the subVI to the
application
a. A Boolean LED will indicate whether isolation has been added to the circuit in the
configuration file
4. If the user clicks No, the VI will end and not load data
44
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
5. Read Config File.vi will also end if the user closes the panel
Programming Instructions
1. Create a new VI named Write Config File.vi in the …\Device Test directory and add it to Device
Test.lvproj
2. On the Front Panel, place a File Path Control named File Name, a Boolean toggle switch named
Isolate, and error in and error clusters
3. Give the VI a meaningful icon (use the appropriate icon in the …\Exercises\icons folder if you
wish)
4. On the Block Diagram, use the LabVIEW VIs: Open Config Data, Write Key, and Close Config Data
to write the configuration
b. Set “Circuit Setting” as the Section Name input to Write Key, and “Isolation Added?” as
the Key input
5. Save the VI, turn the Isolate Boolean to true, and run the VI, creating a configuration file named
“config file” in the …\Device Test directory
6. Copy Transparent Sub.vi from the <root>\Exercises\ Exercise - F2.1.2 VI Server Classes directory
to the …\Device Test directory and rename the VI: Read Config File.vi
7. Change the Front Panel to the User Interface shown above, renaming the stop button to No
a. Note that the Front Panel has been sized so that the error in and error out clusters are
out of view
45
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Since Read Config File.vi will be used as a dialog box, we can anticipate that the user will be
supplying the path and interfacing with the buttons directly on the Front Panel of Read Config
File.vi and not passing any inputs to the VI. For this reason, we will not need to assign the file path
control or the Boolean buttons to the connector pane of Read Config File.vi.
8. Give Read Config File.vi a meaningful icon (use the appropriate icon in the …\Exercises\icons
folder if you wish)
9. On the Block Diagram of Read Config File.vi, add an event case for a value change on the Yes
button
10. Add the LabVIEW VIs: Open Config Data, Read Key, and Close Config Data to the event case
b. Program Read Key to get the “Isolation Added?” key that we wrote to the “Circuit
Setting” section and wire the output to the Isolation Added? Front Panel Boolean
11. Program the Yes value change case to end the VI when it completes
a. Press Yes to read the configuration file and check that a true “Isolation Added?” value is
read from “config file”
We will be integrating Write Config File.vi and Read Config File.vi to the final Device Test
application in a future exercise.
END OF EXERCISE
46
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Unit 2
47
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
User Interface
48
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Requirements
1. Configure two simulated DAQ devices
Programming Instructions
1. Open MAX
If you have your own National Instruments Multifunction IO device (E Series or M Series) you can
follow along with your own device. You can even use it for our upcoming exercises instead of
“MSeriesDev”, just right click on your device and choose Rename, then use that name for all
future exercises that reference “MSeriesDev”.
a. Attributes
b. Device Routes
c. Calibration
49
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
a. Properties show connected RTSI configuration, terminal blocks, and potential power-up
states of the digital ports
a. Notice that it does not have tabs for device routing or properties
If you’re ever concerned if your device is functioning or configured properly, you can configure a
simulated device of the same model and see if selection and behavior is significantly different.
50
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
7. Go back to the M Series device and continue to explore the menus on the top bar
a. Self Test ensures that system resources are allocated and available
i. Analog Input: choose any analog input channel, the signal from the device is a
simulated slow sine wave
51
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
iii. Digital IO: read to and write from the digital ports/line
iv. Counter: not terribly exciting for simulated devices, but for a real device we can
generate a pulse train or count the number of digital pulses on a given line
8. Click on Device Pinout to get the pinout for the selected device
9. Close MAX
END OF EXERCISE
52
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
User Interface
53
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
54
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Requirements
1. Acquire and Analyze.vi will take a continuous measurement at 1000 samples per second from
an analog input channel of the National Instruments DAQ device we have configured in MAX
a. A power spectrum will be taken of the waveform data obtained from the acquisition
b. Both time and frequency domain data will be displayed on Front Panel graphs
2. Isolate and Power.vi will set the state of three digital lines on the DAQ Device
a. This will meet the Project Requirements for the Device Test application:
• The application will control three digital lines in a National Instruments DAQ device:
o Two digital lines are required to turn relays on and off that connect and disconnect the
circuit from isolation. These digital lines will always change state together, they will
never be different values from each other. The relays connect to isolation and stay
connected when the digital lines are high. The relays disconnect from isolation and stay
disconnected when the digital lines are low.
o A third digital line sends a digital trigger to turn on and off the standalone power supply
that powers the circuit. The power supply turns on and stays on when the digital line is
high, it turns off and stays off when the digital line is low. This is known as Pause
Triggering.
3. Digital States.vi will keep the state of the three digital lines written to it from Isolate and
Power.vi
Programming Instructions
1. Create a new VI named Acquire and Analyze.vi in the …\Device Test directory
2. Open Device Test Main.vi and copy the tab control with both graphs onto the Front Panel of
Acquire and Analyze.vi
3. On the Block Diagram of Acquire and Analyze.vi, place the following DAQmx VIs programmed in
the following manner:
a. DAQmx Create Virtual Channel with the polymorphic VI selector set to AI Voltage
ii. On the Digital Lines Front Panel control, choose three lines to write to, for
example: “MSeriesDev/port0/line0:2”, or “MSeriesDev/port0/line0,2,4”
b. DAQmx Timing with the polymorphic VI selector set to Sample Clock, rate set to 1000,
and sample mode set to Continuous Samples
55
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
d. DAQmx Read with the polymorphic VI selector set to Analog Waveform 1Chan N
Samples, displaying its data on the Time Domain graph
If this VI were to be used alone, we would not need to use both the DAQmx Stop Task and DAQmx
Clear Task. However, we will be breaking this Block Diagram up and placing it in different states in
the Device Test application. Using DAQmx Stop Task allows us to stop acquisition on the current
task without erasing the task. It is generally used when we will be starting, stopping, and
restarting an acquisition without changing configuration as we will be doing in the Device Test
application.
4. Add a Spectral Measurements Express VI to accept the waveform data from the DAQmx Read
and output a power spectrum to the Power Spectrum graph
b. Configure the Spectral Measurements Express VI in the same way it has been configured
on the Block Diagram of Device Test Main.vi
5. Place a While Loop around both the DAQmx Read and Spectral Measurement Express VI
56
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
6. Save and run the VI and view the data on both graphs. If you are referencing a simulated DAQ
device, the DAQmx driver will simulate acquisition of a 1HZ sine wave with the max and min
voltage matching those in the task (in our case, we used the default values from DAQmx Create
Channel which are 5 and -5, respectively). The full period of the sine wave is represented over
10,000 samples.
7. In preparation to be used in the Device Test application to test a floating signal source, go back
and change terminal configuration to RSE
8. Create a new VI named Isolate and Power.vi in the …\Device Test directory
9. On the Front Panel, create a 1D array of Boolean Push Buttons and a 1D array of Boolean LEDs
as show in the User Interface above
10. On the Block Diagram, place the following DAQmx VIs programmed in the following manner:
a. DAQmx Create Physical Channel with the polymorphic VI selector set to Digital Output
b. DAQmx Write with the polymorphic VI selector set to Digital 1D Bool 1Chan 1Samp
57
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
11. Save the VI and choose some Booleans in the array to be true and others false (remember the
requirement that the first two lines will always be in the same state as each other)
a. Run the VI
If we had the hardware present, we could independently verify the state of the digital lines we set
with LEDs or by probing with a DMM. However, since the device is simulated, there is no way to
independently confirm that the lines have been set high. Additionally, in our full Device Test
application, we need a way for the application to “remember” what the previous state of the
digital lines has been set to since the DAQmx driver does not retain that information. Therefore,
we will implement a method with a functional global variable that keeps the states of the digital
lines to be accessed and can display them.
12. Create a new VI named Digital States.vi in the …\Device Test directory
13. Give the VI a meaningful icon (use the appropriate icon in the …\Exercises\icons folder if you
wish)
14. Create the Front Panel for Digital States.vi shown above
a. Create an enum Type Def named Digital Control.ctl with the following items
i. Set
ii. Get
15. On the Block Diagram of Digital States.vi, create the necessary structure for a functional global
variable:
58
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
16. In the “Set” state, wire the incoming data in array to the shift register
17. In the “Get” state, wire the left shift register through the case to the right shift register
18. In the “Turn Power On” state, write a true value to the third Boolean in the array (this will be the
digital line that triggers the power supply to turn on)
19. In the “Turn Power Off” state, write a false value to the third Boolean in the array
20. Data out should be wired to from the right shift register or directly before it (between the case
structure and while loop)
59
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
21. Since we want to be able to set the state of the digital lines even in the case of an error, we will
simply wire the error clusters together and not have the error cluster control an error and no
error case
22. Place Digital States.vi on the Block Diagram of Isolate and Power.vi
23. Save and run Isolate and Power.vi, changing the states of the first two Booleans in data in to
true
25. Run Isolate and Power.vi again, notice that the third Boolean in data out has changed to true
while maintaining the value of the first two Booleans from the last time the VI was run
60
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
26. Experiment with the “Set”, “Get”, “Turn Power On”, and “Turn Power Off” states
a. Note that data in will only be used in the “Set” and “Get” state, even when the wire is
connected to Digital States.vi
When we use this VI in the final Device Test application, we will always use Digital States.vi
together with the DAQmx Write when we’re writing to digital lines. We will be using an array of
Boolean constants instead of controls to input data in to Digital States.vi. If we’re disciplined with
always passing data out from Digital States.vi to the data input of DAQmx Write, then we will
always know the current state of the digital lines.
END OF EXERCISE
61
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
User Interface
The desired front panel is shown below
Requirements
This program should
1. Allow a user to input a known instrument command
2. Write that command to the instrument
3. Read the response from the instrument and display it in plain text
4. Stop the VI and close references
Programming Instructions
On the Front Panel:
1. Open a new VI and save it to the Exercises folder with the name Processing Spreadsheet Data.vi
2. Build the Front Panel to match that shown in the User Interface section
a. write string is a string control
b. read buffer is a string indicator (right click on it to show the vertical scrollbar visible
item)
c. Write, Read, and Stop are Buttons
62
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
3. Build the classic Simple Event Handler structure using a While Loop and Event Structure
4. Initialize the structure with the VISA Open Simulation and VISA Configure Serial Port Simulation
VIs as shown below
a. Make sure to pull the simulation VIs from the …Exercises folder
5. Build the Stop, Write, and Read cases as shown below, using the techniques we discussed for
creating event cases. Screenshots are shown below.
63
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
a. Read case:
b. Write case:
c. Stop case:
64
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
7. Run the VI and try the commands in the following order noting the stated observations:
a. Identify the instrument:
i. Write: *IDN?
ii. Read: observe that the name of the instrument is returned.
b. Test the instrument:
iii. Write: *TST?
iv. Read: observe that the self test returns a positive result.
c. Reset the instrument:
v. Write: *RST
vi. Read: observe that nothing is returned – we have reset the instrument, but
have not requested any data back. Also notice this command does not have the
‘?’ in it.
d. Get data from the instrument:
vii. Write: SOUR:FUNC SIN
- this requests the instrument to produce a sine signal
viii. Write: FUNC?
- this requests the instrument send us the name of the set signal; think of this
step as a confirmation.
ix. Read: observe that it returns the name of the signal: SINE
x. Write: SENS:DATA?
- this requests the instrument send us data for the SINE signal
xi. Read: observe that we receive a comma-delimited list of sinusoidal data
e. Repeat step d. above for the other two signal types – TRI and SQR.
f. Try sending an invalid command to the instrument (a misspelled command for instance).
What happens? This is the typical response of an instrument when it receives an invalid
command.
END OF EXERCISE
65
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
66
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
User Interface
Requirements
1. Acquire 1000 samples from an Agilent 34401 DMM and display the data with the data acquired
from the National Instruments DAQ device on the same Time Domain plot
2. Take a power spectrum of the DMM data and display it with the power spectrum from the
National Instruments DAQ device data on the same Power Spectrum plot
67
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Programming Steps
1. First, we will understand what the original Agilent 34401 VIs are doing by viewing the Agilent
34401 VI Tree
i. Initialize
iii. Data
v. Close
a. Note that we are using VISA functions to communicate with the DMM
i. If we go deep enough all of these Agilent Instrument Driver VIs, we will see the
same type of communication taking place with VISA functions
We will keep our communication simple and use four of the VIs in the tree to program our
simulated Agilent 34401 DMM:
a. Initialize
b. Configure Measurement
d. Close
3. Simulation VIs of these four VIs (as well as three more VIs discussed below) are found in the
…\Exercises\Exercise F2.2.2 Instrument Communication directory
In Agilent Read (Multiple Points) SIM, we are outputting a waveform data type instead of the
array of doubles that the real VI would output. An Agilent 34401 DMM could not actually output a
waveform data type because that would assume that there is a consistent timing between
samples, which requires hardware timing. An Agilent 34401 is a low end DMM which does not
have a hardware clock to take consistent timing. If we search down deep enough into the subVIs
of Read (Multiple Points) we see that the acquisition is all software timed, meaning that the
samples would be at inconsistent timing. However, many DMMs do have a hardware clock to take
68
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
consistent timing and would be able to output a waveform data type. Therefore for our purposes,
we will act as if the Agilent 34401 DMM has a hardware clock and can output a waveform data
type. This is more consistent with the types of DMMs used in most industrial applications. Any
DMM with a hardware clock would likely require another VI to configure the hardware timing,
much like DAQmx Timing, another VI to start the acquisition, much like DAQmx Start Task, and
another VI to stop the acquisition, much like DAQmx Stop Task. For this reason, we will also be
configuring Agilent Configure Timing SIM, Agilent Start SIM, and Agilent Stop SIM with our other
Agilent SIM VIs.
4. Open Acquire and Analyze.vi in the …\Device Test directory and add the seven simulation VIs in
the …\Device Test directory to the Block Diagram of Acquire and Analyze.vi above the chain of
DAQmx VIs
a. Add the VIs to initialize, configure, and start acquisition to the left of the While Loop
i. Create a control from the Visa Resource Name input of Agilent Initialize SIM
iii. Wire the constants used by DAQmx Timing to the appropriate terminal on
Agilent Timing Configuration
b. Place Agilent Read (Multiple Points) SIM inside the While Loop and program it to read
1000 samples
c. Place the stop and close VIs to the right of the While Loop
5. Inside the While Loop, combine the waveform data coming from DAQmx Read and Agilent Read
(Multiple Points) SIM into a 1D array of waveforms and wire this to the Time Domain graph and
to the input of the Spectral Measurements Express VI
a. Change the data type that the Convert to Dyanamic Data is expecting from a waveform
to a 1D array of waveforms
69
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
7. Save and run the VI, check that it meets the Requirements
END OF EXERCISE
70
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
3. Acquires data from two channels of the DUT and performs a power spectrum on the data
Reminder:: This exercise is by far the largest in Fundamentals II.. If you have been following the demos
and developing the exercises leading up to this point then you have a firm understanding of o the
concepts in Fundamentals II.. This exercise teaches you many of the consideration and techniques useful
in large project integration. If you feel that this may not be as valuable to you, simply run and view the
completed application in the …\Solutions
Solutions directory.
Project Diagram
71
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
User Interface
72
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
73
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Project Requirements
In previous exercises (Type Defs, Property Nodes, Invoke Nodes, and References), we made
scaled-down versions of the full application. We will now view and consider the complete project
requirements.
Acquisition Functionality
1. The application will be event driven in a state machine architecture
2. The application will simulate receiving and processing data from the DUT in the circuit displayed
on the Front Panel of the top level VI
a. A simulated Agilent DMM will read data from Channel 0 of the DUT
74
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
b. A simulated National Instruments M-Series DAQ device will read data from Channel 1 of
the DUT
c. A power spectrum will be calculated on the waveforms
d. Both time and frequency domain will be displayed on waveform graphs contained in
separate tabs on the Front Panel
3. The application will control three digital lines in a National Instruments M- Series DAQ device:
a. Two digital lines are required to turn relays on and off that connect and disconnect the
circuit from isolation. These digital lines will always change state together, they will
never be different values from each other. The relays connect the circuit to isolation and
stay connected when the digital lines are high. The relays disconnect the circuit from
isolation and stay disconnected when the digital lines are low.
b. A third digital line sends a digital trigger to turn on and off the standalone power supply
that powers the circuit. The power supply turns on and stays on when the digital line is
high, it turns off and stays off when the digital line is low. This is known as Pause
Triggering.
File Storage
4. A configuration file will store the following information about the application:
a. Circuit Setting:
i. Isolation Added?: Indicates whether the circuit has been connected to isolation
b. Physical Channels:
i. DMM Port: The serial port to which the Agilent DMM is connected
ii. Analog Channels: The analog input channel on the National Instruments DAQ
device that is connected to Channel 1 of the DUT
iii. Digital Lines: The three lines that will control the relays connecting to isolation
and act as the digital trigger to the power supply as described in the Acquisition
Functionality section
5. A TDMS file will log data about the acquired waveforms and their corresponding power
spectrums in the following format:
o File: “data”
75
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
wf_xname
wf_xunit_string
76
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
c. If the user clicks No or closes the panel on Read Config File.vi, the subVI will close and
configuration data will not be loaded
d. After “Load Configuration” has been pressed, all buttons will be enabled except the
“Snapshot graph image”, “Log Data”, “Save Configuration”, and Turn Power Off” buttons
which will be disabled and grayed
12. When the user presses the “Connect to Isolation” Boolean when it is in the default false
position, the application will write digital logic high to the first two selected digital lines on the
National Instruments DAQ Device to close the relays connecting the circuit to isolation
a. When isolation is connected, the data being acquired from channel 0 of the DUT will
have an amplitude of 1000 to simulate a greater amount of power coming from the
power supply, when isolation is disconnected, simulated data on the same channel will
have an amplitude of 20
b. Since “Connect to Isolation” is a switch action Boolean, it will remain depressed
c. The circuit display will show that isolation has been added
13. When the user presses the “Connect to Isolation” Boolean when it is in the true position the
application will write digital logic low to the first two selected digital lines on the National
Instruments DAQ Device
a. The circuit display will show that isolation has been removed
14. When the user clicks the “Turn Power On” button, the application will write digital logic high to
the third selected digital line on the National Instruments DAQ Device to send a digital pause
trigger to the standalone power supply, turning it on
a. The Agilent DMM and NI DAQ device will then read the data from Channel 0 and 1 of
the DUT, a power spectrum will be performed on the acquired data, and all data will be
displayed on the Front Panel graphs
b. The “Snapshot graph image”, “Log Data”, “Save Configuration”, and Turn Power Off”
buttons will all become enabled, all other buttons will become disabled and gray
c. The circuit display will show that power has been turned on
15. If the user clicks on “Snapshot graph image” while the power supply is on, an image of the plot
of the waveform graph currently being displayed in the tab control will be saved in the location
chosen by the user in Image Path
16. If the user clicks on “Log Data” while the power supply is on, the last 1000 samples from both
channels of the DUT, the corresponding power spectrums, and a Boolean indicating if the circuit
is isolated will be saved to TDMS file described above in the location chosen by the user in Log
Data Path
17. If the user clicks on “Save Configuration” while the power supply is on, the configuration file
described above will be saved in the location chosen by the user in Config File Path
18. If the user clicks on “Turn Power Off” while the power supply is on, the application will write
digital logic low to the third selected digital line on the National Instruments DAQ Device to send
a digital pause trigger to the standalone power supply, turning it off
a. Acquisition from the DUT will stop
b. After the above actions, all buttons will be enabled again except the “Snapshot graph
image”, “Log Data”, “Save Configuration”, and Turn Power Off” buttons
77
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
c. The circuit display will show that power has been turned off
19. When the user clicks the “STOP” button, the application will shut down all devices and end
20. If an error occurs in any portion of the application, the application will shut down all devices and
end
Documentation
21. All VIs should be documented in their VI properties
22. All controls should have descriptions and tips
23. Comments on the Block Diagram should describe algorithms and logic
24. Self-documenting code should be used as much as possible
State Diagram
Programming Instructions
1. Open Device Test.lvproj in the …/Device Test directory, we will be updating the application to
meet the Project Requirements
2. We will first need to add more states to our state machine so we will start with States.ctl
a. Add the following items and change the order so the final list looks like this:
i. Initialize
78
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
ii. Idle
iii. Reinitialize
v. Add Isolation
x. Save Config
xii. Shutdown
3. Now we will update Device Test Main.vi to the User Interface shown above
b. Copy the physical channel controls from Acquire and Analyze.vi and Isolate and
Power.vi to Device Test Main.vi
i. Circuit Display.ctl is a Strict Type Def of a tab control turned into an indicator,
the tabs have been hidden
Now we will need to examine the data to be passed between states. Previously, in our scaled
down Device Test application, we passed the isolation value with a shift register between states
so that any state could access and write the information. However, in our full application there
are several more pieces of data that need to be written and read from different states. Having a
shift register for each of those would be more difficult to manage and would create a mess of
wires. We will implement the same data structure we used in the F1 project: a cluster where the
needed data is bundled and unbundled by name in the necessary states. This will also help meet
our requirement to develop self-documenting code. Since this data cluster will only ever be used
on the top level VI in our application, we do not need to make a type def of it.
4. Create a Front Panel cluster named Data Structure and place the following items in this order:
79
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
e. Power Spectrum: A cluster of a 1D array of waveforms (use the same control from Log
Data.vi)
f. Time Domain: A 1D array of waveforms (use the same control from Log Data.vi)
*The Agilent DMM control is the exactly the same type of control as Agilent DMM Port in the Physical
Channels cluster. However, we will be using them in different ways. Agilent DMM Port exists to pass the
user selected COM port to the config file in the “Save Config” state. Agilent DMM passes the reference
to the active VISA session between the Agilent DMM SIM VIs when they are used in separate states.
5. Resize the Front Panel of Device Test Main.vi so that Data Structure is out of view.
There is another piece of data that we will be reading and writing from in different states of the
state machine. This is the state of the three digital lines that control the isolation and power
supply. We could write these using the Data Structure as we did with the data above, however,
the functional global variable offers us a much better vehicle for reading and writing the shared
data for two reasons: 1) we will be accessing the state of the digital lines extensively within
subVIs, and 2) when we set the state of the digital lines there are a few algorithms that we will
always use so it makes sense to modularize these algorithms into a subVI. This subVI is the
functional global variable Digital States.vi that we created in the DAQ exercise. We will be
integrating this VI below.
7. Add references for the Boolean buttons that don’t yet have them and place them with the other
references on the lower right of the Block Diagram of Device Test Main.vi
8. According to the Project Requirements, there are three states that our group of Booleans can be
in as far as being enabled/disabled:
1. All enabled except Snapshot, Log, Save Config, and Power OFF Booleans
80
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
2. All disabled and grayed except Snapshot, Log, Save Config, and Power
OFF Booleans
3. All disabled and grayed except Reinit, Load Config, and stop Booleans
b. We will organize our Boolean references into three arrays that can then be passed into
the state machine and enabled and disabled in the appropriate states
c. Build a five element array of Reinit, Load Config, Isolate, Power ON, and stop
references
e. Build a four element array of Snapshot, Log, Save Config, and Power OFF references
9. In the “Idle” state, add or modify event cases with the functionality described below to
incorporate the new Boolean buttons and states we have added:
81
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
c. In the “Isolate” event case, read the Isolate terminal and go to the “Add Isolation” case
when true and to the “Disconnect Isolation” case when false
e. Add an event case for a value change on Analog In channel, Digital Lines, or Agilent
DMM Port, and program the following:
i. Pass in the appropriate array of references to disable the Power ON and Isolate
buttons in this event case
There is another piece of data that we will be reading and writing from in different states of the
state machine. This is the state of the three digital lines that control the isolation and power
supply. We could write these using the Data Structure as we did with the data above, however,
the functional global variable offers us a much better vehicle for reading and writing the shared
data for two reasons: 1) we will be accessing the state of the digital lines extensively within
subVIs, and 2) when we set the state of the digital lines there are a few algorithms that we will
always use so it makes sense to modularize these algorithms into a subVI. This subVI is the
82
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
functional global variable Digital States.vi that we created in the DAQ exercise. We will be
integrating this VI below.
10. Create the “Initialize” case in the state machine and program in the following:
a. Place the terminals for Agilent DMM Port, Analog In channel, and Digital Lines in the
case
b. From Acquire and Analyze.vi, copy the three VIs used to initialize the Agilent DMM and
the two VIs used to initialize the NI DAQ device analog channel and place them in the
case
i. Keep the same configuration as the VIs had in Acquire and Analyze.vi
c. From Isolate and Power.vi, copy the VI used to initialize the NI DAQ device digital lines
to the case
d. Wire the terminals for Agilent DMM Port, Analog In channel, and Digital Lines to the
appropriate VIs
e. Bundle together Agilent DMM Port, Analog In channel, and Digital Lines
f. Pass the bundle of physical channels just created, the Agilent DMM VISA session, and
the two DAQmx tasks to a Bundle by Name function that will write these values back to
the Data Structure cluster in the shift register
g. Place Digital States.vi from the …\Device Test directory in the “Initialize” state
i. Set an array of all false values to the Digital States.vi functional global variable
h. Disable and gray the Snapshot, Log, Save Config, and Power OFF Booleans
j. Place the local variable of Isolate with the false constant wired to it in the case
k. From the data structure cluster wire, unbundle “Isolation” and use it to determine the
next state to execute after “Initialize”
The only reason the value of “Isolation” would be true at this point in the application is if the
application was being reinitialized after reading in values from a configuration file with an
“Isolation” value of true.
83
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
ii. If an error has not occurred, go to the state determined by the “Isolate” value
a. From the Data Structure cluster, unbundle “Agilent DMM”, “Analog Task”, and “Digital
Task”
84
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
We will now be editing Write Config File.vi to add the functionality to write and read the selected
physical channels on the Front Panel to the configuration file. First we will make a Type Def of the
Physical Channels cluster in the Data Structure cluster.
a. Create a Type Def. named Physical Channels.ctl from the Physical Channels cluster in
the Data Structure cluster on the Front Panel of Device Test Main.vi
b. Open Write Config File.vi and add three additional Write Key VIs to write the following
three keys under the “Physical Channels” section
d. On the Block Diagram of Write Config File.vi, unbundle Physical Channels and pass the
appropriate Physical Channel name to the Write Key VI that is writing that value
The VISA session and DAQmx Task wires will be coerced when they are input to the Value input of
the Write Key VIs, this indicates that a string will be written to the configuration file instead of the
VISA Session and DAQmx Task data types.
85
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
e. Delete the Isolate control from the Front Panel of Write Config File.vi
f. Replace the functionality of the Isolate control by placing Digital States.vi on the Block
Diagram of Write Config File.vi
i. Get the value of the data stored in Digital States.vi and wire the data out
terminal to an Index Array function
ii. Wire the output of the Index Array function to the Value input on the Write Key
VI that is writing the “Isolation Added?” key
Either of the first two Boolean values of the Digital States.vi functional global data will tell us
whether isolation has been added to the circuit since the first two digital lines are always equal in
value. By default, Index Array will output the 0 indexed value from the input array. This will
correspond to the value of the first digital line.
h. Open Read Config File.vi and add three additional Read Key VIs in the “Yes” event case
to read the following three keys under the “Physical Channels” section
i. Bundle the Value output from the three VIs into a cluster and pass them to an indicator
made from the Physical Channels.ctl Type Def.
Since we are giving the user the option to press No and not load the config file when the dialog
box pops up, we need a way for the “Load Config” state on Device Test Main.vi to know what the
86
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
j. Add the Boolean indicator Loaded? to the Front Panel of Read Config File.vi
k. In the “Yes” event case of the Block Diagram, write a true value to Loaded?
l. Assign Physical Channels and Loaded? to Connector Pane terminals on Read Config
File.vi
m. Resize the Front Panel of Read Config File.vi to appear as shown in the User Interface
above
o. In the “Load Config” event case on Device Test Main.vi, create a case structure based
on the Loaded? output from Read Config File.vi
i. Unbundle the Physical Channels output from Read Config File.vi and write them
to local variables for the Agilent DMM Port, Analog In channel, and Digital
Lines controls on the Front Panel of Device Test Main.vi
ii. From the Data Structure cluster, unbundle “Agilent DMM”, “Analog Task”, and
“Digital Task”
v. Write the Isolation Added? output from Read Config File.vi to the “Isolation”
value in the Data Structure cluster stored in the shift register
87
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
q. When the user has selected to not load a configuration file from Read Config File.vi:
i. Write nothing to the Data Structure cluster stored in the shift register
r. In the event of an error in the “Load Config” state, go the “Shutdown” state
88
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
a. Copy the DAQmx Write from Isolate and Power.vi to this state
b. Set the state of Digital States.vi with the three element array of Boolean constants
By disabling certain Boolean buttons on the Front Panel, we have ensured that the power supply
will always be off when we toggle isolation. Therefore, when we connect and disconnect isolation,
the third element in the Boolean array will always be false. However, the inverse will not be the
case when we toggle the trigger to the power supply. That is, when we toggle the power supply
on and off, the circuit may have had isolation added to it previously or it may not have. Digital
States.vi stores this information. When we command Digital States.vi to “Turn Power On” or
“Turn Power Off” we are changing the third Boolean in the array that Digital States is storing while
leaving the first two Booleans (which control isolation) in the state previously written to them. We
will address this situation when we code the “Turn Power On” and “Turn Power Off” states.
c. Write the data out value from Digital States.vi to the data input on the DAQmx Write
d. Provide the appropriate task in input to DAQmx Write from the Data Structure wire and
wire that task from task out on DAQmx Write back to Data Structure
e. Write a true value to “Isolation” in the Data Structure cluster stored in the shift register
We need to handle the case where the user runs the application and loads a configuration file
where “Isolation Added?” is true, but the user has never manually clicked the Isolate Boolean on
the Front Panel, meaning that the Isolate button will not be depressed. We will use a local
variable to handle this concern.
89
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
14. Duplicate the “Add Isolation” state to create the “Disconnect Isolation” state
c. Write a false value to “Isolation” in the Data Structure cluster stored in the shift register
b. Write the data out value from Digital States.vi to the data input on the DAQmx Write VI
that writes to the digital lines
ii. Use DAQmx Start Task on the analog task to begin acquisition on DUT Channel 1
Starting both devices together with their respective software “Start” functions as we are doing
here will not ensure that the devices are synchronized. They will start at roughly the same time
but the first sample from one device will almost certainly not be taken at the same time as the
first sample of the other device. To ensure that they both start together, we would need them to
both receive the same hardware trigger or have one device send a hardware trigger to the other.
Once they started together, we would need them to share clocks if we wanted every sample to be
90
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
taken at the same time as the corresponding sample on the other device. This type of accuracy is
generally only necessary for high speed acquisition/generation. If your application needs such
accuracy, look into sharing triggers and clocks between devices. For our Device Test application,
since our acquisition rate is fairly low (1kHz) and we are doing little more than qualitative analysis,
we will not worry about the potential inaccuracies caused by a lack of a shared trigger and clock.
d. Wire the appropriate task and session references to and from the DAQmx and Agilent
DMM VIs and the Data Structure cluster stored in the shift register
e. Write a true value to “Power” in the Data Structure cluster stored in the shift register
f. Use Disable.vi to disable and gray the Reinitialize, Load Config, Isolate, Power ON, and
stop buttons
a. Replace the two Sine Waveform VIs and the Gaussian White Noise Waveform VI with
the Agilent and DAQmx Read VIs from the Block Diagram of Acquire and Analyze.vi
91
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
b. Wire the appropriate task and session references to and from the DAQmx and Agilent
DMM VIs and the Data Structure cluster stored in the shift register
c. Write the 1D array of waveforms output from the Agilent and DAQmx Read VIs to the
“Time Domain” value in the Data Structure cluster stored in the shift register
d. Write the dynamic data output from the Spectral Measurements Express VI to the
“Power Spectrum” value in the Data Structure cluster stored in the shift register
i. If any of them have been selected by the user, proceed to the appropriate state
ii. If none are selected, stay in the “Acquire Data” state unless an error has
occurred in the state
We will replace the Isolate terminal on the Block Diagram by getting the value of the digital line
with the Digital States.vi, exactly as we did with Write Config File.vi above.
b. Delete the Isolate control from the Front Panel of Log Data.vi
92
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
c. Replace the functionality of the Isolate control by placing Digital States.vi on the Block
Diagram of Log Data.vi
i. Get the value of the data stored in Digital States.vi and wire the data out
terminal to an Index Array function
ii. Wire the output of the Index Array function to the property values input on the
TDMS Set Properties VI that was writing the value of the Isolate control
e. On the Block Diagram of Device Test Main.vi, in the “Log Data” state, unbundle the
“Time Domain” and “Power Spectrum” data from the Data Structure cluster and pass
them to Log Data.vi
f. Use Log Data Path on the Front Panel of Device Test Main.vi to determine where Log
Data.vi will save the data
93
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
a. Unbundle the “Physical Channels” cluster from the Data Structure cluster and pass it to
Write Config File.vi that we have created
b. Use Config File Path on the Front Panel of Device Test Main.vi to determine where
Write Config File.vi will save the data
19. Duplicate the “Turn Power On” state to create the “Turn Power Off” state
a. Replace the Agilent DMM and DAQmx Start tasks with their corresponding Stop VIs
c. Use Disable.vi to enable the Reinitialize, Load Config, Isolate, Power ON, and stop
buttons
e. Write a false value to “Power” in the Data Structure cluster stored in the shift register
94
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
a. Close the Agilent DMM VISA session and both DAQmx tasks
b. Write a false value to “Isolation” and “Power” in the Data Structure cluster stored in the
shift register
21. Create logic to update Circuit Display.ctl on the Front Panel of Device Test Main.vi
95
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
a. On the Block Diagram of Device Test Main.vi, to the right of the case structure and
inside the While Loop, unbundle “Isolation” and “Power” from the Data Structure
cluster
b. Use nested case structures to implement the following logic where “Page X”
corresponds to the tab to be displayed on Circuit Display.ctl
Create a constant displaying “Page X” by right clicking on the input to the Circuit Display terminal
and creating a constant. Wire the constant from the cases that executed to the Circuit Display
terminal placed to the right of the nested case structures.
22. Run the Device Test application and make sure it meets the Project Requirements
24. Organize Device Test.lvproj to display under My Computer all subVIs and Type Defs that have
been created for the Device Test application
a. Move them from the Dependencies section if they currently reside there
96
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
b. Make a Virtual Folder under My Computer to contain all the Agilent SIM VIs
END OF EXERCISE
97
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Unit 3
98
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
Requirements
1. Any subVI that acts as a dialog box will not display toolbars, menus, or scrollbars
3. When the user stops the application, the executable will not close
a. The user may reconfigure Front Panel controls and run the executable again
Programming Instructions
Consider the possible standalone preparations discussed in the presentation. Do we need to add a
Quit LabVIEW function? No, the Requirements specifically state not to so that the user can
reconfigure Front Panel controls after the VI stops. Do we need to use relative file path handling?
No, in this application we want the user to decide where the config and log files will be stored.
Should we update subVIs that show their Front Panel to have a dialog box appearance? Yes. Do
we need to set any default values in Front Panel controls? Yes.
1. Change the Window Appearance of Read Config File.vi to be a dialog box in order to remove
toolbars, menus, and scrollbars
2. Change the Window Appearance of Device Test Main.vi to be a top-level application window
3. On Device Test Main.vi, ensure that valid default values are set in Agilent DMM Port, Analog In
channel, and Digital Lines
4. Add the config file and data.tdms file to the LabVIEW project
99
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
a. This will allow users to see the format and typical data included in these files
5. In Device Test.lvproj, create a new Application (EXE) from the Build Applications item
a. Name the application “Device Test” and the executable “Device Test.exe”
b. In the Source Files menu, select Device Test Main.vi as the Startup VI
c. Add files that the application reads and writes to, such as config file and data.tdms, to
Always Include
7. In Device Test.lvproj, create a new Installer from the Build Applications item
a. Name the installer “Device Test Installer” and the product name “Device Test”
100
Exercise Manual Lucid LabVIEW Fundamentals II © Sixclear, llc.
b. In the Source Files menu, select “Device Test” in the Project View window and the
Device Test directory in the Destination View window
View the Additional Installer menu, by default the LabVIEW Run-Time Engine is checked since any
machine needs the Run-Time Engine to run the executable. Since our Device Test application uses
DAQmx, VISA and Agilent 34401 VIs, we need to ensure that any machine we run the application
on has those drivers installed. We can use the Additional Installer menu to install NI DAQmx and
NI-VISA Runtime on that machine. We would go to the Advanced menu to run a separate
executable to install our Agilent VIs on that machine as well.
Adding any of these installers will result in a significantly larger installer file and would take longer
to install on any machine that will run the Device Test application. For this reason, we leave the
decision to add these installers up to you. The solution for this exercise does not have any of these
installers (even the LabVIEW Run-Time Engine) included.
To conserve space on the downloadable image for Fundamentals II, the …\Volume directory in the
…\Device Test Installer directory has been removed from the solution, leaving an empty …\Device
Test Installer directory.
END OF EXERCISE
101