0% found this document useful (0 votes)
457 views

LabVIEW TM Core 3 Exercises Course Softw

LabView

Uploaded by

Parcin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
457 views

LabVIEW TM Core 3 Exercises Course Softw

LabView

Uploaded by

Parcin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Sa TM

m
LabVIEW Core 3
Exercises

Course Software Version 2014


November 2014 Edition
Part Number 325511D-01

LabVIEW Core 3 Exercises

Copyright
© 2004-2014 National Instruments. All rights reserved.
ple
Under the copyright laws, this publication may not be reproduced or transmitted in any form, electronic or mechanical, including photocopying, recording, storing in an information retrieval system, or
translating, in whole or in part, without the prior written consent of National Instruments Corporation.
National Instruments respects the intellectual property of others, and we ask our users to do the same. NI software is protected by copyright and other intellectual property laws. Where NI software may
be used to reproduce software or other materials belonging to others, you may use NI software only to reproduce materials that you may reproduce in accordance with the terms of any applicable license
or other legal restriction.

End-User License Agreements and Third-Party Legal Notices


You can find end-user license agreements (EULAs) and third-party legal notices in the following locations:
• Notices are located in the <National Instruments>\_Legal Information and <National Instruments> directories.
• EULAs are located in the <National Instruments>\Shared\MDF\Legal\license directory.
• Review <National Instruments>\_Legal Information.txt for more information on including legal information in installers built with NI products.
Sa
Trademarks
Refer to the NI Trademarks and Logo Guidelines at ni.com/trademarks for more information on National Instruments trademarks.
ARM, Keil, and µVision are trademarks or registered of ARM Ltd or its subsidiaries.

m
LEGO, the LEGO logo, WEDO, and MINDSTORMS are trademarks of the LEGO Group.
TETRIX by Pitsco is a trademark of Pitsco, Inc.
FIELDBUS FOUNDATION™ and FOUNDATION™ are trademarks of the Fieldbus Foundation.
EtherCAT® is a registered trademark of and licensed by Beckhoff Automation GmbH.
CANopen® is a registered Community Trademark of CAN in Automation e.V.
DeviceNet™ and EtherNet/IP™ are trademarks of ODVA.
Go!, SensorDAQ, and Vernier are registered trademarks of Vernier Software & Technology. Vernier Software & Technology and vernier.com are trademarks or trade dress.
Xilinx is the registered trademark of Xilinx, Inc.

ple
Taptite and Trilobular are registered trademarks of Research Engineering & Manufacturing Inc.
FireWire® is the registered trademark of Apple Inc.
Linux® is the registered trademark of Linus Torvalds in the U.S. and other countries.
Handle Graphics®, MATLAB®, Real-Time Workshop®, Simulink®, Stateflow®, and xPC TargetBox® are registered trademarks, and TargetBox™ and Target Language Compiler™ are trademarks of The
MathWorks, Inc.
Tektronix®, Tek, and Tektronix, Enabling Technology are registered trademarks of Tektronix, Inc.
The Bluetooth® word mark is a registered trademark owned by the Bluetooth SIG, Inc.
The ExpressCard™ word mark and logos are owned by PCMCIA and any use of such marks by National Instruments is under license.
The mark LabWindows is used under a license from Microsoft Corporation. Windows is a registered trademark of Microsoft Corporation in the United States and other countries.
Other product and company names mentioned herein are trademarks or trade names of their respective companies.
Members of the National Instruments Alliance Partner Program are business entities independent from National Instruments and have no agency, partnership, or joint-venture relationship with National
Instruments.

Patents
For patents covering National Instruments products/technology, refer to the appropriate location: Help»Patents in your software, the patents.txt file on your media, or the National Instruments
Patent Notice at ni.com/patents.
Sa
m
Support

Worldwide Technical Support and Product Information


ni.com

Worldwide Offices
ple
Visit ni.com/niglobal to access the branch office websites, which provide up-to-date contact information, support phone numbers, email addresses, and current events.

