AM Fundamentals Pages 103-104

Embed Size (px)

Citation preview

  • 7/28/2019 AM Fundamentals Pages 103-104

    1/30

    Lesson 5V I Server

    You can access the VI Server through block diagrams, ActiveX technology,and the TCP protocol to communicate with VIs and other instances ofLabVEW so you can programmatically control VIs and LabVIEW. Youcan perform VI Server operations on a local computer or remotely across anetwork. Typically, you open a refnum to an instance of LabVEW or toa VI and use the refnum as a parameter to other VIs. The VIs get (read) orset (write) properties, execute methods, or dynamically load a referencedVI. Finally, you close the refnum, which releases the referenced VI frommemory.

    You Will Learn:A. What the VI Server is and relevant object-oriented terminologyB. About the VI Server programming modelC. About the VI Server functionsD. How to implement remote communication using the VI ServerE. How to dynamically call and load VIsF. The difference between strictly typed and weakly typed VI references

    O National Instruments Corporation LabVlEW Advanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    2/30

    Lesson 5 VI Server

    A. What is V I Server?The VI Server is an object-oriented, platform-independent technology thatprovides 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 thatyou can call from other instances of LabVIEW on the Web. Forexample, if you have a data acquisition application that acquires andlogs data at a remote site, you can sample the data occasionally fromyour local computer. By changing your LabVIEW preferences, you canmake some VIs accessible on the Web so transferring the latest data isas easy as a subVI call.Edit the properties of a VI and LabVIEW. For example, you candynamically determine the location of a VI window or scroll a frontpanel so that a part of it is visible. You also can programmatically saveany changes to disk.Update the properties of multiple VIs rather than manually using theFilenVIProperties dialog box for each VI.Retrieve information about an instance of LabVIEW, such as the versionnumber and edition. You also can retrieve environment information,such as the platform on which LabVIEW is running. For example, youcan use this capability if you have an application that uses ActiveX andthere is the possibility a user might try to run it on a non-Windowsplatform. The application could check if the operating system isWindows 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 youhave a large application and want to save memory or startup time.Create a plug-in architecture for the application to add functionalityto the application after you distribute it to customers. For example,you might have a set of data filtering VIs, all of which take the sameparameters. By designing the application to dynamically load these VIsfrom a plug-in directory, you can ship the application with a partial setof these VIs and make more filtering options available to users bysimply placing the new filtering VIs in the plug-in directory.

    LabVlEWAdvanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    3/30

    Lesson 5 Vl Server

    Object-Oriented TerminologyA 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 thefollowing example.

    Control ClassI I Example Property: VisibleExample Method: Attach Da taSocketBoolean Sub-class Array Sub Cla ssExam ple Property: Boolean Text I Array I Exam ple Property: Number of RowsStop ObjectI I isib1e:YesAttach DataSocket: NoBoolean Text: Stop

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

    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Methods: iget-name() ;Address set-name() :get-address( )set-address( )

    Name: Mark DoeObject: Mark Doe Address: 10 2 West Street

    O National instruments Corporation LabVlEWAdvanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    4/30

    Lesson 5 VI Server

    To use the class, you create an object and you could call it M a r k Doe.Once you create the object, you can call the methods that set the data to whatyou 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 docum entation for the other programm ing language for moreinformation about object-oriented programm ing.VI Server Clients

    The V I Server has a set of m ethods and properties that ari accessiblethrough the d ifferent clients, as shown in the follow ing illustration. Th edifferent client interfaces are ActiveX Automa tion client, TC P/IP client, andLabVIE W functions that allow LabVIE W VIs to a ccess the VI Server.VI Server Clients

    Automation Client TCPllP Client

    D ia gr am Access-LabVIEW includes a set of built-in functions located onthe FunctionsnA ll Func tionsnAp plication C on tro l palette you can use toaccess the VI Server on a local or remote com puter.N etw ork Access-If you are using the VI Serve r on a remote com puter,LabV IEW uses the TCP/IP protocol as the means of com munication.ActiveX Interface-ActiveX clients such as Visual Basic, Visual C++ ,and Exc el applications can use the VI Server to run Lab VIEW applications.

    LabVlEWAdvanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    5/30

    Lesson 5 VI Server

    Appl icat ion a nd V I ObjectsThe VI Server is exposed through references to two classes of objects-theApplication object and the VI object. These classes of objects allow youto perform operations using methods and properties.An Application Class reference refers to a local or remote LabVIEWenvironment. This is the actual LabVIEW application itself, not a programwritten using LabVIEW. The properties and methods of the LabVIEWApplication object can, for example, change LabVIEW preferences andreturn system information.A Virtual Instrument class reference refers to a specific VI running in theLabVIEW application. For example, the properties and methods of the VIobject can change the VI's execution and window options.

    O National Instruments Corporation LabVlEWAdvanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    6/30

    Lesson 5 VIServer

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

    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 toensure the correct resources are allocated and reserved.

    CreateReferenceto Object

    2. Pass the reference to a Property Node or Invoke Node so the node knowswhich application or VI it is operating on.

    Ope n ApplicationReferen ce Property Node dos e Referen ce Simple Error handler.^Property

    Open V IReference Invoke NodeMethod

    -b

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

    Operate onPropertiesor Methods

    LabVIEWAdvanced Course Manual

    CloseReferenceto Object-b -FCheck forErrors

  • 7/28/2019 AM Fundamentals Pages 103-104

    7/30

    Lesson 5 Vl Server

    C. V I Server FunctionsThe VI Server-related functions are located on the Functions>>AllFunctionsnApplication Control palette.

    Open Application R eference FunctionThe Open Application Reference function returns a reference to a VI Serverapplication running on the specified computer. If you specify an emptystring for machine name, it returns a reference to the local LabVIEWapplication in which this function is running. If you do specify a machinename, it attempts to establish a TCP connection with a remote VI Server onthat machine on the specified port. You can use this function to getreferences to global VIs and custom controls. machine name can be indotted decimal notation, such as 1 2 . 2 3 . 4 5 . l o 0, or domain namenotation, such as remotemachine.ni com.The port number input allows you to specify multiple servers on a singlecomputer.You use the application reference output as an input to Property Nodesand Invoke Nodes to get or set properties and invoke methods on theLabVIEW application. You also use application reference as the inputto the Open VI Reference function to get references to VIs that arerunning in the LabVIEW application.

    Open VI R eference FunctionThe Open VI Reference function returns a reference to a VI, control, orglobal variable specified by a name string or path to the VI's locationon disk.You can get references to VIs in another LabVIEW application by wiringan application reference, obtained from the Open Application Referencefunction, to this function. If you leave the application reference inputunwired, the Open VI Reference function refers to the local installationof LabVIEW.

    Property NodesE l The Property Node gets (reads) and/or sets (writes) properties of areference. The Property Node automatically adapts to the class of the objectthat you reference. You can use Property Nodes to modify properties of theLabVIEW application or VI Object you define using the Open ApplicationReference function or Open VI Reference function. Once you wire the VIreference to the Property Node, you can access all the properties availablefor that Application or VI reference.

    O National Instruments Corporation LabVlEWAdvanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    8/30

    Lesson 5 VI Server

    You can resize Prop erty Nodes to have more than one input or output.To select whether a pro perty reads or writes data, right-click the PropertyNode and select Change to Read or Change to Write from the shortcutmenu. If a p roperty is read-only, the Change to Write menu item isdimmed.Property Nod es execute from the top to the bottom . If an erro r occurs ona terminal, the node stops at that terminal, returns an error, and does notexecute any further terminals.

    Invoke Nod esl4 l The Invoke Node invokes a method or action on a reference. Most methodshave associated parameters. If the node is configured for VI ServerApplication class or Virtual Instrument class and reference is unwired,

    reference defaults to the curren t Application or VI. A sing le Invoke Nodecan execute only one method on an application or VI.

    Close Reference Function?s;/:+ The Close Reference function releases the application or VI reference . Ifyou close a reference to a specified VI and there are no other references tothat VI, LabVIEW can unload the VI from memory.

    This function does not prom pt you to save changes to the VI. By des ign,VI S erver actions should avoid causing user interaction. You m ust use theSave Instrument method to save the VI programmatically.

    Note If you do not close the application or VI reference with this function, thereference closes autom atically when the top-level VI asso ciated with this functionfinishes execution. However, it is a good program ming practice to conserve theresources involved in maintaining the connection by closing the reference whenyou finish using it.Properties of the Application or V I Classes

    Property Nodes are used to modify properties of the LabVIE W applicationor VI Object defined with the Open Ap plication Reference or Open V IReference function. There are different properties available in theApplication Class and the VI Class.Application Class PropertiesMost App lication Class properties are read-only. They allow you to checka whole range of parameters, such as what VIs are loaded into memory,the operating system , and so o n. The properties that can be w ritten are forthe printing options, which allow you to customize what prints and whatdoes not print.

    LabVlEWAdvanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    9/30

    Lesson 5 Vl Server

    Th e following block diagram opens an application session to the localinstallation of LabVIEW and reads four properties of the LabVIE Wapplication:Th e display properties of all the display monitorsTh e name of the operating system, such as Windows NT, Windows 98,Mac O S, and so onTh e version of the o perating systemWh ether the LabVIEW Web Server is active

    You can use this information to ensure that the compu ter running L abVIEWis configured correctly and prompt the user to reconfigure the com puter ifnecessary.V I Object Propert iesMany of the prop erties of the VI that are exposed correspond to theproperties available in the File>>VI roperties dialog box. Mo st of theproperties are read and w rite. Properties suc h as name, path, type, metrics,and so on are read-only. Som e properties are transient, such as windowposition, title, and s o on.

    Q Tip After you select a property, you can g et help information abou t it by right-clickingthe property and selecting Help for Property Name from the shortcut menu, whereProperty Name is the name of the property.Me thod s of the Appl icat ion or VI C lasses

    Invoke Nodes are used to perform functions on the LabVIEW applicationor VI Object defined with the Open A pplication R eference or Open VIReference function. The re are different m ethods available in theApplication C lass and the VI Class.

    O National Instruments Cor~oration LabVlEWAdvanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    10/30

    Lesson 5 VI Server

    Application Class MethodsWhen you place the Invoke Node o n the block diagram you can accessthe App lication class methods. You d o not have to wire an Applicationreference to the Invoke Node to access the Application class methodsbecause the nod e defaults to the current Application if reference is unwired.Som e of the important methods available are Mass Compile, Get VIVersion, Bring To Front, and so on. Th e Mass C ompile method loads andcom piles all the VIs in a d irectory and all its subdirectories. Th e Get VIVersion method gets the version of LabV IEW in which the VI was lastsaved. On W indows and M ac O S, the Bring To Front method brings theapplication windows to the front.

    Tip After you select a method , you can get help information about it by right-clickingthe method and selecting Help forMethod Name from the shortcut menu, where MethodName is the name of the m ethod.

    VI Object MethodsW hen you w ire the VI reference to the Invoke Node, you can access the VIclass methods.Som e of the important m ethods exported by the VI Server are ExportVI Strings, Set Lock State, Run VI, Save Instrument, and so on. The ExportVI Strings method exports strings pertaining to V I and front panel objectsto a tagged text file. The S et Lock State method sets the lock state of a VI.The R un V I method starts VI execution. The S ave Instrument m ethod savesa VI.

    9 Tip After you se lect a metho d, you can get help inform ation about it by right-clickingthe method and selecting HelpforMethod Name from the shortcut menu, where MethodName is the name of the m ethod.

    LabVIEW Advanced Course Manu al

  • 7/28/2019 AM Fundamentals Pages 103-104

    11/30

    Lesson 5 Vl Server

    Exercise 5-1 Setting Window Options V IObjective: To com plete and run a V I to set or reset pr ope rties of another VI through theVI Server interface.

    Complete a VI that programmatically sets and resets the window optionproperties for another VI.Front Pane l

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

    Set or reset properties by clicking the buttons in the menu cluster.Click the Run Options TestVI button to run the Options Test VI.If you do not click any buttons, no properties are set. Click a button toset the corresponding property. For example, if you do not click anybuttons, the Options Test VI is not sized to the screen, does not haveatitle bar, is not resizeable, does not have scroll bars, and does not havemenu bars.

    O National Instruments Corporation LabVlEWAdvanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    12/30

    Lesson 5 Vl Sewer

    Block Diagram2. Open the block d iagram. Most of the block diagram has been completedfor you. Com plete the contents of the Case structure and other VI Serverportions of the block diagram .

    LabVlEWAdvanced Course Manual

    3. Open a VI reference to the Options Test VI located in theC :\Exercises LabVIEW Advanced directory using the Open VIReference function. Then use a Property Node to set the default statesfor these properties. Last, close the VI reference using the C loseReference 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 thelocal 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 R eference function tothe reference input of the Property Node.Resize the Pro perty Node to have five properties. Right-click eachproperty and select one of the following properties from theProperties>>Front anel Window shortcut menu: Minimizeable,Title Bar Visible, Resizeable, Show Scroll Bars, and Show MenuBar. In step 5, you w ill create a Case statement for each of theseproperties.

    c. Place the Close Reference function, located on the FunctionsnAllFunctionsvApplication Control palette, on the block diagram .This func tion releases the VI reference.Wire the VI reference and error cluster from the Property Nodethrough the case structure to the Run Options Test VI.

  • 7/28/2019 AM Fundamentals Pages 103-104

    13/30

    Lesson5 Vl Server

    O National Instruments Corporation

    From the R un O ptions Test VI, wire the VI reference and errorcluster to the C lose Reference VI.4. Double-click the Run O ptions Test subVI to open it and examine theblock diagram. Th is subV I opens the front panel of Options Test, runsOptions Test, and then closes the front panel. Close the Run Op tions Test

    subVI.5. Com plete the contents of the Case structure. Each case executes whenits corresponding B oolean control chang es value.

    a. Case -1-This is the default case. Wire the tunnels across the Ca sestructure.b. Ca se 0-Wire reference and error in to the Property No de asshown in the follow ing illustration. Right-click the p roperty terminaland select Property>>Front anel Window>bMinimizeable romthe shortcut menu. Right-click the node and select Change To

    Write from the sho rtcut menu. W ire the elementoutput of the IndexArray function to the property terminal.

    c. Case 1-Wire reference and error in to the Property Node asshow n in the follow ing illustration. Right-click the propertyterminal and select Property>>Front anel WindowmTitle BarVisible from the shortcut menu. Right-click the node and selectChange To Write from the shortcut menu. W ire the elementoutputof the Index Array function to the property terminal.

    LabVlEWAdvanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    14/30

    Lesson 5 VIServer

    d. Ca se 2-Wire reference an d error in to the Property Node asshown in th e following illustration. Right-click the property terminaland select Property>>Front anel Window>>Resizeablerom theshortcut menu. Right-click the node an d select Change To Writefrom the shortcut menu. Wire the elementoutput of the Index Arrayfunction to th e property terminal.

    e. Ca se 3-Wire reference and error in to the Property Node asshown in the following illustration. Right-click the property terminaland select PropertymFront Panel WindownShow Scroll Barsfrom the shortcut menu. Right-click the node and select Change toWrite from the sho rtcut menu. Wire the elementoutput of the IndexArray function to the property terminal.

    f. Case 4--Wire reference and error in to the Property Node asshown in the following illustration. Right-click the property terminaland select PropertynFront Panel WindownShow Menu Barsfrom the shortcut menu. Right-click the node and select Change ToWrite from the shortcut menu. W ire the elementoutput of the IndexArray function to th e property terminal.

    LabVlEWAdvanced CourseManual

  • 7/28/2019 AM Fundamentals Pages 103-104

    15/30

    O National Instruments Corporation

    Lesson 5 V1 Server

    6. Save the VI.7. Display the fron t panel and run the VI. C lick each button at least twiceto check that all the properties set and reset correctly. After you click aproperty button, verify it by runn ing the O ptions Test VI. Try all the

    properties. Try using the func tion keys to be sure that key navigationis set up properly. Click the QUIT button to stop the VI.Note Mak e sure that you close the O ptions Test VI by clicking the OK button on itsfront panel befo re setting or resetting the next property.

    8. Close the VI when you finish.End of Exercise 5-1

    LabVlEWAdvanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    16/30

    Lesson 5 Vl Server

    D. Remote CommunicationAn im portant aspect of both the Application and VI references is theirnetwork transparency. You can open references to rem ote objects the sameway you o pen references to those objects on local computers. For operationson rem ote objects, LabVIEW handles sending the information about theoperation across the network and sending results back. The app licationshould look virtually identical regardless of whether the operation is remoteor local.To open an application reference to a rem ote version of LabVIEW , youmust specify the machine name input of the Open Application Referencefunction. Then L abVIEW attempts to establish a TC P connection with aremote VI Server on that computer on the specified port.

    Example-Accessing a Re m ote VI PropertyThe following block diagram shows how to access the properties of aVI object on a remote com puter. The Open Ap plication Reference functionopens a conn ection to a remote computer. The Open VI Reference functionopens a VI on the specified remote computer. The Property Node opens thefront panel of the specified VI. The Invoke Node runs the specified VI andwaits for execution to complete before exiting the function. Because theAuto D ispose Ref is set to False, a Close Reference function must be usedto release the reference and the parallel data space.

    Open VI R eference Inputsvi 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. Thefunction loads the specified VI in to memory, if it is not already ope n, andreturns a reference to this VI. If you w ire a name string, the VI mu st alreadybe in mem ory. If you wire a path and a V I of the same name is already inmemory, the function returns a reference to the open VI, regardless ofwhether its path is the sam e 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

  • 7/28/2019 AM Fundamentals Pages 103-104

    17/30

    Lesson 5 VI Server

    application reference is a reference to a LabVIEW application. The defaultis a reference to an application on the local instance of LabVIEW. If wiredand the reference is to a remote instance of LabVIEW, the remote instanceof LabVIEW is queried to return the VI reference.Refer to the LabVIEW Help for more information about using the Open VIReference function.

    VI Server Configuration for External ApplicationsTo configure the VI Server for external applications, select Tools>>Optionson the server computer and select VI Server:Configuration from thetop-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 throughTCP/IP or ActiveX protocols. For a remote computer, place a checkmark inthe TCPIIP checkbox and enter a Port number that client applications canuse to connect to the VI Server. Once you enable TCP/IP, configure whichInternet hosts have access to the VI Server.You also should specify which of the following Server Resources areavailable to remote applications that access the VI Server:

    Allow VI calls-Allows remote applications to call VIs exportedthrough the VI Server. If you allow remote applications access to VIs,specify which VIs can be exported.Allow VImethods and properties-Allows remote applications toread and set the properties of VIs through the VI Server. If you allowremote applications access to VIs, specify which VIs can be exported.Allow application methods and properties-Allows remoteapplications to read and set the properties of the VI Server.Allow control methods and properties-Allows remote applicationsto read and set the properties of controls in exported VIs. You also cancall methods that are usable with controls.

    TCP IIP Access ConfigurationWhen you allow remote applications to access the VI Server using theTCPIIP protocol, you should specify which Internet hosts have access to theserver. To configure the TCPDP access permissions select Tools>>Optionson the server computer and select VI Server:TCP/IP Access from the toppull-down menu to display the Server:TCP/IP Access page.The TCP/IP Access List describes clients that have access to or are deniedaccess to the LabVIEW server. To change an entry, select it from the list,

    O National Instruments Corporation 5-17 LabVlEW Advanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    18/30

    Lesson 5 VI Server

    and type into the text box at the right of the TCPIIP Access List. To specifyif a client has access to the server, select theAllow Access or Deny Accessoptions. If an address is allowed access, a checkmark appears next to theentry. If an address is denied access, anX appears next to the entry. If nosymbol appears next to the entry, the syntax of the entry is incorrect.When a remote LabVIEW application attempts to open a connection to theVI Server, the VI Server compares the IP address to the entries in theTCP/IP Access List to determine whether it should grant access. If an entryin the TCPflP Access List matches the IP address, theVI Server permits ordenies access based on how you set up the entry. If a subsequent entry alsomatches the client address, its access permission is used in place of theprevious permission. If no entry matches the IP address, the VI Serverdenies access.An Internet (IP) address, such as 130.164.15.138, might have more thanone domain name associated with it. The conversion from a domain nameto its corresponding IP address is called name resolution. The conversionfrom an IP address to its domain name is called name lookup. A namelookup or a resolution can fail when the system does not have access toa DNS (Domain Name System) server or when the address or name isnot valid.Strict Checking indicates whether the TCP/IP server checks DNSresolutions when verifying access permissions. If you select this option, anentry that denies access, has the form of machine. some. com, and cannotbe resolved matches all hosts.An entry that denies access and has the form of * . ome. com matches allhosts that cannot be resolved.If you do not select this option or if an entry allows access, only * matchesan unresolved address.To specify an Internet host address, you can specify either its domainaddress or IP address. You also can use the * wildcard when specifyingInternet host addresses.

    Note If the VI Server runs on a system that does not have access to a DNS server, donot use domain name entries in the TCPIIP access list. Requests to resolve the domainname or an IP address will fail, slowing down the system. For performance reasons, placefrequently matched entries toward the end of the TCPIIP Access List.

    LabVlEWAdvanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    19/30

    Lesson 5 Vl Sewer

    Exported Vls C onfigurationWhen you allow remote applications to access VIs through the VI Server,you should specify which VIs these applications can access. To configurethe exported VIs, select ToolsnOptions on the server computer and selectVI Server:Exported VIs from the top pull-down menu to display theVI Server:Exported VIs page. Configure the exported VIs using thefollowing components of the page:

    Exported VIs-Lists the VIs that can be exported.Exported VI-Enter a VI to list in Exported VIs.Allow Access-Allows access to the VI(s) selected in Exported VIs.Deny Access-Denies access to the VI(s) selected in Exported VIs.Add-Adds a new entry to Exported VIs.Remove-Removes the selected entry from 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, anX appears next to the entry. If nosymbol 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 andcan contain wildcard characters. When a remote client tries to access a VI,the VI Server examines the Exported VIs list to determine whether to grantaccess 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 thatentry. If a subsequent entry also matches the VI, its access permission isused in place of the previous permission. If there is not a VI in the list thatmatches 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 pathseparator.

    0 National Instruments Corporation LabVlEW Advanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    20/30

    Lesson 5 VI Server

    Exercise 5-2 Remote Run VIObjective: To build and run a VI to call another V I through the VI Server interface.

    Build a LabV IEW V I that programmatically opens and runsanother VI (Frequency Response VI) on a remote computer.Front Panel

    1. Open the Rem ote Run VI located in the C :\Exercises LabVIEWAdvanced directory. The front panel is alread y built.

    * Note how we can call thw (Leave Msr.a-...,&

    ne name is anIme (johndoe.

    e Front PanelI Completion

    Q Tip To allow selec tion of .llb iles, right-click the file browser icon and select BrowseOptions.Block Diagra m

    2. Build the following block diagram .Machine Name (Leave M ankif running on local machine)

    Close Front Panel on CompletionSimply wire the V I Refnumand the error cluster through

    a. Place the Open Application Referen ce function, located on theFunctions>>All unctionsnApplication Control palette, on theblock diagram.Wire the Machine Name string control to the machine name input.You can leave the con trol string empty if you are running theexercise on a local co mpu ter. If you w ant to call a VI on a remote

    LabVlEWAdvanced Course Manual 5-20 ni.corn

  • 7/28/2019 AM Fundamentals Pages 103-104

    21/30

    Lesson5 Vl Server

    computer you need to supply an IP address or the dom ain name forthe remote com puter. If you do no t call a remote VI, you do not needto use this function.b. Place the Open VI Reference function, located on the Functions>>All Functions>>A pplication ontrol palette, on the block diagram .

    Wire the V I to execute path control, which determines the VI toexecute, to the vi path input of the Open VI Reference function.

    O National Instruments Corporation

    c. Place the Close Reference function, located on the Functions>>AllFunctions>>Ap plication ontrol palette, on the block diagram. Thisfunction closes the VI reference to the VI you are calling.E l d. Place the Property Node, located on the Functions>>All unctions>>Application Control palette, on the block diagram .

    Wire the Op en VI Reference function to the Property Node.Click the property terminal with the Operating tool and select FrontPanel Window>>Openrom the shortcut menu.Right-click the node and select Change to W rite from the shortcutmenu.Wire a True Boolean constant to the Front Panel Window Openproperty terminal.

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

    f. Place the Simple Error Handler VI, located on the Functions>>AllFunctionsnTime & Dialog palette, on the block diagram.g. Place the Case structure and build it to select if the front panel of thecalled VI rem ains open when the VI com pletes execution. The Truecase contains a Property Node that has a False Boolean constantwired to the Front Panel Window Open property terminal. Thiscloses the front panel of the called VI if it is selected.

    Leave the False case empty and wire the VI refnum and the errorcluster through the case.3. Save the VI.4. Run the VI on the local computer. This VI op ens a reference to theFrequency Response VI located in the C :\Exercises LabVIEW

    Advanced directory. The front panel of the VI is opened by accessingthe Front Panel Open property of the VI. Then , the Run method runs theVI. Because the Wait Until Done property is True, this VI waits for the

    LabVIEWAdvanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    22/30

    Lesson 5 Vl Server

    Frequency Response VI to com plete execution. After exiting theFrequency Response V I, the front panel remains open or closesdepending on the position of the front panel sw itch. Finally, the CloseReference function closes the V I reference, freeing the resources.5. If time permits, complete the following optional and challenge steps,

    otherwise close the V I.Optional

    If your com puter is connected through TCPIIP to another computer that hasLabVIEW, and each co mputer has a unique IP address, you can run theRem ote Run VI on one com puter and have it call the Frequency ResponseVI o n the other computer.6. Find a partner and exchange IP addresses. Decide wh ich compu ter willbe the server. Complete the following steps on the server computer to setup the VI Server.

    a. Select ToolsuOptions and select VI Server: Configuration fromthe top pull-down menu to display the VI Server: Configurationpage. Co nfirm that a checkm ark appears in the TCP/IPConfiguration checkbox and that a port number is entered.b. Select VI Server: TCPIIP Access from the top pull-down menu todisplay the VI Server: TCP/IP page. Enter the IP address of theclient computer. Select the Allow Access option and click the Addbutton.c. Select VI Server: Exported VIs from the top pull-down menu to

    display the VI Server: Exported VIs page. Con firm that there is awildcard (*) that is allowed access. This gives the client computer(any computer allowed access in the VI Server: TCP/IP Accesssection) access to any VIs on your computer. Click the OK button.7. On the client com puter, verify the path to the F requency Response VI onthe server computer. Enter the IP address of the server computer in theMachine Name control.8. Run the R emote R un VI on the client computer. Does the VI behave asexpected? Repeat steps 6 an d 7, but reverse situations with your partner.

    Challenge9. Break into groups of three. Write a VI on the first computer that calls theRem ote Run VI on the second computer, which then calls the FrequencyResponse VI on the third comp uter.End of Exercise 5-2

    LabVlEW Advanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    23/30

    Lesson 5 VI Server

    E. Dy nam ical ly Cal l ing and Loading VlsYou can dynamically load VIs instead of using statically linked subVI calls.A statically linked subVI is one you place directly on the block diagram ofa caller VI. It loads at the same time the caller VI loads. Unlike staticallylinked subVIs, dynamically loaded subVIs do not load until the caller VImakes the call to the subVI.

    Strict ly Typed VI Refnum sUse strictly typed VI refnums to call VIs dynamically. Strictly typed VIrefnums allow you to save load time and memory because the subVI doesnot load until the caller VI needs it, and you can release the subVI frommemory after the operation completes.Pr o g ra m m i n g M o d e lComplete 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 orderto call the VI dynamically. To create a strictly typed refnum, select

    Controls>>All ontrolsnRefnumand place a VI refnum on the frontpanel. Right-click the refnum and select Select VI Server ClassnBrowse from the shortcut menu. The Choose the VI to Open dialogbox 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 inputof the Open VI Reference function.

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

    O National Instruments Corporation LabVlEWAdvanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    24/30

    Lesson 5 Vl Server

    2. Use the C all by R eference Node to dynamically call the VI. It works inthe sam e way as calling a subVI. The only difference is that normallyLabVIEW loads subVIs into memory when the application is first run.whereas with a Call by Reference Node, LabVIEW loads a VI intomem ory when a reference to it is generated by the Open VI Referencefunction.

    V I Refnurn

    e Graph

    A strictly typed refnum sto res the connector pane informa tion of the VIto which it is strictly typed. T he type spe cifier displays its connectorpane. Notice that you a re opening a reference to a VI that has aconne ctor pane of the type you have just selected. It doe s not store anylink to the VI you select.3. Use the C lose Reference function to close the reference to the V I andadd a S imple Error Handler VI.

    V I Refnurn

    LabVlEW Advanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    25/30

    Lesson 5 Vl Server

    F. Strictly Typed versus W eak ly Typed V I ReferencesIn this section, a VI reference refers to the output of the Open V I Refe rencefunction. Th e Open V I Re ference function can provide the followingtwo types of references to a VI, strictly typed and w eakly typed:

    Weakly Typed VI Reference-includes a path to the VI. Th e type ofthe VI reference is not specified. If you c reate an indicator from thevi re fer en ce output of the Open VI Reference function, it looks like thecontrol shown at left if it is weakly typed.Use a w eakly typed VI references to pass a VI reference from anOpen V I Reference function or an Application R eference function to aProperty N ode o r an Invoke Node. Create a weakly typed VI referenceby not specifying the type sp ecifie r VI Re fnu m input.Strictly Typ ed VI Reference-includes the conn ector paneinformation of the VI to be called. An indicator created from thevi re fer en ce output of the Open VI Reference function looks similar tothe control shown a t left if it is strictly typed.Use a strictly typed VI refe rence to dynamically call or load a VI. Createa strictly typed VI reference by specifying the type of th e VI refnum.Connect a strictly typed V I refnum t o the typ e specifier input of theOpen VI Reference function to use. Strictly typed means that theconnector terminals of a called VI and the da ta type they can accept arefixed. When you use the Open VI R eference function, it checks to see ifthe VI has the same connectors and data types as defined in the typespecifier vi re fn um input. If it does not, an error is generated.

    Note Avoid confusing selecting the VI connec tor pane (strictly typed) with getting areference to the selected VI (weakly typed). You specify a particular VI using the vi p a thinput of the Open VI Reference function.

    O National Instruments Corporation LabVlEWAdvanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    26/30

    Lesson 5 Vl Server

    Strictly Typed versus Wea kly Typed Exa mp leYou can use methods in LabVIEW to modify the values of controls in a VIand read the values of indicato rs, as show n in the following block diagram.

    Using a Call by Referen ce Node instead, as show in the following blockdiagram, you can write or read data to a VI in a m uch simpler manner.V I Refnum

    Behavior of Strictly Typed VI R eferenc esWhen you open a strictly typed reference, the referenced V I is reserved forrunning and cannot be edited.For exam ple, you can open a VI reference to a target VI and edit the VI.While this reference is open , you can open anoth er reference-such as astrictly typed reference-and call the target VI as a subVI through the CallBy R eferen ce Node. How ever, until you close the strictly typed reference,editing operations through the Property and Invoke Nodes fail because theVI to w hich they refer is reserved for running by the strictly typed reference.Bec ause opening a strictly typed VI reference puts the referenced V I in thereserved fo r running state, it means that the VI has been ch ecked to makesure it is not corrupted, that it is not currently running a s a top-level VI, thatit has been compiled (if necessary), an d a few other checks. A V I referencedby a strictly typed V I reference can be called using the Ca ll By ReferenceNode 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 anythingto it that would cha nge the way it would execute.

    LabVlEWAdvanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    27/30

    Lesson 5 VI Server

    Exercise 5-3 Weakly VS Strictly Typed Ref VIObjective: To complete and run a VI that demonstrates the dif ference betw een a weaklytyped VI reference and a strictly typed VI reference.

    Complete a LabVIEW VI that demonstrates how to use the VI Server to callweakly typed VIs and strictly typed VIs.Front Panel

    1. Open the Weakly VS Strictly Typed Ref VI located in theC :\Exercises LabVIEW Advanced directory. Complete thefollowing front panel by placing the strictly and weakly typedreferences.

    a. Place a VI Refnum, located on the ControlsnAll ControlsnRefnumpalette, to the right of the Boolean switch.Change the label to strictly Typed.Right-click the reference and select Select VI Server ClassnBrowse from the shortcut menu.Navigate to the Pop Up VI in the C :\Exercises LabVIEWAdvanced directory and click the OK button. The refnum adapts tothe connector pane of the Pop Up VI.

    b. Place a VI Refnum, located on the Controls>,AllControlsnRefnumpalette, 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 VIin the shortcut menu.

    O National Instruments Corporation 5-27 LabVlEWAdvanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    28/30

    Lesson 5 VI Server

    Block Diagram2. Open the block diagram. T he False case runs the Pop U p VI through anInvoke Node. C onnect the Weakly Typed VI reference to the Open V IReference function in the False case as shown in the following block

    diagram.

    The False case contains a VI reference to the Pop U p VI. This VIreference is used to open the front panel of the VI using the FP.Openproperty. The Set Control Value method passes values to the Numericand String front panel controls of the Pop Up VI.Th e Run method is used to run the VI until it completes execution. TheGet All Co ntrol Values method returns the values of the front panelindicators of the Po p Up VI. These values are displayed o n the frontpanel of this VI. Finally, the front panel of the Pop U p VI is closed , andthe VI R eference is released using the C lose VI R eference function.

    3. The True case runs the Pop Up VI through a Call By R eference Nodeusing a strictly typed VI reference. Com plete the True case as shown inthe following block diagram.Strictly Typed

    a. Con nect the strictly typed reference to the Open VI Referencefunction.b. Place the Call By Reference Node, located on the Functions~All

    FunctionsnApplication Control palette, on the block d iagram.Wire the VI reference of the Open VI Reference function to thereference input of the node. The node adopts the connector paneof the Pop Up VI, as shown at left.

    LabVlEW Advanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    29/30

    Lesson 5 Vl Server

    Th e True case contains the strictly typed reference. When you w ire thestrictly typed VI reference of Pop Up VI to the Open VI Referencefunction, a strictly typed V I reference is generated that can then be wiredto the Call By Reference Node.4. Save the VI.5. Display the front panel and run the VI. Select the strictly typed referenceand click the GO button. The Pop Up V I appears. It is designed to returnthe value it received or allow you to chang e the data. When you finishwith Pop Up V I, click the DONE button, and the value of the indicatorsfrom the Pop Up VI display on the front panel.6. Repeat step 5 , and select the weakly typed reference.7 . If time permits, com plete the following challenge steps, otherwise closethe VI.

    Chal lenge8. Rew rite the VI to use the Profilewindow to compare the executionstatistics of the two m ethods.

    The Pop U p VI should execute a set number of times for the Profilewindow to return meaningful statistics.Remove the W hile Loop from the W eakly VS Strictly Typed Ref VIthat checks for the GO button to be clicked. Th is allows you tochoos e the class type before running the V I.

    End of Exercise 5-3

    O National Instruments Corporation LabVlEW Advanced Course Manual

  • 7/28/2019 AM Fundamentals Pages 103-104

    30/30

    Lesson 5 VI Server

    SummaryThe VI Server allows you to programm atically access and control VIsor LabVIE W itself.The VI Server functionality is exposed through references to two m ainclasses of objects-the App lication object and the VI object.You can perform V I Server operations locally or on a remote computer.For operations on a remote ob ject, the VI Serv er is responsible forsending information across the netw ork and returning results.To configure the VI Server, you m ust select communication protocols,a list of ex ported VIs, and a list of clients that have access to the server.A strictly typed VI re fnum is a data type that contains the conne ctor paneinformation of a VI.Strictly typed VI refnums are used to call a VI dynam ically, saving loadtime and memory.When you open a strictly typed reference, the referenced VI is reservedfor running and cannot be edited.