• No results found

LabVIEW Intermediate II (Connectivity Course Manual).pdf

N/A
N/A
Protected

Academic year: 2021

Share "LabVIEW Intermediate II (Connectivity Course Manual).pdf"

Copied!
216
0
0

Loading.... (view fulltext now)

Full text

(1)

LabVIEW

Intermediate II

Connectivity Course Manual

Course Software Version 8.0 October 2005 Edition

Part Number 323758B-01

LabVIEW Intermediate II Course Manual

Copyright

© 2004–2005 National Instruments Corporation. All rights reserved.

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.

In regards to components used in USI (Xerces C++, ICU, and HDF5), the following copyrights apply. For a listing of the conditions and disclaimers, refer to the USICopyrights.chm.

This product includes software developed by the Apache Software Foundation (http:/www.apache.org/). Copyright© 1999 The Apache Software Foundation. All rights reserved.

Copyright © 1995–2003 International Business Machines Corporation and others. All rights reserved. NCSA HDF5 (Hierarchical Data Format 5) Software Library and Utilities

Copyright 1998, 1999, 2000, 2001, 2003 by the Board of Trustees of the University of Illinois. All rights reserved.

Trademarks

National Instruments, NI, ni.com, and LabVIEW are trademarks of National Instruments Corporation. Refer to the Terms of Use section on ni.com/legal for more information about National Instruments trademarks.

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, refer to the appropriate location: Help»Patents in your software, the patents.txt file on your CD, or ni.com/legal/patents.

(2)

National Instruments Corporate Headquarters

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

Worldwide Offices

Australia 1800 300 800, Austria 43 0 662 45 79 90 0, Belgium 32 0 2 757 00 20, Brazil 55 11 3262 3599, Canada 800 433 3488, China 86 21 6555 7838, Czech Republic 420 224 235 774, Denmark 45 45 76 26 00, Finland 385 0 9 725 725 11,

France 33 0 1 48 14 24 24, Germany 49 0 89 741 31 30, India 91 80 51190000, Israel 972 0 3 6393737, Italy 39 02 413091, Japan 81 3 5472 2970, Korea 82 02 3451 3400, Lebanon 961 0 1 33 28 28, Malaysia 1800 887710, Mexico 01 800 010 0793, Netherlands 31 0 348 433 466, New Zealand 0800 553 322, Norway 47 0 66 90 76 60, Poland 48 22 3390150,

Portugal 351 210 311 210, Russia 7 095 783 68 51, Singapore 1800 226 5886, Slovenia 386 3 425 4200, South Africa 27 0 11 805 8197, Spain 34 91 640 0085, Sweden 46 0 8 587 895 00, Switzerland 41 56 200 51 51, Taiwan 886 02 2377 2222, Thailand 662 278 6777, United Kingdom 44 0 1635 523545

For further support information, refer to the Additional Information and Resources appendix. To comment on National Instruments documentation, refer to the National Instruments Web site at ni.com/info and enter the info code feedback.

(3)

Student Guide

A. NI Certification ...v

B. Course Description ...vi

C. What You Need to Get Started ...vi

D. Installing the Course Software...vii

E. Course Goals...vii

F. Course Conventions ...viii

Lesson 1

Calling Shared Libraries in LabVIEW

A. Shared Library Overview...1-2 B. Calling Shared Libraries ...1-2 Exercise 1-1 Computer Name...1-12 Summary ...1-27

Lesson 2

VI Server

A. What is VI Server?...2-2 B. VI Server Programming Model ...2-4 C. VI Server Functions ...2-5 Exercise 2-1 Concept: VI Server Options ...2-13 Exercise 2-2 VI Statistics ...2-15 D. Remote Communication ...2-23 Exercise 2-3 Concept: Remote Run VI ...2-25 E. Dynamically Calling and Loading VIs ...2-29 Exercise 2-4 Dynamically Calling VIs...2-34 Summary ...2-38

Lesson 3

Calling Objects in LabVIEW

A. Calling Objects in LabVIEW Using ActiveX...3-2 B. Using LabVIEW as an ActiveX Client...3-3 Exercise 3-1 Browse to URL...3-7 Exercise 3-2 VI Statistics Report...3-12 C. Using LabVIEW as an ActiveX Server ...3-15 Exercise 3-3 Frequency Response VI...3-17 D. ActiveX Events ...3-19

(4)

LabVIEW Intermediate II Course Manual iv ni.com E. Calling Objects in LabVIEW Using .NET ...3-21 F. Implementing .NET ...3-23 Exercise 3-4 Font Dialog...3-26 Exercise 3-5 Word Processor ...3-32 G. Registering .NET Events ...3-53 Exercise 3-6 Auto Save ...3-55 Summary ...3-63

Lesson 4

Broadcasting Data

A. Broadcasting Data Overview ...4-2 B. Implementing Broadcast Models ...4-5 Exercise 4-1 VI Statistics Broadcast ...4-7 Summary ...4-13

Lesson 5

Serving Data to a Client Using TCP/IP

A. TCP/IP Overview...5-2 Exercise 5-1 Concept: Simple Data Client VI and Simple Data Server VI ...5-6 B. Implementing the Client/Server Model ...5-10 Exercise 5-2 TCP File Transfer ...5-13 Summary ...5-24

Lesson 6

Publishing Data to a Subscriber

A. Publisher/Subscriber Communication Model Overview ...6-2 B. Implementing the Publisher/Subscriber Communication Model...6-9 Exercise 6-1 Publisher and Subscriber ...6-15 Summary ...6-22

Appendix A

Additional Information and Resources

Index

(5)

Thank you for purchasing the LabVIEW Intermediate II: Connectivity course kit. This course manual and the accompanying software are used in the two-day, hands-on LabVIEW Intermediate II: Connectivity course.

Note 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.

A. NI Certification

The LabVIEW Intermediate II: Connectivity course is part of a series of courses designed to build your proficiency with LabVIEW and help you prepare for exams to become an NI Certified LabVIEW Developer and NI Certified LabVIEW Architect. 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 Intermediate I* LabVIEW Intermediate II*

New User Experienced User Advanced User

LabVIEW Advanced Application Development

LabVIEW Advanced Application Development

Certified LabVIEW Associate Developer Exam

Certified LabVIEW Developer Exam Certified LabVIEW Architect Exam Skills tested: • LabVIEW application development expertise Skills learned:

• Modular application development • Structured design and

development practices • Memory management and VI performance improvement

Skills learned:

• Large application design • Code reuse maximization • Object-oriented programming in LabVIEW Skills tested: • LabVIEW application development mastery Skills tested: • LabVIEW environment knowledge Skills learned: • LabVIEW environment navigation

• Basic application creation using LabVIEW

Certifications Courses

Hardware-Based Courses:

• Data Acquisition and Signal Conditioning • Modular Instruments • Instrument Control • Machine Vision • Motion Control • LabVIEW Real-Time

