B&R Automation Studio Structured Text Programing Language

Published on May18, 2023 | Category: Structured Text
Share this article:

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:

One of the key strengths of Structured Text is its ability to create reusable code blocks, which can be modularized and reused across different programs, improving development efficiency and maintainability.
Structured Text is ideal for engineers who prefer text-based programming and need to implement mathematical operations, data manipulation, and advanced logic in a clear and organized manner.

How to Add a Structured Text Program in a B&R Automation Studio Project

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 InsertAdd 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.

img/br-automation-studio/enter-name-of-program-and-local-data-type.webp

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.

img/brautomationst/language-as-structured-text-in-program.webp

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.

img/br-automation-studio/select-an-option-if-you-want-to-assign-object-to-cpu.webp

Once added, the new program appears under the Logical View of the project. It will typically include the following files and sections:

img/brautomationst/b&r-automation-structured-text-program-files.webp

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.

Variable Declarations in Structured Text Programming

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.

img/brautomationst/declarations-of-variable-for-structured-text-program.webp

B&R Automation Structured Text Program Layout

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.

img/brautomationst/b&r-automation-structured-text-program-layout.webp

File Header Section in Structured Text Program

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.

img/brautomationst/file-header-section-structured-text-program.webp

Main Program Section of Structured Text

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.

img/brautomationst/main-program-section-of-structured-text-program.webp

Structured Text Example: Start/Stop Motor Logic

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.

img/brautomationst/br-automation-studio-structured-text-programing-example.webp

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.

B&R Structured Text Example: Timer Program

img/brautomationst/br-automation-studio-timer-program-in-structured-text.webp

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.