====== Structured Text ====== **Structured Text (ST)** is a high-level, **PASCAL-like textual programming language** designed for implementing complex control algorithms, mathematical calculations, and state machines within a controller. It is the preferred choice for software developers because it uses familiar programming constructs, including conditional statements, iterative loops, and explicit variable assignments. ST allows you to express complex functions in just a handful of lines of code, making it ideal for extensive projects. It is also the primary language used to create **custom function blocks**. {{ en:mervis-ide:40-st:st.png?600&direct |Structured Text Editor Example }} === Glossary: Key ST Terms === * **Assignment Operator**: The operator used to **assign** the result of an expression or value to a specific variable (e.g., `Variable := Value;`). * **Control Structures**: Keywords like **`IF-THEN-ELSE`**, **`CASE`**, **`FOR`**, and **`WHILE`** that define the non-sequential flow of the program execution. * **Expression**: A combination of variables, constants, and operators that is evaluated by the controller to produce a **single result value**. * **Variable Declaration**: The mandatory process of defining a variable's **name**, its **data type** (e.g., BOOL, INT, REAL), and its scope before use. * **Program Organization Unit (POU)**: A common term for a modular, reusable code block, which can be either a **Function** or a **Function Block**. === Example Code: Control Structures === The following examples demonstrate how ST uses control structures for logic and calculations. === Conditional Logic (IF...THEN) === This is used to execute a block of code only if a specified Boolean condition is **TRUE**. IF Temperature > 100.0 THEN Heater_Status := TRUE; Alarm_Light := TRUE; END_IF; === Selection Logic (CASE) === The `CASE` statement executes a specific block of code based on the value of an integer expression. CASE Input_Mode OF 1: // Mode 1: Manual Motor_Speed := 50; 2: // Mode 2: Automatic Motor_Speed := Auto_Setpoint; ELSE // Default for any other value Motor_Speed := 0; END_CASE; === Iterative Loop (FOR) === The `FOR` loop repeats a block of code a fixed number of times, using a counter variable. FOR i := 1 TO 10 DO Result_Array[i] := Result_Array[i] * 2; END_FOR;