National Instruments Corporate Headquarters


11500 North Mopac Expressway Austin, Texas 78759-3504 USA Tel: 512 683 0100

To comment on National Instruments documentation, refer to the National Instruments website at ni.com/info and enter the Info Code feedback.
Sa
m
ple
Sa
Contents

m
Student Guide
A. NI Certification........................................................................................................................................................................................vii
B. Course Description ..................................................................................................................................................................................viii
C. What You Need to Get Started ................................................................................................................................................................ix
D. Installing the Course Software ................................................................................................................................................................ix
E. Course Goal .............................................................................................................................................................................................ix

ple
Lesson 1
Developing Successful Applications
Exercise 1-1 Review a Requirements Document............................................................................................................................1-3
Exercise 1-2 Review User Stories...................................................................................................................................................1-5

Lesson 2
Organizing the Project
Exercise 2-1 Create a Project Library .............................................................................................................................................2-3
Exercise 2-2 Resolve Project Conflicts...........................................................................................................................................2-7

Lesson 3
Creating an Application Architecture
Exercise 3-1 Create a Queued Message Handler ............................................................................................................................3-3
Exercise 3-2 Handshaking with Notifiers .......................................................................................................................................3-17

Lesson 4
Customizing the User Interface
Exercise 4-1 Create a User Interface Prototype ..............................................................................................................................4-3
Exercise 4-2 Create User Documentation.......................................................................................................................................4-17
Exercise 4-3 Initialize an Application from a File..........................................................................................................................4-25
Exercise 4-4 Improve Application Usability ..................................................................................................................................4-39

LabVIEW Core 3 Exercises © National Instruments | v


Sa
Contents

Lesson 5
Managing and Logging Errors
ni.com | vi

m
Exercise 5-1 Manage Errors............................................................................................................................................................5-3
Exercise 5-2 Log Errors ..................................................................................................................................................................5-17

Lesson 6
Creating Modular Code
Exercise 6-1 Implement and Test a Data Logging Module ............................................................................................................6-3
Exercise 6-2 Integrate and Test Modules from the Top-Down ......................................................................................................6-19

ple
Exercise 6-3 Integrate and Test Modules from the Bottom-Up......................................................................................................6-35
Exercise 6-4 Implement Fuel Control Valve Functionality............................................................................................................6-53
Exercise 6-5 Integrate and Sandwich Test a Module......................................................................................................................6-63

Appendix A
Additional Information and Resources
Sa
Student Guide

m
Thank you for purchasing the LabVIEW Core 3 course kit. This course manual and the accompanying software are used in the three-day, hands-on LabVIEW Core 3
course.

You can apply the full purchase of this course kit toward the corresponding course registration fee if you register within 90 days of purchasing the kit. Visit
ni.com/training for online course schedules, syllabi, training centers, and class registration.

Note For course and exercise manual updates and corrections, refer to ni.com/info and enter the Info Code core3.

ple
A. NI Certification
The LabVIEW Core 3 course is part of a series of courses designed to build your proficiency with LabVIEW and help you prepare for NI LabVIEW certification
exams. The following illustration shows the courses that are part of the LabVIEW training series. Refer to ni.com/training for more information about
NI Certification.

LabVIEW Learning Path

Certified LabVIEW Certified LabVIEW Certified LabVIEW


Associate Developer Developer Architect

LabVIEW
LabVIEW LabVIEW LabVIEW Core 3
Getting Started Core 1 Core 2 Advanced
Architectures
LabVIEW
in LabVIEW
Connectivity

LabVIEW
Performance Managing
Software
Engineering
Object-Oriented
in LabVIEW
Design &
Programming
in LabVIEW

LabVIEW Core 3 Exercises © National Instruments | vii


Sa
Student Guide

B. Course Description
ni.com | viii