*Core courses are strongly recommended to realize maximum productivity gains when using LabVIEW.

LabVIEW Basics I*

Skills learned:

• LabVIEW environment navigation

• Basic application creation using LabVIEW

LabVIEW Basics II* Begin

(6)

LabVIEW Intermediate II Course Manual vi ni.com

B. Course Description

This course manual teaches you how to use advanced connectivity in VIs. This course manual assumes that you are familiar with Windows, that you have experience writing algorithms in the form of flowcharts or block diagrams, and that you have taken the LabVIEW Basics I: Introduction and LabVIEW Basics II: Development courses or you have familiarity with all the concepts contained therein. This course also assumes that you have one year or more of LabVIEW development experience.

The course manual is divided into lessons, each covering a topic or set of topics. Each lesson consists of the following:

• An introduction that describes the lesson’s purpose and topics • A discussion of the topics

• A set of exercises to reinforce the topics presented in the discussion Several lessons in this manual include optional and challenge exercise sections.

• A summary that outlines the important concepts and skills in the lesson

C. What You Need to Get Started

Before you use this course manual, make sure you have the following items: ❑ Computer running Windows 2000 or later; This course manual is

optimized for Windows XP

❑ LabVIEW Professional Development System 8.0 or later ❑ Spreadsheet application such as Microsoft Excel

❑ LabVIEW Intermediate II: Connectivity course CD, containing the following folders

Directory Description

Exercises Folder containing all the VIs and support files needed to complete the exercises in this course Solutions Folder containing the completed versions of the

(7)

D. Installing the Course Software

Complete the following steps to install the course software.

1. Insert the course CD in your computer. The LabVIEW Intermediate Course Material Setup dialog box appears.

2. Click the Next button.

3. Choose Typical setup type and click the Install button to begin the installation.

4. Click the Finish button to exit the Setup Wizard.

5. The installer places the Exercises and Solutions folders at the top level of the C:\ directory.

Repairing or Removing Course Material

You can repair or remove the course material using the Add or Remove Programs feature on the Windows Control Panel. Repair the course material to overwrite existing course material with the original, unedited versions of the files. Remove the course material if you no longer need the files on your machine.

E. Course Goals

This course presents the following topics: • Networking technologies

– External procedure call model – Broadcast model

– Client/server model – Publish/subscribe model

• Implementing the external procedure call model – Calling shared libraries from LabVIEW

– Programmatically controlling VIs using the VI Server

• Using the VI Server functions to programmatically load and operate VIs and LabVIEW itself

– Calling objects in LabVIEW using ActiveX • Using LabVIEW as an ActiveX client • Using LabVIEW as an ActiveX server • ActiveX events

– Calling Objects in LabVIEW using .NET • Using LabVIEW as a .NET client

(8)

LabVIEW Intermediate II Course Manual viii ni.com • .NET events

• Implementing the broadcast model

– Using the UDP VI and functions to create a UDP multicast session • Implementing the client/server model

– Using the TCP/IP VI and functions to communicate with other applications locally and over a network

• Implementing the publish/subscribe model

– Using the Shared Variable node to read, write, and share data among VIs and other applications locally and over a network

This course does not present any of the following topics:

Basic principles of LabVIEW covered in the LabVIEW Basics I: Introduction and LabVIEW Basics II: Development courses

Every built-in VI, function, or object; refer to the LabVIEW Help for more information about LabVIEW features not described in this course • Developing a complete VI for any student in the class; refer to the

NI Example Finder, available by selecting Help»Find Examples, for example VIs you can use and incorporate into VIs you create

F. Course Conventions

The following conventions are used in this course manual:

» The » symbol leads you through nested menu items and dialog box options

to a final action. The sequence File»Page Setup»Options directs you to pull down the File menu, select the Page Setup item, and select Options from the last dialog box.

This icon denotes a tip, which alerts you to advisory information. This icon denotes a note, which alerts you to important information. This icon denotes a caution, which advises you of precautions to take to avoid injury, data loss, or a system crash.

bold Bold text denotes items that you must select or click in the software, such as menu items and dialog box options. Bold text also denotes parameter names, controls and buttons on the front panel, dialog boxes, sections of dialog boxes, menu names, and palette names.

italic Italic text denotes variables, emphasis, a cross reference, or an introduction

to a key concept. Italic text also denotes text that is a placeholder for a word or value that you must supply.

(9)

monospace Text in this font denotes text or characters that you enter from the keyboard, sections of code, programming examples, and syntax examples. This font also is used for the proper names of disk drives, paths, directories, programs, subprograms, subroutines, device names, functions, operations, variables, filenames, and extensions.

monospace bold Bold text in this font denotes the messages and responses that the computer

automatically prints to the screen. This font also emphasizes lines of code that are different from the other examples.

platform Text in this font denotes a specific platform and indicates that the text following it applies only to that platform.

(10)
(11)

1

Calling Shared Libraries in LabVIEW

You can use LabVIEW to call code written in other languages in the following ways:

• Using platform-specific protocols.

• Using the Call Library Function Node to call the following types of shared libraries:

– Dynamic Link Libraries (DLL) on Windows

– Frameworks on Mac OS

– Shared Libraries on Linux

The scope of this course covers using the Call Library Function Node to call Dynamic Link Libraries (shared libraries) on Windows. Refer to the LabVIEW Help for information about other ways to use LabVIEW to call code written in other languages.

Topics

A. Shared Library Overview B. Calling Shared Libraries

(12)

LabVIEW Intermediate II Course Manual 1-2 ni.com

A. Shared Library Overview

On Windows, a shared library is called a DLL. A shared library is a library of executable functions or data that can be used by a Windows application. Typically, a shared library provides one or more particular functions that a program can access by creating a static or dynamic link to the shared library. A static link remains constant during program execution and a dynamic link is created by the program as needed. The library is stored as a binary file. You can use any language to write DLLs as long as the DLLs can be called using one of the calling conventions LabVIEW supports, either stdcall or C. Examples and troubleshooting information help you build and use DLLs and to successfully configure the Call Library Function Node in LabVIEW. The general methods described here for DLLs also apply to other types of shared libraries.

Refer to the labview\examples\dll directory for examples of using shared libraries.

B. Calling Shared Libraries

This section describes the process of using a DLL in LabVIEW.

Describing and Defining Shared Libraries

You can call most standard shared libraries with the Call Library Function Node. On Windows, these shared libraries are DLLs, on Mac OS, they are Frameworks, and on Linux, they are Shared Libraries. The Call Library Function Node includes a large number of data types and calling

conventions. You can use the Call Library Function Node to call functions from most standard and custom-made libraries.

Functions, Advantages, and Limitations of DLLs

DLLs have the following advantages:

• You can change the DLL without changing any of the VIs that link to the DLL, provided you do not modify the function prototypes.

• Practically all modern development environments provide support for creating DLLs.

