minute read

Controller Variables

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

The Basics

In the C 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 C 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 them 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. They are represented in C by the int64_t data type. AeroScript reals are double-precision floating-point numbers, which are represented in C by the double data type.

In the AeroScript global string array, the strings 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

Global Variables is part of the controller runtime. Thus the Automation1 controller must be running before you do work with global variables. For more information, see the Controller page.

You can get global variables with one of the functions that follow:

Copy
bool Automation1_Variables_GetGlobalIntegers(Automation1Controller controller, int32_t startingGlobalIntegerIndex, int64_t* integerValuesOut, int32_t integerValuesOutMaxLength);
bool Automation1_Variables_GetGlobalReals(Automation1Controller controller, int32_t startingGlobalRealIndex, double* realValuesOut, int32_t realValuesOutMaxLength);
bool Automation1_Variables_GetGlobalString(Automation1Controller controller, int32_t startingGlobalStringIndex, char* stringValueOut, int32_t stringValueMaxLength);

You can set global variables with one of the functions that follow:

Copy
bool Automation1_Variables_SetGlobalIntegers(Automation1Controller controller, int32_t startingGlobalIntegerIndex, int64_t* integerValues, int32_t integerValuesLength);
bool Automation1_Variables_SetGlobalReals(Automation1Controller controller, int32_t startingGlobalRealIndex, double* realValues, int32_t realValuesLength);
bool Automation1_Variables_SetGlobalString(Automation1Controller controller, int32_t startingGlobalStringIndex, const char* stringValue);

Task Variables

In the C API, Task Variables lets 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 int64_t data type. AeroScript reals are double-precision floating points. They are represented by the double 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

Task Variables is part of the controller runtime, so the Automation1 controller must be running before you do work with task variables. For more information about this property, refer to the Controller page.

You can get task variables with one of the functions that follow.

Copy
bool Automation1_Variables_GetTaskIntegers(Automation1Controller controller, int32_t taskIndex, int32_t taskIntegerArrayStartingIndex, int64_t* integerValuesOut, int32_t integerValuesOutMaxLength);
bool Automation1_Variables_GetTaskReals(Automation1Controller controller, int32_t taskIndex, int32_t taskRealArrayStartingIndex, int64_t* realValuesOut, int32_t realValuesOutMaxLength);
bool Automation1_Variables_GetTaskString(Automation1Controller controller, int32_t taskIndex, int32_t taskStringArrayIndex, int64_t* stringValueOut, int32_t stringValueMaxLength);

You can set task variables with one of the functions that follow.

Copy
bool Automation1_Variables_SetTaskIntegers(Automation1Controller controller, int32_t taskIndex, int32_t taskIntegerArrayStartingIndex, int64_t* integerValues, int32_t integerValuesLength);
bool Automation1_Variables_SetTaskReals(Automation1Controller controller, int32_t taskIndex, int32_t taskRealArrayStartingIndex, double* realValues, int32_t realValuesLength);
bool Automation1_Variables_SetTaskString(Automation1Controller controller, int32_t taskIndex, int32_t taskStringArrayIndex, const char* stringValue);

Industrial Ethernet Variables

In the C API, Industrial Ethernet Varaibles lets you get and set the values of Industrial Ethernet mappings on an Automation1 controller. Automation1 exposes the memory block 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 C by the int64_t data type. AeroScript reals are double-precision floating-point numbers. They are represented in C by the double data type.

How to Use

In the C API, Industrial Ethernet Variables is part of the controller runtime. Thus the Automation1 controller must be running before you do work with Industrial Ethernet mappings. For more information about this property, see the Controller page.

You can get the value of a single Industrial Ethernet mapping or get the values of a contiguous segment of an Industrial Ethernet mapping array by using the functions that follow:

Copy
bool Automation1_Variables_GetIndustrialEthernetInteger(Automation1Controller controller, const char* industrialEthernetMappingName, int32_t* integerValueOut);
bool Automation1_Variables_GetIndustrialEthernetIntegerArray(Automation1Controller controller, const char* industrialEthernetMappingArrayName, int32_t industrialEthernetMappingStartingArrayIndex, int32_t* integerValuesOut, int32_t integerValuesOutMaxLength);
bool Automation1_Variables_GetIndustrialEthernetReal(Automation1Controller controller, const char* industrialEthernetMappingName, double* realValueOut);
bool Automation1_Variables_GetIndustrialEthernetRealArray(Automation1Controller controller, const char* industrialEthernetMappingArrayName, int32_t industrialEthernetMappingStartingArrayIndex, double* realValuesOut, int32_t realValuesOutMaxLength);

You can set the value of a single Industrial Ethernet mapping or set the values of a contiguous segment of an Industrial Ethernet mapping array by using the functions that follow:

Copy
bool Automation1_Variables_SetIndustrialEthernetInteger(Automation1Controller controller, const char* industrialEthernetMappingName, int32_t integerValue);
bool Automation1_Variables_SetIndustrialEthernetIntegerArray(Automation1Controller controller, const char* industrialEthernetMappingArrayName, int32_t industrialEthernetMappingStartingArrayIndex, int32_t* integerValues, int32_t integerValuesLength);
bool Automation1_Variables_SetIndustrialEthernetReal(Automation1Controller controller, const char* industrialEthernetMappingName, double realValue);
bool Automation1_Variables_SetIndustrialEthernetRealArray(Automation1Controller controller, const char* industrialEthernetMappingArrayName, int32_t industrialEthernetMappingStartingArrayIndex, double* realValues, int32_t realValuesLength);

Thread Safety

The Automation1_Variables_ functions are thread safe. You can call them from two or more threads without interference.

Full Reference

For more information about the functions that are available for Global Variables, Task Variables, and Industrial Ethernet Variables, refer to the list that follows.

Functions