m
LabVIEW Core 3 introduces you to structured practices to design, implement, document, and test LabVIEW applications. This course focuses on developing
hierarchical applications that are scalable, readable, and maintainable. The processes and techniques covered in this course help reduce development time and improve
application stability. By incorporating these design practices early in your development, you avoid unnecessary application redesign, increase VI reuse, and minimize
maintenance costs.

This course assumes that you have taken the LabVIEW Core 1 and LabVIEW Core 2 courses or have equivalent experience.

This course kit is designed to be completed in sequence. The course and exercise manuals are divided into lessons, described as follows.

In the course manual, each lesson consists of the following:

ple
• An introduction that describes the purpose of the lesson and what you will learn

• A discussion of the topics in the lesson

• A summary quiz that tests and reinforces important concepts and skills taught in the lesson

In the exercise manual, each lesson consists of the following:

• A set of exercises to reinforce the topics in the lesson

• Some lessons include optional and challenge exercise sections or additional exercises to complete if time permits

Note The exercises in this course are cumulative and lead toward developing a final application at the end of the course. If you skip an exercise, use the
solution VI for that exercise, available in the <Solutions>\LabVIEW Core 3 directory, in later exercises.
Sa
C. What You Need to Get Started

m
Before you use this course manual, make sure you have the following items:

 Windows XP or later installed on your computer

 LabVIEW Professional Development System 2012 or later

 LabVIEW Core 3 course CD, containing the following folders:

ple
Directory Description

Exercises Folder containing VIs and other files used in the course
Solutions Folder containing completed course exercises

D. Installing the Course Software


Complete the following steps to install the course software.

1. Insert the course CD in your computer.

2. Follow the prompts to install the course material.

The installer places the Exercises and Solutions folders at the top level of the root directory. Exercise files are located in the <Exercises>\LabVIEW Core
3 directory.

Tip Folder names in angle brackets, such as <Exercises>, refer to folders in the root directory of your computer.

E. Course Goal
Given a requirements document for a LabVIEW development project, you will follow a software development process to design, implement, document and test the
key application features in a manner that satisfies requirements for readability, scalability, and maintainability.

LabVIEW Core 3 Exercises © National Instruments | ix


Sa
m
ple
Sa 5

m
Managing and Logging Errors

Topics
Exercise 5-1 Manage Errors

ple
Exercise 5-2 Log Errors

LabVIEW Core 3 Exercises © National Instruments | 5-1


Sa
m
ple
Sa
Exercise 5-1 Manage Errors

m
Goal
Modify your code to gracefully handle both critical and non-critical errors.

Scenario
In the sprint planning meeting for this iteration, the product owner chose to implement the following user stories:

• As a boiler operator, I want the boiler controller to prevent the boiler from entering an unsafe state as a result of a critical error.

ple
• As a boiler operator, I want the system to be robust enough that minor errors do not result in system shut down, so that the boiler only shuts down if the error
prevents safe operation.

Critical errors require shutting down the application because they cannot be otherwise managed. If they are not handled, critical errors may result in injury to personnel
or damage to equipment. They may also place the system into an unmanageable state.
Non-critical errors are more akin to inconveniences that should not prevent continued execution of the application.

After discussing these user stories with the team, you identified and classified the following errors:

Table 5-1. Errors

Cause of Error Critical or Non-Critical

Cancelling the Open File dialog when loading the INI file Non-critical

The user chooses an invalid INI file Critical


During development, you accidentally mistype a message string or case name Critical

To address these errors, your team identifies the following tasks:

1. Modify Read Configuration Data.vi to handle cancellation of the Open File dialog.

2. Modify Read UI Constants.vi to handle selection of an invalid INI file.

3. Modify the Default case of the Message Handling Loop and Boiler Controller to handle typos when sending messages.

4. Modify the Message Handling Loop and Boiler Controller Loop to handle shutting down in the event of a critical error.

LabVIEW Core 3 Exercises © National Instruments | 5-3


Sa
Lesson 5

Design
Managing and Logging Errors

The team decides on the following strategies for approaching each task:
ni.com | 5-4

m
1. Modify Read Configuration Data.vi to handle cancellation of the Open File dialog.

• Modify Read Configuration Data.vi to load a default INI file if the user cancels the Open File dialog.

2. Modify Read UI Constants.vi to handle selection of an invalid INI file.

• Modify Read UI Constants.vi to check that each key was properly read from the INI file.

ple
• Use an error ring to generate a custom error to indicate that the INI file is not valid.

3. Modify the Default case of the Message Handling Loop and Boiler Controller to handle typos when sending messages.

• Use an error ring to generate a custom error to indicate that an invalid message was received by that loop.

4. Modify the Message Handling Loop and Boiler Controller Loop to handle shutting down in the event of a critical error.

• Create a separate Error case in the Message Handling Loop and Boiler Controller Loop.

• Modify Dequeue Message.vi to send you to the Error case instead of the Exit case in the event of an error.

• Critical errors should be passed as message data from the bottom up (Boiler»Boiler Controller»Message Handling Loop)

• The Error case of the Message Handling Loop sends you to the Initiate Stop case, as if you clicked Emergency Stop.
Sa Figure 5-1. Errors Passed up to the Message Handling Loop, which then Stops All Loops

m
Critical
Error

Boiler “Error”

Boiler Controller
“Error”

ple
MHL “Error”

MHL
“Initiate Stop”

Boiler MHL
Controller “Exit” “Wait on Boiler Exit”

No

Wait for Notification


Boiler “Exit”
Notification Received?

Release Release Boiler MHL


Boiler Queue Controller Queue “Exit”

Send Notification Send Notification Release EHL “Stop”


to Boiler Controller to MHL MHL Queue User Event

Stop Loop Stop Loop Stop Loop Stop Loop

LabVIEW Core 3 Exercises © National Instruments | 5-5


Sa
Lesson 5 Managing and Logging Errors

Implementation
ni.com | 5-6

m
Non-Critical Errors
1. Modify Read Configuration Data.vi to handle cancellation of the Open File dialog.

 Run Main.vi. Cancel the Open File dialog where you would normally select the INI file. Notice that the File Dialog express VI generates Error 43 to indicate
that the operation was cancelled. This error causes the application to exit. This is not a desirable behavior.

 Modify Read Configuration Data.vi to load a default INI file if the user cancels the Open File dialog as shown in Figure 5-2.

ple
Sa Figure 5-2. Read Configuration Data VI Block Diagram Load Default INI File

m
3 1

ple
2

1 Build Path function


2 Path constant
3 Wire the cancelled output of the File Dialog express VI to the case selector.

2. Test the VI.

 Run Main.vi and cancel the Open File dialog. Notice that the code continues executing normally, using the default file.

LabVIEW Core 3 Exercises © National Instruments | 5-7


Sa
Lesson 5 Managing and Logging Errors

Critical Errors
1. Modify Read UI Constants to handle selection of an invalid INI file.
ni.com | 5-8

m
 Run Main.vi. Select any file other than the INI file that you created. Notice that the range of Fuel Control Valve updated to 0-1 instead of 10-75. This did
not generate an error, but the application cannot function without proper configuration of the Fuel Control Valve limits.

 Modify Read UI Constants.vi as shown in Figure 5-3 to check that each key was properly read from the INI file.
Figure 5-3. Read UI Constants Using Error Ring

1 ple 1

Error Ring—Generate a custom error to indicate that the INI file is not valid. This error shuts down the system.
 Configure the Error ring with custom error code 5000 and the message Could not read UI constants from INI file.
Sa
2. Modify the Default case of the Message Handling Loop and Boiler Controller to handle typos when sending messages.

m
 Modify the Reset event case of the Event Handling Loop to send the incorrect message, Resets, to the Message Handling Loop.
Figure 5-4. Event Handling Loop Reset: Value Change Case with Typo

ple
1 Change the Message string constant input to Resets.