The Call Library Function Node is most appropriate when you have existing code you want to call, or if you are familiar with the process of creating standard shared libraries. Because a library uses a format standard among several development environments, you can use almost any development environment to create a library that LabVIEW can call. Refer to the documentation for your compiler to determine whether you can create standard shared libraries.

(13)

The LabVIEW compiler can generate code fast enough for most

programming tasks. Call shared libraries from LabVIEW to accomplish tasks a text-based language can accomplish more easily, such as time-critical tasks. Also use shared libraries for tasks you cannot perform directly from the block diagram, such as calling system routines for which no corresponding LabVIEW functions exist. Shared libraries also can link existing code to LabVIEW, although you might need to modify the code so it uses the correct LabVIEW data types.

Shared libraries execute synchronously, so LabVIEW cannot use the execution thread used by these objects for any other tasks. When a VI runs, LabVIEW monitors the user interface, including the menus and keyboard. In multithreaded applications, LabVIEW uses a separate thread for user interface tasks. In single-threaded applications, LabVIEW switches between user interface tasks and running VIs.

When shared library object code executes, it takes control of its execution thread. If an application has only a single thread of control, the application waits until the object code returns. In single-threaded operating systems such as Mac OS, shared libraries even prevent other applications from running.

LabVIEW cannot interrupt object code that is running, so you cannot reset a VI that is running a shared library until execution completes. If you want to write a shared library that performs a long task, be aware that LabVIEW cannot perform other tasks in the same thread while these objects execute.

Method for Calling Shared Libraries

Use the Call Library Function Node to directly call a 32-bit Windows DLL, a Mac OS Framework, or a Linux Shared Library function. With this node, you can create an interface in LabVIEW to call existing libraries or new libraries specifically written for use with LabVIEW. National Instruments recommends using the Call Library Function Node to create an interface to external code.

Note Be aware when using the Call Library Function Node or writing code that is called by the Call Library Function Node that LabVIEW reserves Windows messages

WM_USER through WM_USER+99 for internal use only.

Right-click the Call Library Function Node and select Configure from the shortcut menu to open the Call Library Function dialog box, shown in the following figure. Use the Call Library Function dialog box to specify the library, function, parameters, return value for the object, and calling conventions on Windows. When you click OK in the Call Library Function dialog box, LabVIEW updates the Call Library Function Node

(14)

LabVIEW Intermediate II Course Manual 1-4 ni.com according to your settings, displaying the correct number of terminals and setting the terminals to the correct data types.

As you configure parameters, the Function Prototype text box displays the C prototype for the function you are building. This text box is a read-only display.

Setting the Calling Convention

Use the Calling Conventions pull-down menu in the Call Library Function dialog box to select the calling convention for the function. The default calling convention is C.

(Windows) You also can use the standard Windows calling convention, stdcall.

Refer to the documentation for the DLL you want to call for the appropriate calling conventions.

Configuring Parameters

Initially, the Call Library Function Node has no parameters and has a return type of Void. The return type for the Call Library Function Node returns to the right terminal of the top pair of terminals. If the return type is Void, the top pair of terminals is unused. Each additional pair of terminals

(15)

Function Node. To pass a value to the Call Library Function Node, wire to the left terminal of a terminal pair. To read the value of a parameter after the Call Library Function Node call, wire from the right terminal of a terminal pair. The following figure shows a Call Library Function Node that has a return type of Void, a string parameter, and a numeric parameter.

Return Type

For return type, you can set Type to Void, Numeric, or String. Void is only available for return type and is not available for parameters. Use Void for the return type if your function does not return any values.

Even if the function you call returns a value, you can use Void for the return type. When the function returns a value and you select Void as the return type, the value returned by the function is ignored.

Note If the function you are calling returns a data type not listed, choose a return data type the same data size as the one returned by the function. For example, if the function returns a char data type, use an 8-bit unsigned integer. A call to a function in a DLL cannot return a pointer because there are no pointer types in LabVIEW. However, you can specify the return type as an integer that is the same size as the pointer. LabVIEW then treats the address as a simple integer, and you can pass it to future DLL calls.

Adding and Deleting Parameters

To add parameters to the Call Library Function Node, click the Add a Parameter Before button or the Add a Parameter After button. To remove a parameter, click the Delete this Parameter button.

Editing Parameters

Use the Parameter pull-down menu to select the return value or a parameter for editing. When selected, you can edit the Parameter name to something more descriptive, which makes it easier to switch between parameters. The Parameter name does not affect the call, but it is propagated to output wires. Also, you can edit all fields in the Parameter section for the selected parameter.

(16)

LabVIEW Intermediate II Course Manual 1-6 ni.com Selecting the Parameter Type

Use the Type pull-down menu to indicate the type of each parameter. You can select from the following parameter types:

NumericArrayStringWaveformDigital WaveformDigital DataActiveXAdapt to Type

After you select an item from the Type pull-down menu, you see more items you can use to indicate details about the parameter and about how to pass the data to the library function. The Call Library Function Node has a number of different items for parameter types because of the variety of data types required by different libraries. Refer to the documentation for the library you call to determine which parameter types to use.

The following sections discuss the different parameter types available from the Type pull-down menu.

(Windows) Refer to the labview\examples\dll\data passing\Call Native Code.llb for an example of using data types in shared libraries.

Numeric

For numeric data types, you must indicate the exact numeric type by using the Data Type pull-down menu. You can choose from the following data types:

• 8-, 16-, 32-, and 64-bit signed and unsigned integers • 4-byte, single-precision numbers

• 8-byte, double-precision numbers

Note Extended-precision numbers and complex numbers can be passed by selecting Adapt to Type from the Type pull-down menu. However, standard libraries generally do not use extended-precision numbers and complex numbers.

Use the Pass pull-down menu to indicate whether you want to pass the value or a pointer to the value.

(17)

Array

Use the Data Type pull-down menu to indicate the data type of the array. You can choose from the same data types available for numeric parameters. Specify the dimensions of the array in Dimension.

Use the Array Format pull-down menu to make one of the following choices:

Array Data Pointer passes a one-dimensional pointer to the array data.Array Handle passes a pointer to a pointer that points to a four-byte

value for each dimension, followed by the data.

Array Handle Pointer passes a pointer to an array handle.

Note Do not attempt to resize an array with system functions, such as realloc. Doing so might crash your system. Instead, use one of the Code Interface Node (CIN) manager functions, such as NumericArrayResize.

String

Use the String Format pull-down menu to indicate the string format. You can choose from the following string formats:

C String Pointer—a string followed by a null characterPascal String Pointer—a string preceded by a length byteString Handle—a pointer to a pointer to four bytes for length

information, followed by string data

String Handle Pointer

Select a string format that the library function expects. Most standard libraries expect either a C string or a Pascal string. If the library function you are calling is written for LabVIEW, you might want to use the string handle format.

Note Do not attempt to resize a string with system functions, such as realloc, because your system might crash.

String Options

LabVIEW stores strings as arrays, that is, structures pointed to by handles. The Call Library Function Node works with C and Pascal-style string pointers or LabVIEW string handles. The following illustration shows an example of a LabVIEW string handle.

