Example Code

Using Network Shared Variables to Communicate between LabVIEW Projects

Code and Documents

Attachment

This example code shows how to use Aliased Network Shared Variables to communicate data from one LabVIEW project to another. You can use this to communicate between computers, RT targets and executables. It will require some setup before running.

Please follow these steps to use this example:

1) Unzip the Shared Variable Communication.zip file to a folder.

2) Open the ProjectA.lvproj file.

3) Deploy the Network Shared Variable libraryA.

Deploy.png

4) Open ProjectB.lvproj file.

5) Open the BooleanB shared variable in the LibraryB library.

ProjectB.png

6) Check that the 'Enable Aliasing' checkbox is checked, Bind to: PSP URL,  and then select 'browse'.

Shared Variable Properties.png

7) Find the BooleanA under LibraryA under the local computer (or on the computer it is located on, if it is not hosted locally)

Browse for Variable.png

😎 Deploy the LibraryB.

9) Open and run both  Host A and Host B.

10) The boolean will change on an input from either location.

Please take care when using variables that are being written to in multiple locations. This example is designed to show how to use a network shared variable to communicate between LabVIEW projects without statically referencing it. This implementation could lead to race conditions which can lead to unexpected behavior.

National Instruments
Staff Certification Engineer

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
DinaDemara
Member
Member
on

This was very helpful as I am looking for communication paths between local computer and PXI using two separate projects.  When I changed Library A to run on the PXI (and changed binding to the shared variable using the PXI IP address), the example did not work.  Wondered if anyone else has solved this issue.

DinaDemara
Member
Member
on

After more investigation, I found that shared variables are not working between local computer and PXI with LabVIEW 8.6 (see http://forums.ni.com/t5/LabVIEW/Deploy-Shared-Variables/m-p/1619816/highlight/true#M585856).  In order to get the communications working, I had to abandon Shared Variables and go with TCP (use examples Simple.Data Client.vi and Simple Data Server.vi).  This is more complex and requires flattening data into strings, but it will work for LabVIEW 8.6

Contributors