Summary

In this article, we will go through how to create, set up, and manage local variables.

Control not currently supported on the IG41.

Local Variables Introduction

Local variables are a read/write variable created in the gateway’s PLC. This data input/output allows end users to send data between the PLC and the cloud such as setpoints, statuses, etc.

Local variables are created and stored on the IG gateway itself. These are useful for variables you would like to use as Counters, or include in any of your Logic and Calculations. When the gateway is offline, you will not be able to update these local variables. Once a Local Variable is created, it creates both a Digital Input and Digital Output to be accessed by your Dashboards, Reporting, other Programs, etc.

Create Local Variables

To create a new local variable from within the control interface select Create New Local Variable or add row and simply begin typing on under the existing local variables. (Seen below)

17.png

After selecting Create Option, the following window will appear

18.png

Select Submit to confirm creation. 

Manage Local Variables

Local Variables exist on the hardware itself and therefore must be handled differently. You may notice that even after deleting a local variable’s corresponding data input, it is still available when mapping variables. This section will discuss how to remove or edit existing local variables.

To locate the Local Variables, navigate to the gateways page, select the three dots on the right side and select inputs. 

19.png

Then select Local Variables

20.png

From here, scroll down to view all local variables for that gateway. 

21.png

To edit a local variable, select the pencil next to the corresponding local variable you’d like to edit. You will then see this window appear. 

23.png

Select Submit to confirm any changes. 

To delete a local variable, select the trash button next to the corresponding local variable. You will be asked to confirm the action. Select OK and the local variable will be deleted. 

Local Variable Inputs/Outputs

Set up your Local Variable inputs and outputs by going to “I/O” in the Configuration Page and adding inputs and outputs.

Example below:

Gateway I/O

Gateway I/O is the onboard Analog/Digital channels related to your gateway. Selecting this allows you to select the physical ports on your Industrial Gateway and reference that read/write port.

Data I/O

Data I/O includes (with some exceptions) your entire I/O library that is stored to cloud. If it is on your I/O page as an Input or Output, it can most likely be referenced here. This includes but is not limited to: Local Variables (from other gateways), Sensor Data, Analog/Digital Data Inputs and outputs, Third Party Device data, etc.

This gives users the ability to write a program using information calculated in the cloud, collected by a Samsara Sensor, or use a variable that was collected from a different gateway all together.

These variables DO NOT NEED TO BE DECLARED in your programming block but instead need to be selected in the sidebar. Upon selecting program variables, you will see them populate next to the program variables field. This means they are automatically declared. You can simply copy the tag name and use it in your program.

As you may notice, one program variable is yellow. This means the variable is collected by a different gateway and it is known as a REMOTE VARIABLE.

Data Outputs

Any time we want to pass data back to the cloud from the control program, we use data outputs. Data outputs must first be declared outside of the structured text interface before using them in a structured text program.

 The steps to creating a data output are as follows: 

  1. Create a Local Variable

  2. Navigate out of structured text interface to I/O Configuration > Data Outputs

  3. Create New data output with an output type of local variable

  4. Select the Gateway and the Local Variable that was just created

  5. Navigate back to structured text interface

  6. Select data output from drop down options

 Steps 1-4 can be used for creating a setpoint variable. This is useful when wanting to enter user defined setpoints for a control program from the dashboard. Or if a user wants to display metrics on a graph.

 Alternatively, if a data output already exists for reasons such as writing to 3rd party registers then the above steps are not necessary, and the data output can simply be selected from the drop-down menu.

 Data outputs are useful for returning a status back to the dashboard from the Structured text program.

Referencing I/O in Structured Text

To reference an Input / Output in structured text, refer to our guides on setting up Analog and Digital I/O and import them as Program Variables: Set up Program Variables for IG21

Both Analog and Digital Program Variables will be referenced as LREAL. Use 0.0/1.0 as TRUE/FALSE mapping for Digital Outputs.