Using Shared Variables in Executables

Overview

Shared variables are an effective way to transmit data between multiple computers using simple coding techniques. They were first introduced in LabVIEW 8.0 and are faster and simpler to implement than similar communication methods. The following is an outline of how they work and the steps required to properly establish connectivity from within executables.

Contents

The Shared Variable Engine

In order to use shared variables effectively, it is important to understand the nature of the Shared Variable Engine (SVE) and its role in communication. The SVE is installed with every version of LabVIEW since version 8.0. When running executables on a computer without LabVIEW, you need to install SVE on that computer. Shared variables use the Publish-Subscribe-Protocol (PSP), which is a form of User Datagram Protocol (UDP) communication.  Refer to Understanding Shared Variable Technology for more information about PSP.

The SVE is where a variable resides on a computer. The SVE is responsible for network communication and for managing bindings, all of which you can configure from within LabVIEW. THE SVE also includes the Variable Manager, which allows users to monitor the status of variables deployed locally and on real-time targets, reassign bindings, and to un-deploy.

Network Troubleshooting

If data values transmit correctly when running the application from within LabVIEW, the network is functioning properly. Ensuring this works is a quick and easy way to ensure that no firewalls or network security procedures hamper communication.

Otherwise, if you experience difficulties while attempting communication from within LabVIEW, follow these troubleshooting steps.

  1. Make sure that you connect the computers within the same subnet or that the computers can ping one another from the command prompt in Windows. To ping another computer, type ping followed by the IP address of the computer. For example: ping 192.168.0.1.  Additionally, you can find the IP address by typing the ipconfig command in the command prompt.

  2. Lower firewalls on the default network connection or ensure that LabVIEW has been unblocked in any operational firewalls.

  3. The SVE installs the Variable Manager which you can use to view the variables currently deployed on that computer. Make sure that the variables are listed in the variable manager. Be sure to check this on all computers involved – they must all list the variables. If the shared variables are deployed properly on all computers involved, go to step 5.

  4. Ensure that Autodeploy is selected for the library containing the variables. This you can find this option by right-clicking on the library. You also can manually deploy the variables by selecting Deploy All. Once you deploy the shared variables on a computer they remain deployed in memory unless you undeploy them, shut down the SVE, remove the variables using the Variable Manager, or restart the computer. Selecting Autodeploy from within LabVIEW does not deploy variables in an executable. This must be done programmatically, which is described later.

  5. Make sure that the variables on one of the computers are bound to another. Be aware that at least one computer must not bind the variables to anything. If you are using only two computers (A and B), only bind B to A. Upon binding in this manner, A effectively becomes the publisher, and B becomes the subscriber, even though they you can set both to read and write data for this variable. Double-click the variable in the Project Explorer window. Select the option to bind to source and click the Browse button. Change the pull-down box that appears to Network Items and navigate to the variable on the other computer. You need to deploy the variable before you can find it on the other computer.

  6. Turn on buffering. Network traffic and packet loss can result in lost data or overwritten data. To prevent this data loss, buffer data in the variable on the subscriper computer. You can access this option by double-clicking the variable in the Project Explorer window.

Setting Up Your Application

The library containing the shared variables in use by an application must be deployed on any and every machine that is using them for communication. Autodeploy is checked in LabVIEW projects by default, so running a VI from within LabVIEW that uses shared variables will automatically deploy the library.

**Note: It is very important to understand that no autodeploy functionality is available for executables.

Deploying Variables in Executables

In order to deploy shared variables in executables, the use of a property node is necessary. For information on how to do this, consult the KB, How Do I Deploy Network Shared Variables From a Compiled Executable?

Data Communication in Executables

Shared variables work based upon a PSP. As such, the variables of the subscriber must be bound to a source or publisher. Data can flow both ways, but this concept can be helpful when attempting to understand how to configure a project. Without the LabVIEW DSC addon, bindings are configured statically from the shared variable’s option menu dialog and cannot be modified programmatically.

One publisher must exist in a shared variable application, to which many subscribers are allowed to bind. The publisher’s variables cannot be bound to anything.

**Note: It is not necessary to bind a subscriber’s variable to the publisher if it is intended for use on the same machine as the publisher.

Development From Within the Same Project

Since the subscriber’s variables must be bound to the publisher’s, it is easiest to use separate libraries for the subscriber and for the publisher. Duplicate the variables between the two libraries and bind the variables of B to A as discussed earlier. Ensure that you are using a network address that will still be valid from the remote location.

Development From Within Separate Projects

This method is possible and very similar to what is required when using the same project. Create variables of the same data type and bind those of the subscriber to the publisher’s.

Which Library Should Be Deployed?

These variables will exist within separate libraries for both development techniques, so ensure that you are deploying the correct library for the VI programmatically and that the variables being referenced in the code belong to the correct library. Using distinct names is helpful when troubleshooting this.

Explanation of Included Example Code

The zip file attached below has been tested successfully across multiple computers. It does not use DSC property nodes, so it cannot programmatically bind. Because of this, it will be necessary to reset the bindings for the client’s library and recompile the client executable. Run the server executable on the computer that is intended to publish the variables and then set the network address to the location of these deployed variables. Further instructions are included with the actual VIs.

When you launch the executables, they will prompt you for the location of the library to use. This is the library that contains the shared variables that the executable needs to communicate with. Make sure that you are specifying the correct library as they will be different for the client and the server.

The build specifications for the client and server both reference the necessary VIs and the associated library. By doing so, the necessary library is included in a subfolder of the executable’s folder named, Data.

Was this information helpful?

Yes

No