Use a functional global variable (FGV) to communicate between two parallel process loops contained within different VIs under the same target, and use a FGV to stop parallel loops with one "stop" button. The "functional" nature of the FGV means that you can create additional functionality beyond that of a basic global variable, e.g., counting and calculations that operate on the stored value.
Communicate data, control, and status between two or more parallel process loops contained within the same target (“target-scoped”), either in the same VI or in different VIs
Make the latest value of a variable available to other process loops
Stop multiple parallel loops from a single control
Perform additional operations (the “functional” aspect of the FGV acronym) beyond merely storing the data, e.g., counting and calculations
A functional global variable is subVI with these defining characteristics:
Uninitialized shift register – an uninitialized shift register on a while-loop causes LabVIEW to allocate storage for a single value that persists as long as the calling VI remains in memory
Single-iteration while-loop – the while-loop conditional terminal is wired to a “true” constant, therefore it only iterates once; the while-loop is merely a mechanism to hold the shift register
Case structure with enumerated control – the case structure selects an operation to perform on the stored value; “read” and “write” are the most basic operations, and additional cases can implement additional functions such as “increment”, “decrement”, etc.
Non-reentrant subVI – this execution mode ensures that only one instance of the subVI exists in the target; multiple instances of the subVI all refer to the same stored value
Memory efficiency – the stored value exists in only one place in memory, whereas each instance of a local/global variable reader creates its own copy of the data
Avoids race conditions – the stored value cannot be written while it is being read because the subVI can only be executed by one process at a time
Keep in mind
The subVI execution mode must be set to “non-reentrant” (open the subVI, press Ctrl+I, select “Execution” category, and choose “non-reentrant execution”); the other two reentrant execution modes create independent copies (“clones”) of the subVI, thereby eliminating the global variable aspect of the FGV
LabVIEW block diagram elements
The functional global variable is a design pattern as opposed to a set of built-in VIs. Refer to the example code below for details.
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.