minute read

Controller Variables

You are reading our Automation1 API documentation for the Python™ programming language.

The Basics

In the Python API, Controller Variables lets you get and set controller global variables, controller task variables on a task, and the values of Industrial Ethernet mappings on an Automation1 controller. Refer to the sections that follow for more information.

Global Variables

In the Python API, Global Variables lets you get and set global variables on an Automation1 controller. You can access controller global variables from all tasks on the controller. This makes the variables useful when you share information between tasks or between the controller and your custom application.

There are three types of global variables:

  • Global integer array ($iglobal in AeroScript)
  • Global real array ($rglobal in AeroScript)
  • Global string array ($sglobal in AeroScript)

AeroScript integers are 64-bit signed integers. They are represented in Python by the int data type. AeroScript reals are double-precision floating-point numbers. They are represented in Python by the float data type.

The strings in the AeroScript global-string array have a maximum length of 255 bytes. ASCII characters consume one byte. But the use of multi-byte characters, such as Unicode characters, results in multiple bytes of the string being consumed for individual characters.

How to Use

In the Python API, Global Variables is part of the Controller.runtime property. For all the APIs that operate under this property, the Automation1 controller must be running before you can do work with global variables. For more information about this property, see the Controller page. The methods and properties that you use to work with global variables exist under the Controller.runtime.variables.global_ property. This property is suffixed with an underscore because “global” is a reserved word in the Python language.

You can get a single global variable. Use one of the methods that follow:

Copy
global_integer = controller.runtime.variables.global_.get_integer(global_int_index)
global_real = controller.runtime.variables.global_.get_real(global_real_index)
global_string = controller.runtime.variables.global_.get_string(global_string_index)

You can also get two or more global variables at the same time from the same contiguous segment in the global variable array. Use one of the methods that follow:

Copy
global_integers = controller.runtime.variables.global_.get_integers(starting_global_real_index, number_of_ints)
global_reals = controller.runtime.variables.global_.get_reals(starting_global_real_index, number_of_reals)

Task Variables

In the Python API, Task Variables let you get and set task variables on a task on an Automation1 controller. You can access task variables from AeroScript and every API but only from the same task. You can use task variables to share information between iterations of a program running on the same task.

There are three types of task variables, and every task on an Automation1 controller has a set of these task variable arrays: 

  • Task integer array ($itask in AeroScript)

  • Task real array ($rtask in AeroScript)

  • Task string array ($stask in AeroScript)

AeroScript integers are 64-bit.They are represented by the int data type. AeroScript reals are double-precision floating points. They are represented by the float data type.

The strings in an AeroScript task string array have a maximum length of 255 bytes. ASCII characters use just one byte. But, multi-byte characters, such as Unicode characters, use multiple bytes of the string.

The TaskIntegers Parameter, TaskReals Parameter, and TaskStrings Parameter specify the number of variables that are available to the task for which this parameter is set.

How to Use

In the Python API, Task Variables is part of the Controller.runtime property. The Automation1 controller must be running before you can do work with task variables. Refer to Controller for more information.

You can get and set a single task variable with one of the methods that follow.

Copy
integer_value = controller.runtime.variables.task.get_integer(task_name_or_index, task_int_array_index)
real_value = controller.runtime.variables.task.get_real(task_name_or_index, task_real_array_index)
string_value = controller.runtime.variables.task.get_string(task_name_or_index, task_string_array_index)

controller.runtime.variables.task.set_integer(task_name_or_index, task_int_array_index, integer_value)
controller.runtime.variables.task.set_real(task_name_or_index, task_real_array_index, real_value)
controller.runtime.variables.task.set_string(task_name_or_index, task_string_array_index, string_value)

You can also get and set a contiguous segment of values in the integer and real task variable arrays using the methods that follow.

Copy
int_values = controller.runtime.variables.task.get_integers(task_name_or_index, task_int_array_starting_index, number_of_ints)
real_values = controller.runtime.variables.task.get_reals(task_name_or_index, task_real_array_starting_index, number_of_reals)

controller.runtime.variables.task.set_integers(task_name_or_index, task_int_array_starting_index, int_values)
controller.runtime.variables.task.set_reals(task_name_or_index, task_real_array_starting_index, real_values)

Industrial Ethernet Variables

In the Python API, Industrial Ethernet Variables lets you get and set the values of Industrial Ethernet mappings on an Automation1 controller. Automation1 exposes the memory blocks of Industrial Ethernet protocols, such as Modbus and EtherCAT, through Industrial Ethernet mappings. These Industrial Ethernet mappings let you map memory regions used by Industrial Ethernet protocols to arbitrary controller data types. For more information, see Modbus TCP/IP Overview and EtherCAT Overview.

Industrial Ethernet mappings can be AeroScript integers or reals. AeroScript integers are 64-bit. They are represented in Python by the int data type. AeroScript reals are double-precision floating-point numbers. They are represented in Python by the float data type.

How to Use

In the Python API, Industrial Ethernet Variables is part of the Controller.runtime property. For all the APIs that operate under this property, the Automation1 controller must be running before you can do work with Industrial Ethernet mappings. For more information about this property, see the Controller page.

You can get and set the value of a single Industrial Ethernet mapping by using the methods that follow:

Copy
integer_value = controller.runtime.variables.industrial_ethernet.get_integer(industrial_ethernet_mapping_name)
real_value = controller.runtime.variables.industrial_ethernet.get_real(industrial_ethernet_mapping_name)
controller.runtime.variables.industrial_ethernet.set_integer(industrial_ethernet_mapping_name, value)
controller.runtime.variables.industrial_ethernet.set_real(industrial_ethernet_mapping_name, value)

You can also get and set a contiguous segment of values within a single Industrial Ethernet mapping array by using the methods that follow:

Copy
integer_values = controller.runtime.variables.industrial_ethernet.get_integers(industrial_ethernet_mapping_array_name, starting_industrial_ethernet_mapping_array_index, number_of_ints)
real_values = controller.runtime.variables.industrial_ethernet.get_reals(industrial_ethernet_mapping_array_name, starting_industrial_ethernet_mapping_array_index, number_of_reals)
controller.runtime.variables.industrial_ethernet.set_integers(industrial_ethernet_mapping_array_name, starting_industrial_ethernet_mapping_array_index, values)
controller.runtime.variables.industrial_ethernet.set_reals(industrial_ethernet_mapping_array_name, starting_industrial_ethernet_mapping_array_index, values)

Thread Safety

The threading library is the only multithreading library that is officially supported by the Automation1 Python API.

All the methods and properties that operate under the Controller.runtime.variables.global_ and Controller.runtime.variables.task properties are thread safe. You can call them from two or more threads without interference.

Full Reference

For more information about the methods that are available for Global Variables, Task Variables, and Industrial Ethernet Variables, refer to the lists that follow.

Controller.runtime.variables.global_ Methods

Controller.runtime.variables.task Methods

Controller.runtime.variables.industrial_ethernet Methods