(18)

LabVIEW Intermediate II Course Manual 1-8 ni.com Think of a string as an array of characters. Assembling the characters in order forms a string. LabVIEW stores a string in a special format in which the first four bytes of the array of characters form a 32-bit signed integer that stores how many characters appear in the string. Thus, a string with n characters requires n + 4 bytes to store in memory. For example, the string text contains four characters. When LabVIEW stores the string, the first four bytes contain the value 4 as a 32-bit signed number, and each of the following four bytes contains a character of the string. The advantage of this type of string storage is that NULL characters are allowed in the string. Strings are virtually unlimited in length, up to 231 characters.

The Pascal string format is nearly identical to the LabVIEW string format, but instead of storing the length of the string as a 32-bit signed integer, it is stored as an 8-bit unsigned integer. This limits the length of a Pascal-style string to 255 characters. A graphical representation of a Pascal string appears in the following illustration. A Pascal string that is n characters long requires n + 1 bytes of memory to store.

C strings are probably the type of strings you deal with most often. The similarities between the C-style string and normal numeric arrays in C becomes much clearer when you notice that C strings are declared as char *. C strings do not contain any information that directly indicate the length of the string, as do the LabVIEW and Pascal strings. Instead, C strings use a special character, called the NULL character, to indicate the end of the string, as shown in the following illustration. NULL has a value of zero in the ASCII character set. Notice that this is the number zero and not the character 0.

String Data t \04 t e x \00 \00 \00 String Length String Length String Data t \04 t e x

(19)

Thus, in C, a string containing n characters requires n + 1 bytes of memory to store, n bytes for the characters in the string and one additional byte for the NULL termination character. The advantage of C-style strings is that they are limited in size only by available memory. However, if you are acquiring data from an instrument that returns numeric data as a binary string, as is common with serial or GPIB instruments, values of zero in the string are possible. For binary data where NULLs might be present, you should use an array of 8-bit unsigned integers. If you treat the string as a C-style string, the program assumes incorrectly that the end of the string has been reached, when in fact the instrument is returning a numeric value of zero.

Waveform

When you call a shared library that includes a waveform data type, you do not have to specify a numeric value from the Data Type pull-down menu; the default is 8-byte double. However, you must specify a Dimension. If the Parameter is a single waveform, specify a Dimension of 0. If the

Parameter is an array of waveforms, specify a Dimension of 1. LabVIEW does not support an array of waveforms greater than 1D.

Digital Waveform

Specify a Dimension of 0 if the Parameter is a single digital waveform. Specify a Dimension of 1 if the Parameter is an array of digital waveforms. LabVIEW does not support an array of digital waveforms greater than 1D.

Digital Table

Specify a Dimension of 1 if the Parameter is an array of digital data. Otherwise, specify a Dimension of 0. LabVIEW does not support an array of digital data greater than 1D.

Note You can pass waveforms, digital waveforms, and digital data through shared libraries, but accessing the data inside the shared libraries is not supported at this time.

NULL Character

String Data

t \00

(20)

LabVIEW Intermediate II Course Manual 1-10 ni.com

ActiveX

Select one of the following items from the Data Type pull-down menu: ActiveX Variant Pointer passes a pointer to ActiveX data.

IDispatch* Pointer passes a pointer to the IDispatch interface of an ActiveX Automation server.

IUnknown Pointer passes a pointer to the IUnknown interface of an ActiveX Automation server.

Adapt to Type

Use Adapt to Type to pass arbitrary LabVIEW data types to DLLs. The arbitrary LabVIEW data types are passed to DLLs in the following ways: • Scalars are passed by reference. A pointer to the scalar is passed to the

library.

Arrays and strings are passed according to the Data Format setting. You can choose from the following Data Format settings:

Handles by Value passes the handle to the library. The handle is not NULL.

Pointers to Handles passes a pointer to the handle to the library. If the handle is NULL, treat the handle as an empty string or array. To set a value when the handle is NULL, you must allocate a new handle.

• Clusters are passed by reference.

• Scalar elements in arrays or clusters are in line. For example, a cluster containing a numeric is passed as a pointer to a structure containing a numeric.

• Clusters within arrays are in line.

• Strings and arrays within clusters are referenced by a handle.

Note When one or more of the parameters of the function you want to call in a DLL are of types that do not exist in LabVIEW, ensure that each parameter is passed to the function in a way that allows the DLL to correctly interpret the data. Create a skeleton .c file from the current configuration of the Call Library Function Node. By viewing the .c file, you can determine whether LabVIEW passes the data in a manner compatible with the DLL function. You then can make any necessary adjustments.

Working with Unusual Data Types

You might encounter a function that expects data in a form that the Call Library Function Node cannot pass. Specifically, the Call Library Function Node does not support structures or arrays containing a pointer to other data or structures containing flat arrays that can be variably sized. You can call a function that expects an unsupported data type in the following ways:

(21)

• If the data contains no pointers, you might be able to use the Flatten to String function to create a string containing the binary image of the data required and pass this string as a C string pointer. You will probably want to use the byte order input to Flatten to String to specify that the data be flattened in native byte order.

• Write a library function that accepts the data in the form used by LabVIEW and builds the data structure expected by the other library. This function can then call the other library and retrieve any returned values before returning. Your function will probably accept the data from the diagram as adapt to type, so that any diagram data type can be passed.

Thread-Safe and Thread-Unsafe DLLs

In a multithreaded operating system, you can make multiple calls to a DLL or shared library simultaneously. By default, all call library objects run in the user interface thread. The control below the Browse button in the Call Library Function dialog box reflects your selection of Run in UI Thread or Reentrant.

Before you configure a Call Library Function Node to be reentrant, make sure that multiple threads can call the function simultaneously. The

following characteristics are the basic characteristics of thread safe code in a shared library:

• The code is thread safe when it does not store any global data, such as global variables, files on disk, and so on.

• The code is thread safe when it does not access any hardware. In other words, the code does not contain register-level programming.

• The code is thread safe when it does not make any calls to any functions, shared libraries, or drivers that are not thread safe.

• The code is thread safe when it uses semaphores or mutexes to protect access to global resources.

• The code is thread safe when it is called by only one non-reentrant VI. Refer to the Execution Properties Page topic of the LabVIEW Help for more information about reentrancy. Refer to the Benefits of Multithreaded Applications topic of the LabVIEW Help for more information about multithreading in LabVIEW.

(22)

LabVIEW Intermediate II Course Manual 1-12 ni.com

Exercise 1-1

Computer Name

Goal

Call a DLL function from the Windows API.

Scenario

Programmatically determining the Windows computer name is necessary in a number of situations. For example, if you have several computers logging data to a central server, you should identify the computer name for each set of data in order to track the data. The computer name is also helpful for storing or retrieving data over a Windows File Share and is a useful piece of information to include when generating reports.

