Sunteți pe pagina 1din 30

Lesson 5 VI Server

You can access the VI Server through block diagrams, ActiveX technology, and the TCP protocol to communicate with VIs and other instances of LabVEW so you can programmatically control VIs and LabVIEW. You can perform VI Server operations on a local computer or remotely across a network. Typically, you open a refnum to an instance of LabVEW or to a VI and 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.

You Will Learn:


A. What the VI Server is and relevant object-oriented terminology

B. About the VI Server programming model


C. About the VI Server functions

D. How to implement remote communication using the VI Server E. How to dynamically call and load VIs F. The difference between strictly typed and weakly typed VI references

O National Instruments Corporation

LabVlEW Advanced Course Manual

Lesson 5

VI Server

A. What is VI Server?
The VI Server is an object-oriented, platform-independent technology that provides programmatic access to LabVIEW and LabVIEW applications. It allows you to perform the following operations: Call a VI remotely. Configure an instance of LabVIEW to be a server that exports VIs that 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 the data occasionally from your local computer. By changing your LabVIEW preferences, you can make some VIs accessible on the Web so transferring the latest data is as easy as a subVI call. 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 FilenVI Properties dialog box for each VI. Retrieve information about an instance of LabVIEW, such as the version number and edition. You also can retrieve environment information, such as the platform on which LabVIEW is running. For example, you can use this capability if you have an application that uses ActiveX and there is the possibility a user might try to run it on a non-Windows platform. The application could check if the operating system is Windows and if not generate an error message. Dynamically load VIs into memory when another VI needs to call them, rather than loading all subVIs when you open a VI. This is useful if you have a large application and want to save memory or startup time. 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 simply placing the new filtering VIs in the plug-in directory.

LabVlEWAdvanced Course Manual

Lesson 5

Vl Server

Object-Oriented Terminology
A class defines what an object is able to do, what operations it can perform (methods), what data it contains, and what properties it has, such as color, size, and so on. For example, a class could be Boolean, as shown in the following example.

Control Class Example Property: Visible Example Method: Attach DataSocket

Boolean Sub-class Example Property: Boolean Text

Array

Array SubClass Example Property: Number of Rows

Stop Object Visib1e:Yes Attach DataSocket: No Boolean Text: Stop

Object-oriented programming is based on objects. An object is a member of a class. For example, you could create an object called stop and it would be based on the class Boolean. Objects can have methods and properties. Methods are equivalent to functions, in that they perform an operation, such as generate a waveform. You also can pass parameters with the method, such as frequency, number of samples, and so on. Properties are the attributes of an object. The properties of a front panel could be its size, color, whether the scroll bars are visible, and so on. The following example shows a class called Person. This class contains data that gives details of a person, such as name, address, and so on. There are methods to set and get data, such as the name and address.
..............................................................
Methods: get-name() ; set-name() : get-address( ) set-address( )

Address

Object: Mark Doe

Name: Mark Doe Address: 102 West Street

O National instruments Corporation

LabVlEWAdvanced Course Manual

Lesson 5

VI Server

To use the class, you create an object and you could call it Mark Doe. Once you create the object, you can call the methods that set the data to what you require, such as name, address, and so on.

Note If you intend to use another programming language, such as Visual Basic, or Visual C++, refer to the documentation for the other programming language for more information about object-oriented programming.

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

Automation Client

TCPllP Client

Diagram Access-LabVIEW includes a set of built-in functions located on the FunctionsnAll FunctionsnApplication 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.

LabVlEWAdvanced Course Manual

Lesson 5

VI Server

Application and VI Objects


The VI Server is exposed through references to two classes of objects-the Application object and the VI object. These classes of objects allow you to perform operations using methods and properties. An Application Class reference refers to a local or remote LabVIEW environment. This is the actual LabVIEW application itself, not a program written using LabVIEW. The properties and methods of the LabVIEW Application object can, for example, change LabVIEW preferences and return system information. A Virtual Instrument class reference refers to a specific VI running in the LabVIEW application. For example, the properties and methods of the VI object can change the VI's execution and window options.

O National Instruments Corporation

LabVlEWAdvanced Course Manual

Lesson 5

VI Server

B. VI Server Programming Model


The VI Server programming model, shown in the following illustration, follows a convention similar to file 110 and network references.

Create Reference to Object


Open Application Reference

Operate on Properties or Methods


Property Node Property

Close Reference to Object


dose Reference

Check for Errors

Simple Error handler.^

Open V I Reference

Invoke Node Method

Use the following general procedure to build a VI Server application.

1. Create a reference to the Application object or VI object using the Open Application Reference function or the Open VI Reference function to ensure the correct resources are allocated and reserved.
2. Pass the reference to a Property Node or Invoke Node so the node knows which application or VI it is operating on.

3. Close the reference to release the object resources and check for errors.

Lab VIEW Advanced Course Manual

Lesson 5

Vl Server

C. VI Server Functions
The VI Server-related functions are located on the Functions>>All FunctionsnApplication Control palette.

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 1 2 3 . 2 3 . 4 5 . l o 0, 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 VI's location on disk. 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

El

The Property Node gets (reads) and/or sets (writes) properties of a reference. The Property Node automatically adapts to the class of the object that you reference. You can use Property Nodes to modify properties of the LabVIEW application or VI Object you define using the Open Application Reference function or Open VI Reference function. Once you wire the VI reference to the Property Node, you can access all the properties available for that Application or VI reference.

O National Instruments Corporation

LabVlEWAdvanced Course Manual

Lesson 5

VI Server

You can resize Property Nodes to have more than one input or output. To select whether a property reads or writes data, right-click the Property Node and select Change to Read or Change to Write from the shortcut menu. If a property is read-only, the Change to Write menu item is dimmed. Property Nodes execute from the top to the bottom. If an error occurs on a terminal, the node stops at that terminal, returns an error, and does not execute any further terminals.

Invoke Nodes

l4l

The Invoke Node invokes a method or action on a reference. Most methods have associated parameters. If the node is configured for VI Server Application class or Virtual Instrument class and reference is unwired, reference defaults to the current Application or VI. A single Invoke Node can execute only one method on an application or VI.

Close Reference Function


?s;/:+

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.

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.

LabVlEWAdvanced Course Manual

Lesson 5

Vl Server

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 NT, Windows 98, Mac OS, 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.

VI Object Properties
Many of the properties of the VI that are exposed correspond to the properties available in the File>>VI Properties dialog box. 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.

O National Instruments Cor~oration

LabVlEWAdvanced Course Manual

Lesson 5

VI Server

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. On Windows and Mac OS, the Bring To Front method brings the application windows to the front.
Tip After you select a method, you can get help information about it by right-clicking the method and selecting Help for Method Name from the shortcut menu, where Method Name is the name of the method.

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.

Tip After you select a method, you can get help information about it by right-clicking the method and selecting Help for Method Name from the shortcut menu, where Method Name is the name of the method.

LabVIEW Advanced Course Manual

Lesson 5

Vl Server

Exercise 5-1
Objective:

Setting Window Options VI

To complete and run a VI to set or reset properties of another VI through the VI Server interface.
Complete a VI that programmatically sets and resets the window option properties for another VI.

Front Panel
1. Open the Setting Window Options VI located in the c : \Exercises\ LabVIEW Advanced directory. The front panel of the VI is built for you.

Set or reset properties by clicking the buttons in the menu cluster. Click the Run Options Test VI button to run the Options Test VI.

If you do not click any buttons, no properties are set. Click a button to
set the corresponding property. For example, if you do not click any buttons, the Options Test VI is not sized to the screen, does not have a title bar, is not resizeable, does not have scroll bars, and does not have menu bars.

O National Instruments Corporation

LabVlEWAdvanced Course Manual

Q 1
Lesson 5 Vl Sewer

Block Diagram
2. Open the block diagram. Most of the block diagram has been completed for you. Complete the contents of the Case structure and other VI Server portions of the block diagram.

a a a

a a

a a a a a a a a a a

3. Open a VI reference to the Options Test VI located in the C :\Exercises\LabVIEW Advanced directory using the Open VI Reference function. Then use a Property Node to set the default states for these properties. Last, close the VI reference using the Close Reference function. In step 5, you build the Case structure.

