<< Click to Display Table of Contents >> Navigation: »No topics above this level« Program content |
mapp Services V5.16
Structured Text programs are programmed in text files with extension ".st" or ".iec" as well as data objects with postfix "_st" or "_iec".
Structured Text programs are defined in section PROGRAM with attribute _MAIN. Attributes _INIT, _CYCLIC and _EXIT as used in Automation Studio ST are not supported.
In addition to program section _MAIN, the program can contain declaration sections.
TYPE
// Type declarations
END_TYPE
VAR
// Variable declarations
END_VAR
PROGRAM _MAIN
// Main program section
END_PROGRAM
A Structured Text program with variable (constant) declaration and main program
VAR CONSTANT
P1 : PointType := (Pos:=(X:=100));
END_VAR
PROGRAM _MAIN
MoveLR(P1); // linear rapid movement
END_PROGRAM
In addition to Structured Text programs, the declaration sections can be defined in standalone declaration files.
Recommended content |
|
.var / _var |
Variable declarations |
.typ / _typ |
Type declarations |
.fun / _fun |
Function / Function block declarations |
Scope defines the visibility of the element (variable, type, function, action) in ST programs.
The storage location defines the owner (location) of the element.
Scope and storage categories: Variable shared across all interpreter instances, e.g. all axis groups
•NC_GLOBAL: Element that is shared across all interpreter instances, e.g. all axis groups
•IP_GLOBAL: Element that is shared within the same interpreter instance, e.g. within the same axis group
•LOCAL: Element visible/shared within the file
The default scope is always defined by the file extension. Storage is always the same as scope. Storage for variables can be overridden in their declarations, however.
Default scope |
|
.st / _st |
LOCAL |
.iec / _iec |
LOCAL |
.var / _var |
IP_GLOBAL |
.typ / _typ |
IP_GLOBAL |
.fun / _fun |
IP_GLOBAL |
Comparison between variables declared in ST files and variables declared in VAR files
The file extension defines the default scope:
•In an ST file, the variable is only visible in the current program file.
•In a VAR file, the variable is visible in all files (program and declaration files).
Shared variables visible only in selected programs
Process variable "Home" (already created on the PLC) can be made available for all ST programs by declaring it in VAR file "defs.var". File "defs.var" must be loaded (started) before starting "program1.st" and "program2.st". The declaration of variable "Home" does not need to be repeated in ST programs "program1.st" and "program2.st".
Files "program1.st" and "program2.st" contain a declaration of variable "P1". This is due to file extension ".st", which is local to those files.
defs.var:
VAR {AT PLC}
Home : McPointType;
END_VAR
program1.st:
VAR CONSTANT
P1 : McPointType := (Pos:=(X:=100));
END_VAR
PROGRAM _MAIN
MoveJR(Home); //Rapid point-to-point movement
Feedrate(1000);
MoveJ(P1); //Point-to-point movement
END_PROGRAM
program2.st:
VAR CONSTANT
P1 : McPointType := (Pos:=(X:=200));
END_VAR
PROGRAM _MAIN
MoveJR(Home); //Rapid point-to-point movement
Feedrate(1000);
MoveJ(P1); //Point-to-point movement
END_PROGRAM
Topics in this section: