Structured Text (ST) is a high-level, text-based programming language supported by B&R Automation Studio, conforming to the IEC 61131-3 standard. It is specifically designed for developing complex and efficient control algorithms for industrial automation systems.
In Structured Text, each statement ends with a semicolon (;). A single statement can span multiple lines, and line breaks are interpreted as space characters, allowing flexibility in formatting the code for better readability.
ST is widely used in Programmable Logic Controllers (PLCs) to create logic for various industrial automation applications. The language supports a rich set of features including:
To begin programming in Structured Text using B&R Automation Studio, first create a new project. If you don’t have a physical PLC, no worries — B&R Automation Studio offers a PC-based simulation environment. During the project setup, select PC-based Simulation as the target system to enable development and testing without real hardware.
To add a program written in Structured Text, go to the menu bar, click on Insert → Add Object. Alternatively, right-click on the Logical View in the project tree and select Add Object.
In the Add Object dialog, choose Program. You can either create a new program or link to an existing one, then click Next.
Enter the name of your program and assign a local data type name. Optionally, you may add a description to define the purpose of the program. Then click Next.
In the initialization settings, choose Structured Text as the programming language from the drop-down list. This defines how the logic will be written and executed. Click Next to continue.
If prompted, you can assign the program object directly to the CPU. This links the code for runtime execution. After setting your preference, click Finish to complete the setup.
Once added, the new program appears under the Logical View of the project. It will typically include the following files and sections:
With these steps completed, your project is now ready for Structured Text programming. You can start developing logical operations, control algorithms, and advanced automation sequences using the powerful capabilities of the IEC 61131-3 Structured Text language in B&R Automation Studio.
In Structured Text (ST) programming within B&R Automation Studio, variables are fundamental elements used to store data. There are two main types of variables:
To declare global variables, open the Global.var file and define your variables there. For local variable declarations, open the .var file associated with your newly added Structured Text program. Add the required variable names, select their data types (e.g., BOOL, INT, REAL), and optionally define instance names for function blocks.
Open your inserted Structured Text program. The file follows a predefined layout structure in B&R Automation Studio. It begins with a file header section followed by the main program logic. The main program logic is defined between PROGRAM _CYCLIC and END_PROGRAM, which is the standard structure for cyclic execution blocks in B&R projects.
The file header section appears at the beginning of the ST program file. It contains meta-information about the source code, including:
This section is entirely commented out and is not executed by the PLC runtime. It serves documentation purposes only and can be edited to include your company name, website, developer contact details, and project version history.
The main program section starts with the declaration PROGRAM _CYCLIC and ends with END_PROGRAM. Inside this section, the logic of your automation process is implemented using Structured Text statements.
Each instruction must be terminated with a semicolon (;). You can use conditional statements, loops, assignments, logical operators, arithmetic expressions, and calls to function blocks.
The following is a simple example of a motor control logic using two momentary push buttons. One button (pb_start) is used to start the motor, and the other button (pb_stop) is used to stop it.
The logic is implemented using an IF...ELSE conditional structure. Logical operations are performed using AND, OR, and NOT operators to manage different input conditions.
If pb_start is pressed and pb_stop is not pressed, the motor turns ON. If pb_stop is pressed, the motor turns OFF.
This example is a good starting point to understand conditional logic in ST. Try creating variations with more inputs or interlocks. If you face any issues, feel free to ask questions in the comments or reach out to the developer community.
The image above illustrates a timer function block used in Structured Text. In B&R Automation Studio, timers such as TON (ON delay) are implemented as function blocks and must be instantiated with a variable name (known as the instance name).
In this example:
Make sure to declare the timer and its related variables correctly to avoid compile-time errors. Function block programming enables modular and reusable design in automation systems.