a. Place the Open VI Reference function, located on the Functions,, All FunctionsnApplication Control palette, on the block diagram. This function returns a reference to a VI specified by a name string or path to the VI location on disk. This VI reference refers to the local version of LabVIEW.
b. Place a Property Node, located on the FunctionsnAll Functions,, Application Control palette, on the block diagram.

Right-click and select Change All to Write. Wire the vi reference output of the Open VI Reference function to the reference input of the Property Node. Resize the Property Node to have five properties. Right-click each property and select one of the following properties from the Properties>>Front Panel Window shortcut menu: Minimizeable, Title Bar Visible, Resizeable, Show Scroll Bars, and Show Menu Bar. In step 5, you will create a Case statement for each of these properties. c. Place the Close Reference function, located on the FunctionsnAll FunctionsvApplication Control palette, on the block diagram. This function releases the VI reference. Wire the VI reference and error cluster from the Property Node through the case structure to the Run Options Test VI.

LabVlEWAdvanced Course Manual

Lesson 5

Vl Server

From the Run Options Test VI, wire the VI reference and error cluster to the Close Reference VI.

4. Double-click the Run Options Test subVI to open it and examine the block diagram. This subVI opens the front panel of Options Test, runs Options Test, and then closes the front panel. Close the Run Options Test subVI.

5. Complete the contents of the Case structure. Each case executes when its corresponding Boolean control changes value.
a. Case -1-This structure. is the default case. Wire the tunnels across the Case

b. Case 0-Wire reference and error in to the Property Node as shown in the following illustration. Right-click the property terminal Panel Window>bMinimizeablefrom and select Property>>Front the shortcut menu. Right-click the node and select Change To Write from the shortcut menu. Wire the element output of the Index Array function to the property terminal.

c. Case 1-Wire reference and error in to the Property Node as shown in the following illustration. Right-click the property terminal and select Property>>Front Panel WindowmTitle Bar Visible from the shortcut menu. Right-click the node and select Change To Write from the shortcut menu. Wire the element output of the Index Array function to the property terminal.

I I I

O National Instruments Corporation

LabVlEWAdvanced Course Manual

Lesson 5

VI Server

d. Case 2-Wire reference and error in to the Property Node as shown in the following illustration. Right-click the property terminal and select Property>>Front Panel Window>>Resizeable from the shortcut menu. Right-click the node and select Change To Write from the shortcut menu. Wire the element output of the Index Array function to the property terminal.

e. Case 3-Wire reference and error in to the Property Node as shown in the following illustration. Right-click the property terminal and select PropertymFront Panel WindownShow Scroll Bars from the shortcut menu. Right-click the node and select Change to Write from the shortcut menu. Wire the element output of the Index Array function to the property terminal.

f. Case 4--Wire reference and error in to the Property Node as shown in the following illustration. Right-click the property terminal and select PropertynFront Panel WindownShow Menu Bars from the shortcut menu. Right-click the node and select Change To Write from the shortcut menu. Wire the element output of the Index Array function to the property terminal.

LabVlEW Advanced Course Manual

m
Cb

9 9

Lesson 5

V1 Server

m m

m m

e3

ra

6. Save the VI. 7. Display the front panel and run the VI. Click each button at least twice to check that all the properties set and reset correctly. After you click a property button, verify it by running the Options Test VI. Try all the properties. Try using the function keys to be sure that key navigation is set up properly. Click the QUIT button to stop the VI.
Note Make sure that you close the Options Test VI by clicking the OK button on its front panel before setting or resetting the next property.

ea

rb la Ib IB

8. Close the VI when you finish.

End of Exercise 5-1

m
b b b
b

m
b

I )

b b

m
b

e
I )

m
b b b

b
Ib D D

O National Instruments Corporation

LabVlEWAdvanced Course Manual

Lesson 5

Vl Server

D. Remote Communication
An important aspect of both the Application and VI references is their network transparency. You can open references to remote objects the same way you open references to those objects on local computers. For operations on remote objects, LabVIEW handles sending the information about the operation across the network and sending results back. The application should look virtually identical regardless of whether the operation is remote or local. To open an application reference to a remote version of LabVIEW, you must specify the machine name input of the Open Application Reference function. Then LabVIEW attempts to establish a TCP connection with a remote VI Server on that computer on the specified port.

Example-Accessing

a Remote VI Property
The following block diagram shows how to access the properties of a VI object on a remote computer. The Open Application Reference function opens a connection to a remote computer. The Open VI Reference function opens a VI on the specified remote computer. The Property Node opens the front panel of the specified VI. The Invoke Node runs the specified VI and waits for execution to complete before exiting the function. Because the Auto Dispose Ref is set to False, a Close Reference function must be used to release the reference and the parallel data space.

Open VI Reference Inputs


vi path accepts a string containing the name of the VI you are referencing, or a path containing the complete path to the VI you are referencing. The function loads the specified VI into memory, if it is not already open, and returns a reference to this VI. If you wire a name string, the VI must already be in memory. If you wire a path and a VI of the same name is already in memory, the function returns a reference to the open VI, regardless of whether its path is the same as the input. If the VI is not in memory, the VI must be at the specified path for this function to succeed.

LabVlEWAdvanced Course Manual

nb corn

Lesson 5

VI Server

application reference is a reference to a LabVIEW application.The default is a reference to an application on the local instance of LabVIEW. If wired and the reference is to a remote instance of LabVIEW, the remote instance of LabVIEW is queried to return the VI reference. Refer to the LabVIEW Help for more information about using the Open VI Reference function.

VI Server Configuration for External Applications


To configure the VI Server for external applications, select Tools>>Options on the server computer and select VI Server:Configuration from the top-pull down menu to display the VI Server:Configuration page. The default VI Server configuration allows ActiveX to call LabVIEW, but does not allow TCP/IP as a protocol. The options specify whether applications access the VI Server through TCP/IP or ActiveX protocols. For a remote computer, place a checkmark in the TCPIIP checkbox and enter a Port number that client applications can use to connect to the VI Server. Once you enable TCP/IP, configure which Internet hosts have access to the VI Server. You also should specify which of the following Server Resources are available to remote applications that access the VI Server: Allow VI calls-Allows remote applications to call VIs exported through the VI Server. If you allow remote applications access to VIs, specify which VIs can be exported. Allow VI methods and properties-Allows remote applications to read and set the properties of VIs through the VI Server. If you allow remote applications access to VIs, specify which VIs can be exported. Allow application methods and properties-Allows remote applications to read and set the properties of the VI Server. Allow control methods and properties-Allows remote applications to read and set the properties of controls in exported VIs. You also can call methods that are usable with controls.

TCPIIP Access Configuration


When you allow remote applications to access the VI Server using the TCPIIP protocol, you should specify which Internet hosts have access to the server. To configure the TCPDP access permissions select Tools>>Options on the server computer and select VI Server:TCP/IP Access from the top pull-down menu to display the Server:TCP/IP Access page. The TCP/IP Access List describes clients that have access to or are denied access to the LabVIEW server. To change an entry, select it from the list,
O National Instruments Corporation
5-17

LabVlEW Advanced Course Manual

Lesson 5

VI Server

and type into the text box at the right of the TCPIIP Access List. To specify if a client has access to the server, select the Allow Access or Deny Access options. If an address is allowed access, a checkmark appears next to the entry. If an address is denied access, an X appears next to the entry. If no symbol appears next to the entry, the syntax of the entry is incorrect. When a remote LabVIEW application attempts to open a connection to the VI Server, the VI Server compares the IP address to the entries in the TCP/IP Access List to determine whether it should grant access. If an entry in the TCPflP Access List matches the IP address, the VI Server permits or denies access based on how you set up the entry. If a subsequent entry also matches the client address, its access permission is used in place of the previous permission. If no entry matches the IP address, the VI Server denies access. An Internet (IP) address, such as 130.164.15.138, might have more than one domain name associated with it. The conversion from a domain name to its corresponding IP address is called name resolution. The conversion from an IP address to its domain name is called name lookup. A name lookup or a resolution can fail when the system does not have access to a DNS (Domain Name System) server or when the address or name is not valid.

