Programmatically access a network-published shared variable (NPSV)
Use the NPSV programmatic API (application programmer's interface) VIs as an alternative method to a shared variable node.
NOTE: Refer to the NPSV code example page for a detailed introduction to NPSVs; the sample code presented here is a modified version of that example.
Use cases
Host PC controls the RT application and monitors its status via a network connection
Multiple PCs require access to variables hosted on a single RT target
Efficiently work with multiple network-published shared variables (NPSVs); an alternative to the shared variable node approach to access NPSVs
Features
Open a reference to a NPSV and then use the “Read Variable” and “Write Variable” VIs to access the NPSV by reference instead of by shared variable nodes
LabVIEW block diagram elements
Locate these elements with "Quick Drop" (press Ctrl+Space and start typing the name); click on an icon to see more sample code that uses that element:
Example code
Connect your Academic RIO Device to your PC using USBLAN, Ethernet, or Wi-Fi. NOTE: Not all Academic RIO Devices have Ethernet and Wi-Fi connectivity options.
If using the NI myRIO 1950 or NI RIO Control Module start with the NI myRIO 1900 Archive.
Different IP address: Right-click on the "NI myRIO 1900" Device, choose "Properties", and then enter the new IP address
Different device:
Right-click on the top of the project hierarchy, select "New Targets and Devices", keep the "Existing target or device" option, and then find and select your particular device
Select all of the components under the "NI myRIO 1900" device: click the first one and then shift+click the last one
Drag the selected components to the new device
Right-click the "NI myRIO 1900" device and select "Remove from project"
Run the “RT Main” VI:
This is a “headless” VI – once started, the PC host monitors and controls the VI, including initiating a controlled stop
The VI contains one non-deterministic loop and one deterministic loop
Polls the “LED0” NPSV every 100ms and sets the states of LEDs 0 and 3
Writes the “Button” NPSV according to the state of the Academic RIO Device onboard pushbutton
Reads the onboard accelerometer Z-axis every 10ms in the deterministic loop, and writes the “Accelerometer-Z” NPSV
Run the “PC Main” VI:
Writes the “LED0” NPSV every 10ms according to the LED0 front-panel button
Reads the “Button” NPSV and displays its state
Reads the “Accelerometer-Z” NPSV and displays its value as a chart; tip the Device to see changes