There is not a native function within LabVIEW to retrieve the computer name. However, the Windows operating system provides an API, in the form of DLLs, which allows you to interface with the operating system. One common use of this API is retrieving useful information about the operating system or computer, such as the computer name.

Call a Windows API DLL function to determine the name of the computer. You should also handle any errors returned by the function in an appropriate manner.

Note The Windows computer name is different from the network address of a computer. You can determine a computer’s network address in LabVIEW by using the String to IP and IP to String functions located on the TCP/IP palette.

Design

Inputs and Outputs

Program Structure

When you call a DLL in LabVIEW, any error handling must be performed manually. Therefore Call Library Function nodes do not have error cluster inputs and outputs. Because you cannot wire error clusters to enforce dataflow between nodes, you must use other data wires or structures to

Table 1-1. Computer Name Inputs and Outputs

Type Name Properties Default Values

Numeric Control Buffer Size 32-bit Unsigned

Integer

256

(23)

control the execution order of your program. The best structure for controlling execution order is a state machine, as it allows you better decision making and error handling strategies than a Sequence structure.

State Machine Design

For this program you utilize a state machine with three states: Get Computer Name, Handle Error and Stop. The first state gets the computer name. If the state succeeds, the program moves to the Stop state and finishes. If the DLL call to get the computer name fails, the program enters the Handle Error state, where it accesses an error code and translates the error code into an error message.

Get Computer Name Case

The Windows API provides a function called GetComputerName in Kernel32.dll. In order to call this function in LabVIEW, you need to allocate a string buffer large enough to hold the computer name. Use the byte array method described in the String Options section of this lesson to allocate the buffer. If the buffer is too small to store the computer name, or if another error occurs, this function returns a value of zero. Use the return value from this function to control the transition logic of the state machine. Handle Errors Case

In order to provide a meaningful error message for Windows API calls, you need to perform two steps. First, you must call the Windows API function GetLastError. This function returns a numeric value that represents any error encountered during the last function call, in this case,

GetComputerName. In order to translate the numeric code into a meaningful message, you must call the FormatMessage Windows API function. You can use this function many different ways. Control the behavior of the function by setting one or more flags in a parameter called dwFlags. In order to return a message for a system error, set the

FORMAT_MESSAGE_FROM_SYSTEMflag. Also set the

FORMAT_MESSAGE_IGNORE_INSERTS flag because you do not need to include any additional parameters in your message. Setting this parameter also allows you to ignore the arguments parameter of the function, thereby simplifying the function call. For more information on setting flags, refer to the Background: Windows API Reference section.

Tip All of the functions called in this exercise are in kernel32.dll. However, Windows API functions are found in many other DLLs. Refer to the Windows API Reference to determine in which DLL a given function is located.

Stop Case

The stop case simply finishes the state machine, thereby ending the While Loop and the program.

(24)

LabVIEW Intermediate II Course Manual 1-14 ni.com

Additional Information

The following sections describe some issues particular to Windows API calls that you must address in order to implement a solution.

Background: Windows API Reference

You can find the Windows API definitions for each of the functions used in this exercise in the C:\Exercises\LabVIEW Intermediate II\ Computer Name directory. Open each of the PDF files in this directory and browse the reference material in them. As you proceed through the exercise, refer to the references periodically to identify the meaning of each

parameter you pass to the functions.

Note The function information in these PDF files is from the Windows API Reference in the MSDN library. You can access the full Windows API Reference at:

http://msdn.microsoft.com/library/en-us/winprog/winprog/ windows_api_reference.asp.

Bit Masked Flags

Some functions in the API contain a flags parameter that allows you to enable one or more options by masking the bits in an integer. The dwFlags parameter of the FormatMessage function is an example of this technique. In order to set a flag in LabVIEW, pass an integer constant with the

appropriate size and value to the Call Library Function node. Remember that you can change the way a numeric constant is represented to make it easier to enter the flag value. For example, the specification for the

FormatMessage function gives the flags in hexadecimal format, you can set the format of your numeric constant to hexadecimal and then enter the value directly.

If you need to set multiple flags in a flags parameter, you can use a Bitwise Or to combine multiple flags. In LabVIEW, the Or function is a

polymorphic function which automatically becomes a Bitwise Or if you wire two integers to it.

Data Types

Windows API and other DLL function specifications often refer to many data types which have different names in LabVIEW. The following table lists LabVIEW types for some of the Windows data types used in this exercise. For a more complete list, the Call DLL example in the NI Example Finder provides a complete data type conversion list, as well as examples for each data type. The Windows Data Type reference is also a useful reference, it can be found at: http://msdn.microsoft.com/library/en-us/ winprog/winprog/windows_data_types.asp.

(25)

String Types

Many Windows API functions support two methods for representing strings. The first method is ASCII, in which each character in a string is represented by a single character. Traditional ASCII has a 128 character set, which contains all of the upper and lowercase letters, as well as other common symbols and a set of control characters. LabVIEW typically uses ASCII to represent strings.

The second method uses “wide” strings, which is another term for Unicode string representation (UTF-16 encoding). Unicode requires two bytes for each character, and allows for a much larger character set than traditional ASCII. Unicode is not natively supported in LabVIEW, but it is possible to use Unicode through add on libraries or calls to external functions.

Windows API functions which deal with strings often have two versions present in the DLL, marked with an “A” for ASCII and a “W” for wide. For example, there are two GetComputerName functions in kernel32.dll, GetComputerNameA and GetComputerNameW. In most cases, you should use the “A” version of the function in LabVIEW.

Implementation

1. Create the front panel shown in Figure 1-1.

Figure 1-1. Computer Name Front Panel Table 1-2. Data Type Conversion

Windows Data Type LabVIEW Data Type

LPTSTR String (Pass as C String Pointer)

DWORD U32

LPDWORD U32 (Pass by pointer)

BOOL I32

va_list* Varies (Use Adapt to Type)

(26)

LabVIEW Intermediate II Course Manual 1-16 ni.com ❑ Create a blank VI and save the VI as Computer Name.vi in the

C:\Exercises\LabVIEW Intermediate II\Computer Name directory.

❑ Create the Buffer Size control as described in Table 1-1.

❑ Create the Computer Name indicator as described in Table 1-1. 2. Create a type defined enumerated type control to control the state

machine.

❑ Place an enum control on the front panel. ❑ Label the enum Computer Name.

❑ Right-click the Computer Name control and select Advanced» Customize from the shortcut menu to open the Control Editor. ❑ Right-click the control and select Edit Items from the shortcut

menu.

❑ Enter the items as shown in Figure 1-2 and click the OK button.

Figure 1-2.

(27)

❑ Save the control as Computer Name.ctl in the C:\Exercises\ LabVIEW Intermediate II\Computer Name directory. ❑ Close the Control Editor and click Yes when prompted to replace the

original with the customized control.

❑ From the block diagram, right-click the Computer Name control and select Change to Constant from the shortcut menu.

