This content is not available in your preferred language.

The content is shown in another available language. Your browser may include features that can help translate the text.

Using Network Published Shared Variables to Communicate Between Computers

Updated Jun 27, 2019

Reported In

Hardware

  • CompactRIO Controller

Software

  • LabVIEW

Issue Details

I want to use shared variables to communicate data between Windows computers connected to a network. How can I achieve this?

I want data from my cRIO to be available to different computers on the network. Is this possible?

Solution

You need to chose one computer to act as a server and host the variables, with another computer acting as a client. Then, follow the steps below to setup the server and client machines.

Note: A cRIO can be used as either the server machine hosting the variables, or the client, depending on your application.

Server Machine:
  1. Create a LabVIEW Project and add a variable by right-clicking My Computer and selecting New » Variable. Make sure the Variable Type is set to Network Published.
  1. Create a new VI and write or read the Network Published Shared variable normally, as explained in Using the LabVIEW Shared Variable.
The server project should look similar to this.
Client Machine:
Create a new LabVIEW Project, add a New VI and use the functions of the Shared Variable API to communicate with the Shared Variable hosted in the remote server. The Shared Variable API can be found in the Functions Palette under Data Communication.
 
  1. Use an ​Open Variable Connection function with a String or Shared Variable Refnum constant or control to specify the Network Published Shared Variable URL as ni.var.psp://<machine_name_or_IP_address>/<library>/<variable>. The Shared Variable Refnum constant or control can be created by right-clicking the shared variale refnum in input of any of the Shared Variable API functions and selecting Create » Constant/Control.
  2. Write or read the variables as required using the Write Variable or Read Variable functions.
  3. Use a Close Variable Connection function to close the reference to the Network Published Shared Variable.
The code should look similar to this:
 

Additional Information

The Shared Variable API, available since LabVIEW 2009, is the recommended method to communicate between Windows systems. However, there is an alternative method binding the network published shared variables to front panel objects, which will make controls or indicators update automatically if there are any changes in the bound variables. The data binding method is not recommended because it obscures the functionality of the front panel objects; since the controls or indicators are not getting their values from a wire, it degrades the readability of the code.

For additional information, refer to the documents in the Related Links and to the Shared Variable.lvproj shipping example. To locate the shipping example, launch LabVIEW and click Help » Find Examples.. to open the Example Finder, and once it loads, select Browse (according to Task) and expand Networking » Shared Variable.

If you are using the above method to read Network Shared Variables on a Client Machine, ensure you are only opening the reference only once. Putting the open VI in a loop will open up a new instance each time the loop is run, and will cause LabVIEW to hang or crash with open references.

WAS THIS ARTICLE HELPFUL?

Not Helpful