Strict Checking indicates whether the TCP/IP server checks DNS resolutions when verifying access permissions. If you select this option, an entry that denies access, has the form of machine. some. com, and cannot be resolved matches all hosts.
An entry that denies access and has the form of * .some. com matches all hosts that cannot be resolved. If you do not select this option or if an entry allows access, only * matches an unresolved address. To specify an Internet host address, you can specify either its domain address or IP address. You also can use the * wildcard when specifying Internet host addresses.
Note If the VI Server runs on a system that does not have access to a DNS server, do not use domain name entries in the TCPIIP access list. Requests to resolve the domain name or an IP address will fail, slowing down the system. For performance reasons, place frequently matched entries toward the end of the TCPIIP Access List.

LabVlEWAdvanced Course Manual

Lesson 5

Vl Sewer

Exported Vls Configuration


When you allow remote applications to access VIs through the VI Server, you should specify which VIs these applications can access. To configure the exported VIs, select ToolsnOptions on the server computer and select VI Server:Exported VIs from the top pull-down menu to display the VI Server:Exported VIs page. Configure the exported VIs using the following components of the page: Exported VIs-Lists Exported VI-Enter Allow Access-Allows Deny Access-Denies Add-Adds Remove-Removes the VIs that can be exported. a VI to list in Exported VIs. access to the VI(s) selected in Exported VIs. access to the VI(s) selected in Exported VIs. the selected entry from Exported VIs.

a new entry to Exported VIs.

If an entry is allowed access to VIs, a checkmark appears next to the entry. If an entry is denied access to VIs, an X appears next to the entry. If no symbol appears next to the entry, the syntax of the entry is incorrect. Each entry in the Exported VIs list describes a VI name or a VI path and can contain wildcard characters. When a remote client tries to access a VI, the VI Server examines the Exported VIs list to determine whether to grant access to the requested VI. If an entry in the list matches the requested VI, the server allows or denies access to that VI based on how you set up that entry. If a subsequent entry also matches the VI, its access permission is used in place of the previous permission. If there is not a VI in the list that matches the requested VI, access to the VI is denied. You can use the ?, *, and * * characters as wildcard characters. The ? and * wildcards do not include the path separator. * * includes the path separator.

0 National Instruments Corporation

LabVlEW Advanced Course Manual

Lesson 5

VI Server

Exercise 5-2
Objective:

Remote Run VI
Build a LabVIEW VI that programmatically opens and runs another VI (Frequency Response VI) on a remote computer.

To build and run a VI to call another VI through the VI Server interface.

Front Panel
1. Open the Remote Run VI located in the C : \Exercises\LabVIEW Advanced directory. The front panel is already built.

* Note how we can call th