LabVIEW Core 3 Exercises © National Instruments | 5-9


Sa
Lesson 5 Managing and Logging Errors ni.com

 Open the Default case of the Message Handling Loop. Notice that the code is already generating an error. Replace the Format into String and Error Cluster
|

From Error Code functions with an error ring, as shown in Figure 5-5. This method of generating an error allows greater flexibility in how you generate the
5-10

m
error.

Figure 5-5. Message Handling Loop Default Case with Error Ring

ple
1

1 Error Ring—Configure the error ring with Custom Error Code 5003 and the message The invalid message string “%s” was received in the
Message Handling Loop.
Sa
3. Modify the Default case of the Boiler Controller.vi as shown in Figure 5-6.

m
Figure 5-6. Boiler Controller VI Default Case with Error Ring

1
Boiler Controller Loop.

ple
Error ring—Configure the error ring with custom error code 5004 and the message The invalid message string “%s” was received in the

 Run Main.vi. Click Reset. Notice that the application hangs because Dequeue Message.vi sends the Message Handling Loop directly into the Exit
case which causes the Message Handling Loop and Event Handling Loop stop, but no message is sent to the boiler controller to stop it and the boiler.

 To halt the application, select the Boiler window and press <Ctrl -.>.

LabVIEW Core 3 Exercises © National Instruments | 5-11


Sa
Lesson 5 Managing and Logging Errors

4. Modify the Message Handling Loop and Boiler Controller Loop to handle shutting down in the event of a critical error.
ni.com | 5-12

m
 Create an Error case in the Message Handling Loop and Boiler Controller Loop.
Figure 5-7. Message Handling Loop Error Case

ple
Sa Figure 5-8. Boiler Controller Loop Error Case

m
ple
LabVIEW Core 3 Exercises © National Instruments | 5-13
Sa
Lesson 5 Managing and Logging Errors

5. Modify Dequeue Message.vi, as shown in Figure 5-9 to send you to the Error case instead of the Exit case in the event of an error.
ni.com | 5-14

m
Note You must close all open VIs and modify Dequeue Message.vi from the LabVIEW project. This VI is reentrant, so you must ensure that there is
only one copy in memory before you can edit it.

Figure 5-9. Dequeue Message Block Diagram

ple
3

1 Update the comment to say that the output is an Error message instead of an Exit message
2 Update the Message to Stop the Handler to Error.
3 Error cluster constant

 Critical errors should be passed as message data from the bottom up—Boiler»Boiler Controller»Message Handling Loop.
Sa Note Boiler Controller Error sends a message to the Message Handling Loop Error. Errors in the boiler are passed up to the Boiler Controller in the
same way.

m
The Error cases should not wire the error cluster into the Enqueue Message. For the Boiler Controller, wire an error cluster constant to the shift register for
each loop to avoid an endless error cycle. (The desired effect for the error will happen by launching the shutdown process.)

 The Error case of the Message Handling Loop sends you to the Initiate Stop case, as if you clicked Emergency Stop.

Test the Application


1. Test the VI.

ple
 Run the VI.

 Verify that:

– Cancelling the Open File dialog does not stop the application.

– Specifying an invalid INI file stops the application.

– All previously-implemented functionality except for Reset still works.

– Clicking Reset generates a critical error that halts the application.

2. Test the build specification.

 Build the executable from the build specification.

 Run Boiler Controller.exe.

 Verify the behavior from Step 1.

– Cancelling the Open File dialog fails because the relative path to the default INI file is different for the EXE—in the data folder, instead of at the same
level.

LabVIEW Core 3 Exercises © National Instruments | 5-15


Sa
Lesson 5 Managing and Logging Errors

3. Modify Read Configuration Data.vi, as shown in Figure 5-10, to use a different relative path for EXEs.
ni.com | 5-16

m
Figure 5-10. Modify Read Configuration Data Block Diagram

4. Fix the forced error.

ple
 Update the Reset case of the Event Handling Loop to call Reset instead of Resets.

