ST staple
An ST staple refers to a foundational or essential element within Structured Text (ST) programming, a high-level textual programming language defined by IEC 61131-3 for programmable logic controllers (PLCs). These staples are the basic building blocks and concepts that are universally used and considered crucial for understanding and writing effective ST code.
ST staples typically include:
-
Variables: Declared and typed memory locations used to store data. Understanding variable declaration (e.g.,
VAR
,END_VAR
), data types (e.g.,INT
,REAL
,BOOL
,STRING
), and scope (global, local) is fundamental. -
Operators: Symbols or keywords that perform operations on variables and values. These include arithmetic operators (+, -, *, /), comparison operators (=, <>, <, >, <=, >=), logical operators (AND, OR, NOT, XOR), and assignment operators (:=).
-
Control Structures: Statements that control the flow of execution within a program. Key control structures include:
IF-THEN-ELSIF-ELSE-END_IF
: Conditional branching based on Boolean expressions.CASE-OF-ELSE-END_CASE
: Multi-way branching based on the value of a variable.FOR-TO-BY-DO-END_FOR
: Looping a specific number of times.WHILE-DO-END_WHILE
: Looping while a condition is true.REPEAT-UNTIL-END_REPEAT
: Looping until a condition is true.
-
Functions and Function Blocks: Reusable blocks of code that perform specific tasks. Functions return a single value, while function blocks maintain internal state and can have multiple inputs and outputs. Understanding how to declare, call, and pass parameters to functions and function blocks is essential.
-
Data Types: The specification of the kind of values that variables can hold. Common data types are
BOOL
(Boolean),INT
(integer),REAL
(floating-point),STRING
(text),TIME
(duration), andDATE
(calendar date). Structured data types like arrays and structures are also considered staples. -
Addressing: Understanding how to access physical inputs and outputs of the PLC, often using special syntax or keywords.
-
Comments: Explanatory text within the code that is ignored by the compiler. Properly commenting code is considered a best practice and a staple of good ST programming.