❑ Set the value of the Computer Name constant to Get Computer Name.

3. Build a state machine to control the program as shown in Figure 1-3.

Figure 1-3. State Machine

❑ Place a While Loop on the block diagram. ❑ Place a Case structure inside the While Loop.

❑ Wire the Computer Name constant to the case selector terminal through a shift register on the While Loop.

❑ Right-click the Case structure and select Add Case for Every Value from the shortcut menu to add a case for every value in the

Computer Name control.

❑ Wire the Buffer Size control to the state machine as shown in Figure 1-3.

(28)

LabVIEW Intermediate II Course Manual 1-18 ni.com 4. Call the GetComputerName function.

❑ Open the GetComputerName function reference from C:\Exercises\LabVIEW Intermediate II\

Computer Name\getcomputername.pdf and identify the prototype and parameters for the function.

❑ Place a Call Library Function Node in the Get Computer Name case of the Case structure.

❑ Double-click the Call Library Function Node to open the Call Library Function dialog box.

❑ Click the Browse button and navigate to C:\WINDOWS\ system32\kernel32.dll.

❑ Select GetComputerNameA from the Function Name pull-down menu.

❑ Select Reentrant from the Run in UI Thread pull-down menu.

Note Because the Windows API functions are reentrant (multi-threaded), calling GetComputerName in UI thread functions correctly, except the error is not stored in the proper memory location for GetLastError to access it.

❑ Select stdcall (WINAPI) from the Calling Conventions pull-down menu.

❑ Leave parameter set to return type.

❑ Select Numeric from the Type pull-down menu. ❑ Click the Add a Parameter After button. ❑ Enter lpBuffer in the Parameter text box. ❑ Select String from the Type pull-down menu. ❑ Click the Add a Parameter After button. ❑ Enter lpnSize in the Parameter text box. ❑ Select Numeric from the Type pull-down menu.

❑ Select Unsigned 32-bit Integer from the Data Type pull-down menu.

(29)

❑ Confirm that the function prototype matches Figure 1-4. ❑ Click the OK button.

Figure 1-4. GetComputerName Call Library Function

5. Create the Get Computer Name case as shown in Figure 1-5.

Figure 1-5. Get Computer Name Case

❑ Place a numeric constant with a representation of U8 in the Get Computer Name case. Label the constant Byte.

❑ Place an Initialize Array function in the Case structure. ❑ Place a Byte Array To String function in the Case structure. ❑ Place an Equal To 0? function in the Case structure.

(30)

LabVIEW Intermediate II Course Manual 1-20 ni.com ❑ Place a Select function in the Case structure.

❑ Place the Computer Name indicator inside the Case structure. ❑ Create two constants from the enum terminal on the right side of the

Case structure. Set one value to Stop and the other to Handle Error. ❑ Place a False constant inside the Case structure.

❑ Wire the case as shown in Figure 1-5. 6. Call the GetLastError function

❑ Open the GetLastError function reference from C:\Exercises\LabVIEW Intermediate II\

Computer Name\getlasterror.pdf and identify the prototype and parameters for the function.

❑ Place a Call Library Function Node in the Handle Error case. ❑ Double-click the Call Library Function Node to open the Call

Library Function dialog box.

❑ Click the Browse button and select C:\WINDOWS\system32\ kernel32.dll.

❑ Select GetLastError from the Function Name pull-down menu. ❑ Select Reentrant from the Run in UI Thread pull-down menu. ❑ Select stdcall (WINAPI) from the Calling Conventions pull-down

menu.

❑ Select Numeric from the Type pull-down menu.

❑ Select Unsigned 32-bit Integer from the Type pull-down menu. ❑ Confirm that the function prototype matches Figure 1-6.

(31)

Figure 1-6. GetLastError Call Library Function

7. Call the FormatMessage function.

❑ Open the FormatMessage function reference from C:\Exercises\LabVIEW Intermediate II\

Computer Name\formatmessage.pdf and identify the prototype and parameters for the function.

❑ Place a Call Library Function Node in the Handle Error case. ❑ Double-click the Call Library Function Node to open the Call

Library Function dialog box.

❑ Click the Browse button and select C:\WINDOWS\system32\ kernel32.dll.

❑ Select FormatMessageA from the Function Name pull-down menu.

❑ Select Reentrant from the Run in UI Thread pull-down menu. ❑ Select stdcall (WINAPI) from the Calling Conventions pull-down

menu.

❑ Select Numeric from the Type pull-down menu.

❑ Select Unsigned 32-bit Integer from the Type pull-down menu. ❑ Click the Add a Parameter After button.

(32)

LabVIEW Intermediate II Course Manual 1-22 ni.com ❑ Enter dwFlags in the Parameter text box.

❑ Select Unsigned 32-bit Integer from the Type pull-down menu. ❑ Click the Add a Parameter After button.

❑ Enter lpSource in the Parameter text box.

❑ Select Adapt to Type from the Type pull-down menu.

❑ Select Pointers to Handles from the Data Format pull-down menu.

❑ Click the Add a Parameter After button. ❑ Enter dwMessageId in the Parameter text box.

❑ Select Unsigned 32-bit Integer from the Type pull-down menu. ❑ Click the Add a Parameter After button.

❑ Enter dwLanguageId in the Parameter text box.

❑ Select Unsigned 32-bit Integer from the Type pull-down menu. ❑ Click the Add a Parameter After button.

❑ Enter lpBuffer in the Parameter text box. ❑ Select String from the Type pull-down menu. ❑ Click the Add a Parameter After button. ❑ Enter nSize in the Parameter text box.

❑ Select Unsigned 32-bit Integer from the Type pull-down menu. ❑ Click the Add a Parameter After button.

❑ Enter Arguments in the Parameter text box.

❑ Select Adapt to Type from the Type pull-down menu.

❑ Select Pointers to Handles from the Data Format pull-down menu.

❑ Confirm that the function prototype matches Figure 1-7. ❑ Click the OK button.

(33)

Figure 1-7. FormatMessage Call Library Function

Note The terminals corresponding to the arguments with type Void are blank until wired because void parameters accept any type of data

8. Create the Handle Error case shown in Figure 1-8.

Figure 1-8. Handle Error Case

❑ Place a numeric constant with a representation of U8 in the Handle Error case. Label the constant Byte.

❑ Place a numeric constant with a representation of I32 in the Case structure. Label the constant String Size.

(34)

LabVIEW Intermediate II Course Manual 1-24 ni.com ❑ Place an Initialize Array function in the Case structure.

❑ Place a Byte Array To String function in the Case structure. ❑ Place a numeric constant with a representation of U32 in the Case

structure. Label the constant Null Value. ❑ Place an Or function in the Case structure.

❑ Create a constant from the enum terminal on the right side of the Case structure and set the value to Stop.

❑ Place a False constant inside the Case structure.

❑ Place a numeric constant with a representation of U32 in the Case structure.

❑ Right-click the numeric constant and select Format and Precision from the shortcut menu.

