Skip to content

Create a global variable list and a structure

eaxPLCHow-to guideFreeProView as Markdown

You declare a recipe structure once, keep twenty recipes and a line speed in a global variable list, and use them from any program.

  • The project is on the PLC (the Studio shows the Changes view and the project tree). You are an engineer (Lead_Engineer or Administrator).
  • Pick names that are not keywords. TYPE, END_TYPE, STRUCT, END_STRUCT, UNION, END_UNION, FUNCTION, END_FUNCTION, VAR_GLOBAL and VAR_EXTERNAL are reserved, in any letter case.
  1. In the project tree, click + (Add POU).

  2. POU Type: Data type (DUT). Data type form: Structure (STRUCT). POU Name: ST_Recipe. Click Create POU.

  3. The data type opens in the code editor, checked out to you. Write the members:

    TYPE ST_Recipe :
    STRUCT
    Temp_SP : REAL := 180.0;
    Time_s : DINT := 600;
    Hold_s : DINT := 30;
    END_STRUCT
    END_TYPE
  4. Save (Ctrl+S). The PLC’s compiler checks the text and marks any error at its line.

The type’s name must be the POU’s name. A data type POU holds exactly one TYPE. The other forms (enumeration, subrange, union, alias type) are in the same Data type form list; see ST language: phase 3 additions.

  1. Click + again. POU Type: Global variables (GVL). POU Name: GVL_Line. Click Create POU.

  2. The list opens with one variable, already marked read-only from outside ({attribute 'access' := 'read'}). Replace it with your globals:

    VAR_GLOBAL
    {attribute 'access' := 'read_write'}
    {attribute 'write_range' := '0.0..120.0'}
    LineSpeed : REAL := 12.5;
    Recipes : ARRAY[1..NumRecipes] OF ST_Recipe;
    EStopOk : BOOL;
    PumpRun AT Recipes[2].Time_s : DINT;
    END_VAR
    VAR_GLOBAL CONSTANT
    NumRecipes : INT := 20;
    MaxSpeed : REAL := 120.0;
    END_VAR
  3. Save.

A global variable list in the eaxPLC Studio code editor, with read-write access on LineSpeed, an array of recipe structures, an alias onto a recipe member and a CONSTANT block, and live values next to the declarations. A global variable list in the eaxPLC Studio code editor, with read-write access on LineSpeed, an array of recipe structures, an alias onto a recipe member and a CONSTANT block, and live values next to the declarations.

A global variable list: attributes on the line before a declaration, a CONSTANT block, and live values once it runs.

What this list shows:

  • An attribute sits on the line before the declaration it applies to. Without an access attribute a declaration you type yourself is read-write from outside; see Set external access and write limits.
  • An array bound can be a CONSTANT, here NumRecipes, or a constant expression such as NumRecipes * 2.
  • PumpRun is an alias: a second name for Recipes[2].Time_s, with no storage of its own and exactly its target’s type.
  • A list holds VAR_GLOBAL blocks only. Do not write {gvl ...} lines: the PLC writes them when it links the project.

Open a program and use the names directly:

IF EStopOk THEN
Speed := LIMIT(0.0, LineSpeed, MaxSpeed);
Oven.SP := Recipes[Step].Temp_SP;
END_IF;

You may also declare VAR_EXTERNAL LineSpeed : REAL; END_VAR to show the dependency (the type must match), or VAR_EXTERNAL CONSTANT to make a global read-only in that POU.

A program variable may not have a global’s name: rename one of them (Speed is a global variable (GVL_Line): rename the local or use the global).

The new POUs are part of the saved project, but nothing runs until you test or deploy:

  • On a running line, click Test edits (Make online edits). The impact report lists the new globals as Added.
  • Otherwise, Build & Deploy.
  • The project tree shows Data types (DUT) › ST_Recipe and Global variables (GVL) › GVL_Line.
  • The Tags view (tag database) has one row per global, with its scope Global: GVL_Line, and the alias with Alias of Recipes[2].Time_s.
  • The Types view lists ST_Recipe with its size, members, and used by 20 instances.
  • Every program reads the same LineSpeed, initialised before any task runs in the first cycle.
Message Fix
expected variable name, got “Type” (TYPE is a reserved keyword: rename the variable) A variable has a reserved name. Rename it; add {attribute 'was' := 'Type'} on the new name to keep its value (Online changes to data structures).
global variable X declared twice (in GVL_A and GVL_B) A global name is used in two lists. Keep one.
VAR_GLOBAL belongs in a global variable list, not in a PROGRAM or FUNCTION_BLOCK … Move the block into a GVL POU.
CONSTANT NumRecipes needs a value Give every CONSTANT an initial value.
alias PumpRun : INT, but Recipes[2].Time_s is DINT (an alias has exactly its target’s type) Declare the alias with the target’s type.