w (Leave Msr . a . . . , &
I

e Front Panel Completion

ne name is an
Ime (johndoe.

Tip To allow selection of . llb files, right-click the file browser icon and select Browse

Options.

Block Diagram
2. Build the following block diagram.
Machine Name (Leave Mankif running on local machine)

Close Front Panel on Completion Simply wire the V I Refnum and the error cluster through

a. Place the Open Application Reference function, located on the Functions>>All FunctionsnApplication Control palette, on the block diagram. Wire the Machine Name string control to the machine name input. You can leave the control string empty if you are running the exercise on a local computer. If you want to call a VI on a remote

LabVlEWAdvanced Course Manual

5-20

ni. corn

D D D D b b b B B b D b b 5 b b b b b b b
5 b

Lesson 5

Vl Server

computer you need to supply an IP address or the domain name for the remote computer. If you do not call a remote VI, you do not need to use this function. b. Place the Open VI Reference function, located on the Functions>> All Functions>>Application Control palette, on the block diagram. Wire the VI to execute path control, which determines the VI to execute, to the vi path input of the Open VI Reference function. c. Place the Close Reference function, located on the Functions>>All Functions>>Application Control palette, on the block diagram. This function closes the VI reference to the VI you are calling.

El

d. Place the Property Node, located on the Functions>>All Functions>> Application Control palette, on the block diagram. Wire the Open VI Reference function to the Property Node. Click the property terminal with the Operating tool and select Front Panel Window>>Open from the shortcut menu. Right-click the node and select Change to Write from the shortcut menu. Wire a True Boolean constant to the Front Panel Window Open property terminal.

b b b b D B D D D D D b D D D D D D D
b b b

E l

e. Place the Invoke Node, located on the Functions>>All Functions>> Application Control palette, on the block diagram. Wire the VI reference to the Invoke Node. Click the terminal and select Run VI from the shortcut menu. Wire the True Boolean constant to the Wait Until Done and a False Boolean constant to the Auto Dispose Ref property terminals.

f. Place the Simple Error Handler VI, located on the Functions>>All FunctionsnTime & Dialog palette, on the block diagram.
g. Place the Case structure and build it to select if the front panel of the called VI remains open when the VI completes execution. The True case contains a Property Node that has a False Boolean constant wired to the Front Panel Window Open property terminal. This closes the front panel of the called VI if it is selected. Leave the False case empty and wire the VI refnum and the error cluster through the case.

3. Save the VI.


4. Run the VI on the local computer. This VI opens a reference to the Frequency Response VI located in the C : \Exercises \LabVIEW Advanced directory. The front panel of the VI is opened by accessing the Front Panel Open property of the VI. Then, the Run method runs the VI. Because the Wait Until Done property is True, this VI waits for the

O National Instruments Corporation

LabVIEWAdvanced Course Manual

Lesson 5

Vl Server

Frequency Response VI to complete execution. After exiting the Frequency Response VI, the front panel remains open or closes depending on the position of the front panel switch. Finally, the Close Reference function closes the VI reference, freeing the resources.

5. If time permits, complete the following optional and challenge steps,


otherwise close the VI.

Optional
If your computer is connected through TCPIIP to another computer that has LabVIEW, and each computer has a unique IP address, you can run the Remote Run VI on one computer and have it call the Frequency Response VI on the other computer.

6. Find a partner and exchange IP addresses. Decide which computer will be the server. Complete the following steps on the server computer to set up the VI Server.
a. Select ToolsuOptions and select VI Server: Configuration from the top pull-down menu to display the VI Server: Configuration page. Confirm that a checkmark appears in the TCP/IP Configuration checkbox and that a port number is entered. b. Select VI Server: TCPIIP Access from the top pull-down menu to display the VI Server: TCP/IP page. Enter the IP address of the client computer. Select the Allow Access option and click the Add button. c. Select VI Server: Exported VIs from the top pull-down menu to display the VI Server: Exported VIs page. Confirm that there is a wildcard (*) that is allowed access. This gives the client computer (any computer allowed access in the VI Server: TCP/IP Access section) access to any VIs on your computer. Click the OK button. 7. On the client computer, verify the path to the Frequency Response VI on the server computer. Enter the IP address of the server computer in the Machine Name control.

8. Run the Remote Run VI on the client computer. Does the VI behave as expected? Repeat steps 6 and 7, but reverse situations with your partner.

Challenge
9. Break into groups of three. Write a VI on the first computer that calls the Remote Run VI on the second computer, which then calls the Frequency Response VI on the third computer.

End of Exercise 5-2

LabVlEW Advanced Course Manual

Lesson 5

VI Server

E. Dynamically Calling and Loading Vls


You can dynamically load VIs instead of using statically linked subVI calls. A statically linked subVI is one you place directly on the block diagram of a caller VI. It loads at the same time the caller VI loads. Unlike statically linked subVIs, dynamically loaded subVIs do not load until the caller VI makes the call to the subVI.

Strictly Typed VI Refnums


Use strictly typed VI refnums to call VIs dynamically. Strictly typed VI refnums allow you to save load time and memory because the subVI does not load until the caller VI needs it, and you can release the subVI from memory after the operation completes.

Programming Model
Complete the following steps to call a VI dynamically using the VI Server.

1. Use the Open VI Reference function to specify the VI you want to call. The Open VI Reference function needs a strictly typed refnum in order to call the VI dynamically. To create a strictly typed refnum, select Controls>>All ControlsnRefnum and place a VI refnum on the front panel. Right-click the refnum and select Select VI Server Classn Browse from the shortcut menu. The Choose the VI to Open dialog box prompts you to select a VI. Select the VI that you want to replicate. Wire the strictly typed VI refnum to the type specifier VI Refnum input of the Open VI Reference function.

Tip You also can create a strictly typed refnum by dragging and dropping a VI icon onto the refnum.

O National Instruments Corporation

LabVlEWAdvanced Course Manual

Lesson 5

Vl Server

2. Use the Call by Reference Node to dynamically call the VI. It works in the same way as calling a subVI. The only difference is that normally LabVIEW loads subVIs into memory when the application is first run. whereas with a Call by Reference Node, LabVIEW loads a VI into memory when a reference to it is generated by the Open VI Reference function.
V I Refnurn

e Graph

A strictly typed refnum stores the connector pane information of the VI to which it is strictly typed. The type specifier displays its connector pane. Notice that you are opening a reference to a VI that has a connector pane of the type you have just selected. It does not store any link to the VI you select.

3. Use the Close Reference function to close the reference to the VI and add a Simple Error Handler VI.
V I Refnurn

LabVlEW Advanced Course Manual

Lesson 5

Vl Server

F. Strictly Typed versus Weakly Typed VI References


In this section, a VI reference refers to the output of the Open VI Reference function. The Open VI Reference function can provide the following two types of references to a VI, strictly typed and weakly typed: Weakly Typed VI Reference-includes a path to the VI. The type of the VI reference is not specified. If you create an indicator from the vi reference output of the Open VI Reference function, it looks like the control shown at left if it is weakly typed. Use a weakly typed VI references to pass a VI reference from an Open VI Reference function or an Application Reference function to a Property Node or an Invoke Node. Create a weakly typed VI reference by not specifying the type specifier VI Refnum input. Strictly Typed VI Reference-includes the connector pane information of the VI to be called. An indicator created from the vi reference output of the Open VI Reference function looks similar to the control shown at left if it is strictly typed. Use a strictly typed VI reference to dynamically call or load a VI. Create a strictly typed VI reference by specifying the type of the VI refnum. Connect a strictly typed VI refnum to the type specifier input of the Open VI Reference function to use. Strictly typed means that the connector terminals of a called VI and the data type they can accept are fixed. When you use the Open VI Reference function, it checks to see if the VI has the same connectors and data types as defined in the type specifier vi refnum input. If it does not, an error is generated.
Note Avoid confusing selecting the VI connector pane (strictly typed) with getting a reference to the selected VI (weakly typed). You specify a particular VI using the vi path input of the Open VI Reference function.

O National Instruments Corporation

LabVlEWAdvanced Course Manual

Lesson 5

Vl Server

Strictly Typed versus Weakly Typed Example


You can use methods in LabVIEW to modify the values of controls in a VI and read the values of indicators, as shown in the following block diagram.

Using a Call by Reference Node instead, as show in the following block diagram, you can write or read data to a VI in a much simpler manner.
V I Refnum

Behavior of Strictly Typed VI References


When you open a strictly typed reference, the referenced VI is reserved for running and cannot be edited. For example, you can open a VI reference to a target VI and edit the VI. While this reference is open, you can open another reference-such as a strictly typed reference-and call the target VI as a subVI through the Call By Reference Node. However, until you close the strictly typed reference, editing operations through the Property and Invoke Nodes fail because the VI to which they refer is reserved for running by the strictly typed reference. Because opening a strictly typed VI reference puts the referenced VI in the reserved for running state, it means that the VI has been checked to make sure it is not corrupted, that it is not currently running as a top-level VI, that it has been compiled (if necessary), and a few other checks. A VI referenced by a strictly typed VI reference can be called using the Call By Reference Node at any moment without having to check all these conditions again. Thus, in the reserved for running state you cannot edit the VI or do anything to it that would change the way it would execute.

LabVlEWAdvanced Course Manual

Lesson 5

VI Server

Exercise 5-3
Objective:

Weakly VS Strictly Typed Ref VI

To complete and run a VI that demonstrates the difference between a weakly typed VI reference and a strictly typed VI reference.
Complete a LabVIEW VI that demonstrates how to use the VI Server to call weakly typed VIs and strictly typed VIs.

Front Panel
1. Open the Weakly VS Strictly Typed Ref VI located in the C : \Exercises \LabVIEW Advanced directory. Complete the following front panel by placing the strictly and weakly typed references.

a. Place a VI Refnum, located on the ControlsnAll ControlsnRefnum palette, to the right of the Boolean switch. Change the label to strictly Typed. Right-click the reference and select Select VI Server Classn Browse from the shortcut menu. Navigate to the Pop Up VI in the C : \Exercises\LabVIEW Advanced directory and click the OK button. The refnum adapts to the connector pane of the Pop Up VI. b. Place a VI Refnum, located on the Controls>,AllControlsnRefnum palette, to the left of the Boolean switch. Change the label to Weakly Typed. Right-click the VI Refnum and check that the VI Server class is VI in the shortcut menu.

O National Instruments Corporation

5-27

LabVlEWAdvanced Course Manual

Lesson 5

VI Server

Block Diagram
2. Open the block diagram. The False case runs the Pop Up VI through an Invoke Node. Connect the Weakly Typed VI reference to the Open VI Reference function in the False case as shown in the following block diagram.

The False case contains a VI reference to the Pop Up VI. This VI reference is used to open the front panel of the VI using the FP.Open property. The Set Control Value method passes values to the Numeric and String front panel controls of the Pop Up VI. The Run method is used to run the VI until it completes execution. The Get All Control Values method returns the values of the front panel indicators of the Pop Up VI. These values are displayed on the front panel of this VI. Finally, the front panel of the Pop Up VI is closed, and the VI Reference is released using the Close VI Reference function.

3. The True case runs the Pop Up VI through a Call By Reference Node using a strictly typed VI reference. Complete the True case as shown in the following block diagram.
Strictly Typed

a. Connect the strictly typed reference to the Open VI Reference function. b. Place the Call By Reference Node, located on the Functions~All FunctionsnApplication Control palette, on the block diagram. Wire the VI reference of the Open VI Reference function to the reference input of the node. The node adopts the connector pane of the Pop Up VI, as shown at left.

LabVlEW Advanced Course Manual

Lesson 5

Vl Server

The True case contains the strictly typed reference. When you wire the strictly typed VI reference of Pop Up VI to the Open VI Reference function, a strictly typed VI reference is generated that can then be wired to the Call By Reference Node. 4. Save the VI. 5. Display the front panel and run the VI. Select the strictly typed reference and click the GO button. The Pop Up VI appears. It is designed to return the value it received or allow you to change the data. When you finish with Pop Up VI, click the DONE button, and the value of the indicators from the Pop Up VI display on the front panel.

6. Repeat step 5, and select the weakly typed reference. 7. If time permits, complete the following challenge steps, otherwise close the VI.

Challenge
D D D D D D D D D D D D D D D D b b
9 D
8. Rewrite the VI to use the Profile window to compare the execution statistics of the two methods.
The Pop Up VI should execute a set number of times for the Profile window to return meaningful statistics. Remove the While Loop from the Weakly VS Strictly Typed Ref VI that checks for the GO button to be clicked. This allows you to choose the class type before running the VI.

End of Exercise 5-3

D D b D B D D

O National Instruments Corporation

LabVlEW Advanced Course Manual

Lesson 5

VI Server

Summary
The VI Server allows you to programmatically access and control VIs or LabVIEW itself. The VI Server functionality is exposed through references to two main classes of objects-the Application object and the VI object. You can perform VI Server operations locally or on a remote computer. For operations on a remote object, the VI Server is responsible for sending information across the network and returning results. To configure the VI Server, you must select communication protocols, a list of exported VIs, and a list of clients that have access to the server.

A strictly typed VI refnum is a data type that contains the connector pane information of a VI.
Strictly typed VI refnums are used to call a VI dynamically, saving load time and memory. When you open a strictly typed reference, the referenced VI is reserved for running and cannot be edited.

LabVlEW Advanced Course Manual

S-ar putea să vă placă și