❑ Configure the constant as shown in Figure 1-9.

Figure 1-9. Numeric Constant Properties

❑ Set the value of the constant to 00000200. ❑ Label the constant Ignore Arguments.

(35)

❑ Create a copy of the Ignore Arguments constant.

❑ Change the label of the new constant to System Message. ❑ Set the value of the System Message constant to 00001000. ❑ Place a One Button Dialog function in the Case structure. ❑ Wire the case as shown in Figure 1-8.

9. Create the Stop case as shown in Figure 1-10.

Figure 1-10. Stop Case

❑ Select the Stop case of the Case structure.

❑ Create a constant from the enum tunnel on the right side of the Case structure and set the value to Stop.

❑ Create a constant from the stop tunnel on the right side of the Case structure and set the value to True.

10. Save the VI.

Testing

1. Test the VI with an appropriate buffer size. ❑ Switch to the front panel of the VI.

❑ Run the VI with the default Buffer Size (256).

❑ The name of your computer should display in the Computer Name indicator.

(36)

LabVIEW Intermediate II Course Manual 1-26 ni.com 2. Verify that the correct computer name displays.

❑ Locate My Computer on the desktop of your computer or in Windows Explorer.

❑ Right-click My Computer and select Properties from the shortcut menu.

❑ Select the Computer Name tab and verify that the Full Computer Name matches the value the VI returns.

Note The case of the names does not need to match. 3. Test the error handling in the VI.

❑ Set the Buffer Size control to 1 and run the VI.

❑ Verify that the VI displays The file name is too long. as an

error message.

Tip The error message that displays for this VI is the description for the Windows error message ERROR_BUFFER_OVERFLOW (System Error 111). Refer to

http://msdn.microsoft.com/library/en-us/debug/base/

system_error_codes.asp for more information about system error codes and their descriptions.

(37)

Summary

• Dynamic linking is a mechanism that links applications to libraries at run time.

• The Call Library Function Node offers easy access to DLLs. • To call a function in a DLL, you need to know the following:

– The calling convention used.

– The data type returned by the function.

– The parameters to be sent to the function, their types, and the order in which they must be passed.

– The location of the DLL on the computer.

– Whether the function can be called safely by multiple threads simultaneously.

(38)

LabVIEW Intermediate II Course Manual 1-28 ni.com

(39)

2

VI Server

You can access the VI Server through block diagrams, ActiveX technology, and the TCP protocol to communicate with VIs and other application instances so you can programmatically control VIs and LabVIEW. You can perform VI Server operations on a local computer or remotely across a network.

Topics

A. What is VI Server?

B. VI Server Programming Model C. VI Server Functions

D. Remote Communication

(40)

LabVIEW Intermediate II Course Manual 2-2 ni.com

A. What is VI Server?

The VI Server is an object-oriented, platform-independent technology that provides programmatic access to LabVIEW and LabVIEW applications. Use the VI Server to perform the following programmatic operations: • Call a VI remotely.

• Configure a LabVIEW application instance to be a server that exports VIs you can call from other instances of LabVIEW on the Web. For example, if you have a data acquisition application that acquires and logs data at a remote site, you can sample that data occasionally from your local computer. By changing your LabVIEW preferences, you can make some VIs accessible on the Web so that transferring the latest data is as easy as a subVI call. The VI Server handles the networking details. The VI Server also works across platforms, so the client and the server can run on different platforms.

• Edit the properties of a VI and LabVIEW. For example, you can dynamically determine the location of a VI window or scroll a front panel so that a part of it is visible. You also can programmatically save any changes to disk.

• Update the properties of multiple VIs rather than manually using the File»VI Properties dialog box for each VI.

• Retrieve information about an application instance, such as the version number and edition. You also can retrieve environment information, such as the platform on which LabVIEW is running.

• Dynamically load VIs into memory when another VI needs to call them, rather than loading all subVIs when you open a VI.

• Create a plug-in architecture for the application to add functionality to the application after you distribute it to customers. For example, you might have a set of data filtering VIs, all of which take the same parameters. By designing the application to dynamically load these VIs from a plug-in directory, you can ship the application with a partial set of these VIs and make more filtering options available to users by placing the new filtering VIs in the plug-in directory.

• Control front panel objects.

VI Server Clients

The VI Server has a set of methods and properties that are accessible through the different clients, as shown in Figure 2-1. The different client interfaces are ActiveX Automation client, TCP/IP client, and LabVIEW functions that allow LabVIEW VIs to access the VI Server.

(41)

Figure 2-1. VI Server Clients

Block Diagram Access—LabVIEW includes a set of built-in functions

located on the Application Control palette you can use to access the VI Server on a local or remote computer.

Network Access—If you are using the VI Server on a remote computer, LabVIEW uses the TCP/IP protocol as the means of communication. • ActiveX Interface—ActiveX clients such as Visual Basic, Visual C++,

and Excel applications can use the VI Server to run LabVIEW applications.

Application and VI Objects

You access VI Server functionality through references to two main classes of objects—the Application object and the VI object. After you create a reference to one of these objects, you can pass the reference to a VI or function that performs an operation on the object.

An Application refnum refers to a local or remote application instance. You can use Application properties and methods to change LabVIEW

preferences and return system information. A VI refnum refers to a VI in an application instance.

With a refnum to an application instance, you can retrieve information about the LabVIEW environment, such as the platform on which LabVIEW is running, the version number, or a list of all VIs currently in memory. You also can set information, such as the list of VIs exported to other application instances.

When you create a refnum to a VI, LabVIEW loads the VI into memory. The VI stays in memory until you close the refnum, and the VI meets the following conditions:

• There are no other references to the VI. • The front panel of the VI is not open.

• The VI is not a subVI of another VI in memory. VI Server

ActiveX Interface Block

Diagram Functions TCP/IP

ActiveX

(42)

LabVIEW Intermediate II Course Manual 2-4 ni.com With a refnum to a VI, you can update all the properties of the VI available in the File»VI Properties dialog box as well as dynamic properties, such as the position of the owning pane. You also can programmatically print the VI documentation, save the VI to another location, and export and import its strings to translate into another language.

B. VI Server Programming Model

The programming model for VI Server applications is based on refnums. Refnums also are used in file I/O, network connections, and other objects in LabVIEW.

Typically, you open a refnum to an application instance or to a VI. You then use the refnum as a parameter to other VIs. The VIs get (read) or set (write) properties, execute methods, or dynamically load a referenced VI. Finally, you close the refnum, which releases the referenced VI from memory. Figure 2-2 illustrates the VI Server programming model.

Figure 2-2. VI Server Programming Model

Use the following general procedure to create a VI Server application. 1. (Optional) Configure the VI Server.

2. Use the Open VI Reference function to open a reference to a VI on the local or remote computer that already exists in memory for the

application instance, or to dynamically load a VI from disk.

Use the Open Application Reference function to open a reference to the local or remote application you are accessing through the server or to access a remote application instance.

