It is possible to use shared variables to move data from one system to the other using network published shared variables. For this setup, you can use two computers to communicate the data to each other, or you could use one computer and a controller such as a CompactRIO (cRIO).
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: If using a cRIO, it can be used as either the server machine hosting the variables, or the client, depending on your application.Server Machine:
- 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.
- 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.
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.
- 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.
- Write or read the variables as required using the Write Variable or Read Variable functions.
- Use a Close Variable Connection function to close the reference to the Network Published Shared Variable.
The code should look similar to this:
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.