G Web Server Examples

Creating Simultaneous Instances Remote Panels LabVIEW Applications

This tutorial teaches you how to use the new Remote Panel feature in LabVIEW in conjunction with VI templates to build LabVIEW applications that have a unique user interface for each new user instead of displaying a common user interface to everyone. We will refer to such applications as "Simultaneous Instances Remote Panels" applications. This functionality is useful in the case where you want a lot of people to have access to your LabVIEW appliction, but you want each user to see different data that is unique to that individual. For example, this is useful in the case of distance learning applications where you want every student to use the same LabVIEW VIs, but each student has a different idea for how to use the VI to solve the problem and therefore wants to interact and control it differently. By using the material provided in this tutorial you can learn how to use the Remote Panels feature in LabVIEW and use VI Templates to build these applications.

The LabVIEW Remote Panels feature allows you to view and control VIs throught a standard Web browser. Creating the Remote Panels page is easy with the LabVIEW Web Publishing Tool. A few mouse clicks creates a web page with the embedded VI front panel image, that can be viewed through the client's web browser.

Remote Panels allow multiple clients to simultaneously view the front panel of the same VI (if multiple remote panel licenses are enabled.) However, only one client can control the VI front panel. By default, the execution system cannot execute multiple calls to the same VI simultaneously. For our distance learning example, this means that every student would see the same application and all of them would have to interact with it in the same way since only one student could control it and everyone else is watching what that one student is doing.

However, if you make a VI reentrant, each instance of the call maintains its own state of information. Then, the execution system runs the VI from its own separate dataspace. Although it does allow mulitple calls to the same VI to occur and for each call to have unique data, it does not allow the VI to be in use by multiple students at the same time. What would happen in this case is that each student could have unique control of the application but the VI would be accessible by only one student at a time, and the next student would not be able to use the VI until the student currently using the VI was finished. This is a result of how the LabVIEW VI Server actually calls the VI. When you call a VI using a Virtual Instrument Class Reference (Open VI Reference, Property/Invoke Nodes, Close Application/VI Reference), it is treated as if you had opened the front panel and were running the VI. You cannot have multiple copies of a "Top Level" VI running simultaneously.

The solution therefore must both allow all students to have unique control of the LabVIEW VI, and allow all of these individual instances of the VI to run simultaneously. This can be achieved by using the VI templates. Each time a template VI is called simultaneously with VI server, a replica VI with unique name is created. At the end of execution, these uniquely named VIs may be closed and deleted. When the VI is opened as a template VI, each connection to the web page will result in a new instance of the VI and each client can gain control of its instance through the remote panels. In this case, each student gets a unique instance of the VI to work with each time they open the web page.

To show how these technologies can be used, lets walk through an example application that uses this technique. The example below uses CGI scripting to dynamically access the LabVIEW VI Server and return individual instance of the template VI. The LabVIEW Internet Toolkit provides the ability for your LabVIEW applications to respond to CGI scripting commands.


Pressing the Submit button on this page invokes the CGI VI – redirect.vi.

This CGI script will clone a new handler from the handler template (handler.vit), create an HTML document in <LabVIEW-directory>/www that contains an embedded link to the handler.vi, and return HTML code to the web browser that redirects the browser to the HTML document just created.

This is what the diagram of the redirect.vi looks like:

Figure 1

The redirect.vi is a state machine which is run from a Browser. The VIs circled in red are the crucial VIs that will be contained in every CGI VI that you create. The VIs outlined in blue are specific to decoding the form elements that were passed to the CGI, as well as building the HTML page to be returned to client's browser.

The following block diagram shows the code for the first subVI CreateAndLoadHandler.vi

Figure 2
The CreateAndLoadHandler VI checks all the VIs in memory, and searches for a VI whose name starts with "handler" string. If there is no such VI already in memory, it will open a reference to handler VI template, and name the VI "handler0". If a "handler" VI was found, the created reference will increment the number by one and point to a new handler VI, named "handler1".

Once the reference to the "handler" VI has been created, CreateHandlerHTMLFile VI will execute. This VI will create an .htm page with the embedded VI, and save it into the <LabVIEW-directory>\www directory

Figure 3
This embedded page is operated by the LabVIEW built-in G Web server. The second string element in this array of strings, has the HTML code that creates an alert page with the time restriction message. This page informs the user that the browser will be redirected to the default.html page after 5 minutes, or when the Finish button is pressed. The elapsed time is displayed in the Windows status bar at the bottom of the window. The time restriction is added to prevent indefinitely opened remote panel pages.

After adding some heading tags, the final page is constructed with the Modified HTML Document.vi

Figure 4
The Modified HTML Document.vi runs the referenced handler VI, and measures the time needed to display this VI in the remote window. This time will be used by the DelayedClosedRef.vi (below) to provide a more deterministic release of the VI references.

Figure 5
The DelayedClosedRef.vi allows 30sec for the browser to load the "handler" VI remote panel image, before closing the reference to this VI. Once a VI is opened remotely, it will remain in memory on the server as long as a remote client is viewing the panel and the VI reference from the CGI is open. By default, the reference from the CGI panel will be closed when the CGI VI is stopped, because it has not been accessed in 120 sec (default CGICacheTime that idle CGIs are cached). This time is specified in <LabVIEW-directory>\internet\http\conf\lvhttp.cfg.

The final HTML page with the embedded "handler: VI looks like this:

Figure 6
The following example demonstrates how to allow several users to access your LabVIEW application, and have full control of it.

Simultaneously Controlling Remote Panel Instances of VI Templates

The VI combines the new Remote Panel feature, with VI Templates and CGI scripting.


© National Instruments