3. Use the Property Node to get or set properties or the Invoke Node to get or set methods.

You also can use a Call By Reference Node to call a dynamically loaded VI. Create Reference to Object Operate on Properties or Methods Close Reference to Object Check for Errors

(43)

4. Use the Close Reference function to close any open references. 5. Check for errors.

C. VI Server Functions

Use the following Application Control functions and nodes to build VI Server applications:

Open Application Reference—Opens a reference to a local or remote

application instance.

Open VI Reference—Opens a reference to a VI on the local or remote computer or dynamically loads a VI from disk.

Property Node—Gets and sets VI, object, or application properties.Invoke Node—Invokes methods on a VI, object, or application.

Call By Reference Node—Calls a dynamically loaded VI.

Close Reference—Closes open references to the VI, object, or application you accessed using the VI Server.

Open Application Reference Function

The Open Application Reference function returns a reference to a VI Server application running on the specified computer. If you specify an empty string for machine name, it returns a reference to the local LabVIEW application in which this function is running. If you do specify a machine name, it attempts to establish a TCP connection with a remote VI Server on that machine on the specified port. You can use this function to get

references to global VIs and custom controls. machine name can be in dotted decimal notation, such as 123.23.45.100, or domain name notation, such as remotemachine.ni.com.

The port number input allows you to specify multiple servers on a single computer.

You use the application reference output as an input to Property Nodes and Invoke Nodes to get or set properties and invoke methods on the LabVIEW application. You also use application reference as the input to the Open VI Reference function to get references to VIs that are running in the LabVIEW application.

Open VI Reference Function

The Open VI Reference function returns a reference to a VI, control, or global variable specified by a name string or path to the location of the VI on disk.

(44)

LabVIEW Intermediate II Course Manual 2-6 ni.com You can get references to VIs in another LabVIEW application by wiring an application reference, obtained from the Open Application Reference function, to this function. If you leave the application reference input unwired, the Open VI Reference function refers to the local installation of LabVIEW.

Property Nodes

Use the Property Node to get and set various properties on an application or VI. Select properties from the node by using the Operating tool to click the property terminal or by right-clicking the white area of the node and selecting Properties from the shortcut menu.

You can read or write multiple properties using a single node. However, some properties are not readable and some are not writable. Use the Positioning tool to resize the Property Node to add new terminals. A small direction arrow to the right of the property indicates a property you read. A small direction arrow to the left of the property indicates a property you write. Right-click the property and select Change to Read or Change to Write from the shortcut menu to change the operation of the property. The node executes from top to bottom. The Property Node does not execute if an error occurs before it executes, so always check for the possibility of errors. If an error occurs in a property, LabVIEW ignores the remaining properties and returns an error. The error out cluster contains information about which property caused the error.

Invoke Nodes

Use the Invoke Node to perform actions, or methods, on an application or VI. Unlike the Property Node, a single Invoke Node executes only a single method on an application or VI. Select a method by using the Operating tool to click the method terminal or by right-clicking the white area of the node and selecting Methods from the shortcut menu. You also can create an Invoke Node by right-clicking the object, selecting Create»Invoke Node, and selecting a method from the shortcut menu.

Close Reference Function

The Close Reference function releases the application or VI reference. If you close a reference to a specified VI and there are no other references to that VI, LabVIEW can unload the VI from memory.

This function does not prompt you to save changes to the VI. By design, VI Server actions should avoid causing user interaction. You must use the Save:Instrument method to save the VI programmatically.

(45)

Note If you do not close the application or VI reference with this function, the reference closes automatically when the top-level VI associated with this function finishes execution. However, it is a good programming practice to conserve the resources involved in maintaining the connection by closing the reference when you finish using it.

Properties of the Application or VI Classes

Property Nodes are used to modify properties of the LabVIEW application or VI Object defined with the Open Application Reference or Open VI Reference function. There are different properties available in the Application Class and the VI Class.

Application Class Properties

Most Application Class properties are read only. They allow you to check a whole range of parameters, such as what VIs are loaded into memory, the operating system, and so on. The properties that can be written are for the printing options, which allow you to customize what prints and what does not print.

The following block diagram opens an application session to the local installation of LabVIEW and reads four properties of the LabVIEW application:

• The display properties of all the display monitors

• The name of the operating system, such as Windows 2000, Windows XP, and so on

• The version of the operating system

• Whether the LabVIEW Web Server is active

You can use this information to ensure that the computer running LabVIEW is configured correctly and prompt the user to reconfigure the computer if necessary.

(46)

LabVIEW Intermediate II Course Manual 2-8 ni.com

VI Object Properties

Many of the properties of the VI that are exposed correspond to the properties available in the VI Properties dialog box. You can access the VI Properties dialog box by selecting File»VI Properties. Most of the properties are read and write. Properties such as name, path, type, metrics, and so on are read only. Some properties are transient, such as window position, title, and so on.

Tip After you select a property, you can get help information about it by right-clicking the property and selecting Help for Property Name from the shortcut menu, where

Property Name is the name of the property.

Methods of the Application or VI Classes

Invoke Nodes are used to perform functions on the LabVIEW application or VI Object defined with the Open Application Reference or Open VI Reference function. There are different methods available in the Application Class and the VI Class.

Application Class Methods

When you place the Invoke Node on the block diagram you can access the Application class methods. You do not have to wire an Application reference to the Invoke Node to access the Application class methods because the node defaults to the current Application if reference is unwired. Some of the important methods available are Mass Compile, Get VI Version, Bring To Front, and so on. The Mass Compile method loads and compiles all the VIs in a directory and all its subdirectories. The Get VI Version method gets the version of LabVIEW in which the VI was last saved. The Bring To Front method brings the application windows to the front.

VI Object Methods

When you wire the VI reference to the Invoke Node, you can access the VI class methods.

Some of the important methods exported by the VI Server are Export VI Strings, Set Lock State, Run VI, Save Instrument, and so on. The Export VI Strings method exports strings pertaining to VI and front panel objects to a tagged text file. The Set Lock State method sets the lock state of a VI. The Run VI method starts VI execution. The Save:Instrument method saves a VI.

References

Related documents

In Chapter 3, motivated by applications in economics like quantile treatment ef- fects, or conditional stochastic dominance, we focus on the construction of confidence corridors

The first three foundations chapters are designed to provide information to the reader on nursing practice related to infusion therapy (nursing process ap- plied to infusion

of sheep from a farm in Onahau Bay continued for a while but soon the lower slopes of what had 

After the pre-test, the descriptive text was taught to the students by practicing the steps of Know, Want, and Learned (KWL) Strategy.. The social functions of a descriptive

Press the “Windows” key on the front panel to bring up the Windows START menu and then select Settings Control

This page allows user to configure the global PoE settings of the device and also displays current PoE status including Total PoE Power Budget, Power Used, Power Left and

► Manual control (including touch panel) or remote control (LabView). ► Modular architecture