Global Variables
This AeroScript program uses global variable arrays to communicate between tasks.
// Global Variables Task 1 Example (GlobalVariables_Task1.ascript): // Demonstrates using global variables to communicate between tasks. // // Explanation: In this example, the Task 2 program (GlobalVariables_Task2.ascript) will signal // the Task 1 program (GlobalVariables_Task1.ascript) when an analog input reaches // a certain value. // Instructions: From Automation1 Studio, run GlobalVariables_Task1.ascript on Task 1, and then run // GlobalVariables_Task2.ascript on Task 2. Then from the Variables & I/O module, set Analog Output 0 // on axis X to a value greater than or equal to 1.0 to cause Task 2 to signal Task 1. program $sglobal[0] = "Waiting for trigger." $iglobal[0] = 0 // Wait for Task 2 to signal Task 1. repeat 100 // Exit the loop once Task 2 signals Task 1. if $iglobal[0] > 0 break end // Display current status. AppMessageDisplay($sglobal[0]) Dwell(0.5) end // Getting to here indicates that either a trigger occurred or the repeat loop timed out. if $iglobal[0] > 0 AppMessageDisplay($sglobal[0]) else AppMessageDisplay("Timeout occurred.") end end
// Global Variables Task 2 Example (GlobalVariables_Task2.ascript): // Demonstrates using global variables to communicate between tasks. // Note: See GlobalVariables_Task1.ascript for instructions. program // Scan Analog Output 0 on Axis X in a loop and signal Task 1 // when the analog output exceeds a voltage. while ($iglobal[0] == 0) $rglobal[0] = AnalogOutputGet(X, 0) if $rglobal[0] >= 1.0 $iglobal[0] = 1 $sglobal[0] = "Triggered." end end end