Use a local variable (front-panel indicator) to communicate between two parallel process loops contained within the same VI, and use a local variable to stop parallel loops with one "stop" button.
Use cases
Communicate data, control, and status between two or more parallel process loops contained within the same VI (“VI-scoped”)
Make the latest value of a variable available to other process loops
Stop multiple parallel loops from a single control
Features
Stores values in front-panel indicators
Tag-based (latest value) communication
Easy to code
Supports multiple clock domains: timed loops and conventional loops
Keep in mind
Local variables can only be created from front-panel controls and indicators
Because this is tag-based (latest value) communication, rapid changes of a variable in one process can be missed in the other process
Ensure that control signals remain active long enough for the other process to detect them, or devise a hand-shaking scheme
Consider global variables if you need to communicate with process loops in another VI that is part of the same RT target
NOTE: The stop button’s mechanical action must be changed from the default (“Latch When Released”) to either “Switch When Pressed” or “Switch When Released”. Both of these settings leave the stop button pressed down when the VI stops. Write a “false” value to the stop button local variable after all loops have stopped to reset the stop button to its default state as the last step before the VI stops running.
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.
Download and unpack the
rt_local-variable.zip (for use with NI myRIO 1900)
or the
NIELVISIII-rt_local-variable.zip (for use with NI ELVIS III)
archive, and then double-click the ".lvproj" file to open the project. NOTE: This project was written for a NI myRIO 1900 or NI ELVIS III connected by USBLAN at IP address 172.22.11.2.
If you are using a different IP address or another Academic RIO Device (Example: NI myRIO 1950 or NI RIO Control Module) do the following:
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:
The “fast counter” in Process Loop #1 increments once each loop cycle
The Boolean “reset” generated by Process Loop #2 resets the fast counter
The “slow counter” in Process Loop #2 increments each time the fast counter reaches 10 counts; this condition also enables the “reset” signal
Displays up-counter value as front-panel indicator
Resets counter to zero when local variable “reset” is true
Process Loop #2: “slow counter”
Displays up-counter value as front-panel indicator
Increments counter when the “fast counter” value equals 10
Activates “reset” indicator when the “fast counter” value equals 10
Stop both loops from a single front-panel “Stop” button
“Stop” button resides in Loop #1
Local variable in Loop #2 reads the “Stop” button value
“Stop” button mechanical action must be changed from default “Latch When Released” to “Switch When Pressed” because latching action is not compatible with local variables
Click “Stop” to stop both loops
Unstick the “Stop” button with the “F” constant after both loops have stopped, otherwise the button remains pressed