Set up Program Variables for IG21
Summary
Program Variables facilitate the transfer of existing values between the cloud and the Control Program. These allow users to read and write values used by the IG's PLC logic.
In this article, we will go through how to set up new or existing program variables.
Control not currently supported on the IG41.
Add a Program Variable
Go to Settings (gear icon on the left corner of the Home Page) → Automation. This brings you to the Structured Text programming screen. For additional information, please see our article on programming with Structured Text: Create Control Program on IG21 with Structured Text . To add local variables to the program, see our article on creating and managing local variables: Set up Local Variables
Data Inputs and Data Outputs in the PLC
The Read and Write sections of the Variable Mapping section are allocated for existing data inputs and data outputs that will be pulled into the structured text for PLC access. Ex: Controlling a pump output which is a data output (Write Variable) by monitoring the level of a well data input (Read Variable). In the Data Inputs and Data Outputs section of the Variable Mapping Section, existing data inputs and outputs can be added. To the left of each input/output, an alias must be assigned to that data input/output. This alias is what will be used in the program when referencing the data input/output.

Note: Data Outputs and read/write accessible while Data Inputs are read only
Remote Variables
Remote Variables are the variables an IG uses from another IG in Control. It takes approximately 1+ minute to update between IGs.
Data Inputs that are sourced from the gateway that the program is running on will be highlighted blue while Data Inputs that are sourced from another gateway will be highlighted yellow. These data inputs are Remote Variables.
Depending on the scenario, a gateway can be both a Local Gateway and a Remote Gateway. The distinction is that the Local Gateway is the gateway performing any control during that specific situation.
Remote Variable Example at a Water Plant:

Remote Variable Example
In the below example, tanklevel is local to the gateway while tanklevel2 is a Remote Variable.

In the case where the remote or local gateway goes offline or where that remote variable can’t be retrieved, the PLC will read this value as being NaN. Monitoring this is a good way to check that there is a healthy cloud connection.
NaN Checking
NaN Checking in Structured Text
In the below example, the logic tanklevel2 <> tanklevel2 checks whether this remote variable is NaN or if it is a valid number. It will return TRUE if it is NaN and will return false if it is not NaN. In the code below, it checks if the value is NaN for five minutes and if it is, it writes to a local variable to send an alert notification to the end user. Another way to implement NaN checking is to write to an internal variable only when the remote variable is not NaN and reference that internal variable for further logic.

NaN Checking in Ladder Logic
Our ladder logic interface has a function block for checking if a value is NaN. This block evaluates to TRUE if the provided input's value is NaN.

Notes: Non-remote variables can also go to NaN in some cases. If they do, it means that the input variable could not be read, or that its value was stale and has not been updated within the last 15 minutes. NaN Checking on critical data inputs is a great way to ensure everything is communicating to and from the cloud properly.