End of Exercise 5-1


Sa
Exercise 5-2 Log Errors

m
Goal
Log information about any error that causes a system shutdown.

Scenario
In the sprint planning meeting for this iteration, the product owner chose to implement the following user story:

• As a boiler operator, I want information about critical errors to be logged to disk, so that I can identify and troubleshoot the cause of the error at a later date.

As it is currently implemented, critical errors cause the application to shut down without providing any additional information to the end-user.

ple
To implement this user story, your team identifies the following tasks:

1. Create the error log file in the same directory as the main application.

2. When a critical error occurs, log the error code and source.

3. If you cannot write to the application directory, display the error information to the user.

4. After logging the error, close the error log file reference.

Design
The team decides on the following strategies for approaching each task:

1. Create the error log file in the same directory as the main application.

• The error log should only be created if a critical error actually occurs.

• Create the error file in the Error case of the Message Handling Loop.

2. When a critical error occurs, log the current time, error code and source.

• Pass the error cluster as Message Data when you send the Error message.

• Extract the error code and source from the error cluster.

• Create a subVI that writes the time, error code, and source to the error log file.

LabVIEW Core 3 Exercises © National Instruments | 5-17


Sa
Lesson 5 Managing and Logging Errors

3. If you cannot write to the application directory, display the error information to the user.
ni.com | 5-18

m
• If the error log reference is invalid, then you cannot write to the file.

• Instead, launch a one-button dialog and display the information to the user.

4. After logging the error, close the error log file reference.

Implementation
1. Add a VI to write the time, error code, and source to the error log file.

ple
 Create a virtual folder called Logging in Support VIs folder the Boiler Controller Project Explorer window.

 Navigate to <Exercises>\LabVIEW Core 3\External\Support VIs\Logging and copy Log Error.vi into the <Exercises>\
LabVIEW Core 3\Course Project\support\Logging directory.

 Add Log Error.vi to the Logging virtual folder of the Boiler Controller Project Explorer window.
Sa
2. If you cannot write to the application directory, display the error information to the user.

m
 Modify the error file in the Error case of the Message Handling Loop as shown in Figure 5-11.
Figure 5-11. Message Handling Loop Error Case

ple
1

1 Create the error log file in the same directory as the main application.
2 After logging the error, close the error log file reference

LabVIEW Core 3 Exercises © National Instruments | 5-19


Sa
Lesson 5 Managing and Logging Errors

3. When a critical error occurs, log the current time, error code and source.
ni.com | 5-20

m
 Modify the Error case of Boiler Controller.vi, as shown in Figure 5-12. You use the custom errors 5001 and 5002 in future exercises.
Figure 5-12. Boiler Controller Error Case

1
1

Pass the error cluster as Message Data when you send the Error message.
ple
Sa
Test the Application
1. Test the VI.

m
 Run the VI. Verify the following:
– Specifying an invalid INI file stops the application and creates Error Log.txt.
– Error Log.txt contains time, error code, and error source information similar to Figure 5-13.

Figure 5-13. Error Log.txt





Run the VI again.
Clicking Reset halts the application with a critical error.
Open Error Log.txt and view the new entry to the file.
Close the file.
Fix the Reset case to send a Reset message.
 Verify the behavior when the application cannot write to the log file.
ple
 Modify the Reset event case of the Event Handling Loop to send a Resets message to the Message Handling Loop.

– Set Error Log.txt to read-only.


– Run the VI.

LabVIEW Core 3 Exercises © National Instruments | 5-21


Sa
Lesson 5



Managing and Logging Errors

Specify an invalid INI file. A dialog appears indicating the time, error code, and source.
Set Error Log.txt to be writable.
ni.com | 5-22

m
2. Test the build specification.

 Build the executable from the build specification.

 Run Boiler Controller.exe.


 Verify the behavior from Step 1.
– Specify an invalid INI file. You do not need to change the Reset case.

ple
End of Exercise 5-2

You might also like