Basics of Structured Text (ST) Programming | Examples & Applications - RealPars (2024)

In this article, we are going to discuss the basics of PLC programming utilizing Structured Text.

As one of the IEC-61131 PLC programming languages, Structured Text or just ST is based on and resembles traditional programming languages like Python or Java.

Rather than being visual or graphics-based like ladder logic or Function Block Diagram, Structured Text is just that, text!

Basics of Structured Text (ST) Programming | Examples & Applications - RealPars (1)

Structured text programming advantages

Like all programming languages, Structured Text has advantages and disadvantages, and there are also reasons you as a programmer might choose to use Structured Text in your next PLC programming project, so let’s get right into it.

1) No PLC programming background needed

Since Structured Text is similar to traditional High-Level programming languages, it can be fairly easy for many people who may not have a background in PLC programming but have experience in traditional coding to learn and develop PLC projects.

Basics of Structured Text (ST) Programming | Examples & Applications - RealPars (2)

2) ST is text-based

In most cases, you can also develop your Structured Text PLC programming project without using the PLC programming software. Since it is text-based, you can write your project in a simple text file and copy and paste it into your PLC project when you are ready.

Basics of Structured Text (ST) Programming | Examples & Applications - RealPars (3)

This also makes editing your project easier when you are debugging. While this feature of Structured Text is useful, remember that without your programming software like TIA Portal or RSLogix, you cannot compile and debug your program.

Basics of Structured Text (ST) Programming | Examples & Applications - RealPars (4)

Most PLC manufacturers support different programming languages in their PLC’s and this is because there are many different reasons that a programmer will choose a particular programming language.

These reasons can be as simple as a client request for a specific programming language all the way to the size of the programming project.

Basics of Structured Text (ST) Programming | Examples & Applications - RealPars (5)

3) ST is a lightweight programming language

Since Structured Text is by definition, text-based, it means that it does not have the memory-intensive graphical interface which can allow for a smaller processor memory and therefore a reduced cost.

This makes Structured Text an ideal candidate for larger PLC programs where controller memory is at a premium.

Basics of Structured Text (ST) Programming | Examples & Applications - RealPars (6)

4) ST programming files can be shared very easily

Some other times you might want to use Structured Text are when you are deploying the same PLC program over and over, such as in a packaged machine that is sent to a customer for a turn-key start-up.

Basics of Structured Text (ST) Programming | Examples & Applications - RealPars (7)

In these cases, your PLC program file can be stored offline in a text file or word document and can be easily sent as an email attachment for someone to download into the PLC and deploy.

Basic rules of ST syntax

The syntax of Structured Text follows some basic rules.

– First, all statements in Structured Text will end with a semicolon.

– A routine will close out with an End_If statement.

-Spaces and tabs are not required, but a good programmer will still use them for readability.

– Also, Structured Text is not case sensitive, but if you are assigning a variable, known as a tag or a symbol such as control valve 1, then using camelCase ControlValve1 is a good practice to get into.

Basics of Structured Text (ST) Programming | Examples & Applications - RealPars (8)

Use of comments in ST programming

Another very common and useful syntax of Structured Text is the use of a comment. As a beginning programmer, the use of comments is essential to creating code that can be read later on.

Here is an example of a comment in structured text programming:

(*this line of code will close control valve 1*)

As you can see, to add a comment in Structured Text you will start with a left parenthesis followed by an asterisk. To close your comment, you will then add another asterisk followed by a right parenthesis.

Structured text operators

Structured Text also uses operators to manipulate data. Some examples of operators are the logical operators such as AND, OR, and NOT. A logical operator is used to compare Boolean data and create logic from it.

Basics of Structured Text (ST) Programming | Examples & Applications - RealPars (9)

Structured text examples

An example of a logical operator in Structured Text looks like this:

Basics of Structured Text (ST) Programming | Examples & Applications - RealPars (10)

In this case, if the control valve 1 is NOT closed, the program would execute based on any following instructions that follow the instruction.

Here is another example:

Basics of Structured Text (ST) Programming | Examples & Applications - RealPars (11)

In this case, if the control valve 1 is closed, or if another parallel condition was true, the program would execute based on any following instructions that follow the instruction.

Remember, just because the expression told us that the control valve 1 is not closed, we still aren’t sure it is open! We will need to create logic that tells us that it is open.

Let’s create a simple statement in Structured Text to turn on a pump when the control valve is open.

First, let’s start by evaluating the state of the control valve. You will want to ensure that the valve is open by using this statement. IF ControlValve1_Closed is False AND ControlValve1_Open is True.

Basics of Structured Text (ST) Programming | Examples & Applications - RealPars (12)

With this statement, you have evaluated that the control valve is not closed and that the control valve is open.

Now, let’s turn on the pump. To do this you will add then Pump_Start is true to the statement.

Now that the pump is running, you need to add logic to stop the pump if the control valve closes. To do this you will simply add another statement to the logic as… IF ControlValve1_Closed is TRUE OR ControlValve1_Open is FALSE THEN pump start is FALSE.

Basics of Structured Text (ST) Programming | Examples & Applications - RealPars (13)

ELSIF statement

Now let’s put all of our statements together to create a routine. To do this you’ll have the first statement and then add ELSE below that. Next, you’ll have the second statement and then add… END_IF at the end.

With this routine, if the control valve 1 is not closed AND it’s open THEN the pump starts.

Otherwise, if the control valve 1 is closed and it’s not open then the pump stops. Very easy, right?

Basics of Structured Text (ST) Programming | Examples & Applications - RealPars (14)

To make this routine easier for others to read and understand, you can also add a comment above that.

So you’ll go with a left parenthesis followed by an asterisk and then add… this routine will start the pump when the control valve is open and stop the pump when the control valve is closed or not open. To close the comment, you will add another asterisk followed by a right parenthesis.

Congratulations! You have just created your first routine in Structured Text! How cool is that? While this simple tutorial was an introduction to Structured Text, adding the ability to utilize Structured Text in your projects will be another powerful tool in your programmer’s toolbox.

It allows you to create large and complex PLC projects quickly and efficiently while maximizing the allocation of memory.

We hope you enjoyed this easy-to-follow tutorial brought to you by the RealPars team.

If you have any questions about the Structured Text, or about programming languages in general, add them in the comments below and we will get back to you in less than 24 hours.

Got a friend, client, or colleague who could use some of this information? Please share this article.

Basics of Structured Text  (ST) Programming | Examples & Applications - RealPars (2024)

FAQs

What are the basics of structured text ST programming? ›

Basic rules of ST syntax

The syntax of Structured Text follows some basic rules. – First, all statements in Structured Text will end with a semicolon. – A routine will close out with an End_If statement. -Spaces and tabs are not required, but a good programmer will still use them for readability.

What are the basics of PLC? ›

A PLC's operation is broken down into three stages: inputs, program execution, and outputs. PLCs capture data from the plant floor by monitoring inputs from any connected machines or devices. These inputs are checked against the program logic, which changes the outputs to any connected output devices.

What does ST stand for in programming? ›

Structured text, abbreviated as ST or STX, is one of the five languages supported by the IEC 61131-3 standard, designed for programmable logic controllers (PLCs). It is a high level language that is block structured and syntactically resembles Pascal, on which it is based.

What is structured text programming function? ›

The structured text consists of a series of instructions which, as determined in high level languages, ("IF.. THEN..ELSE") or in loops (WHILE..DO) can be executed. An expression is a construction which returns a value after its evaluation. Expressions are composed of operators and operands.

What are the 3 main concepts of structured programming? ›

Structured programming is a program written with only the structured programming constructions: (1) sequence, (2) repetition, and (3) selection.

What are the three types of structured programming? ›

There are three categories of structured programming:
  • Procedural programming. Defines modules as procedures or functions that are called with a set of parameters to perform a task. ...
  • Object-oriented programming (OOP). Defines a program as a set of objects or resources to which commands are sent. ...
  • Model-based programming.

How to learn PLC programming for beginners? ›

Learn the basics of ladder logic: Ladder logic is the most common language used in PLC programming. Start by learning the basics of ladder logic, including the different types of contacts, coils, and timers. Study PLC hardware: Understand the hardware components of a PLC system and how they work together.

What are the 4 basic tasks will the PLC do? ›

There are four basic steps in the operation of all PLCs; Input Scan, Program Scan, Output Scan, and Housekeeping. These steps continually take place in a repeating loop. Energizes or de-energize all output devices that are connected to the PLC.

What kind of language is structured text? ›

Structured Text is a modern PLC or PAC programming language that looks very similar to traditional computer programming languages like Visual Basic or C++.

What are the languages used in PLC programming? ›

The five most popular PLC Programming Languages are Ladder Logic, Structured Text, Function Block Diagrams, Sequential Flow Charts and Instruction Lists. These methods of programming are available on most platforms.

Is Structured Text a programming language? ›

Structured text (ST) is a recognized programming language within the IEC standard and is becoming more frequently used within automation.

What are the examples of structured programming? ›

Structured Programming in Everyday Life
  • Sequence. Example: Baking Bread. Add flour. Add salt. Add yeast. ...
  • Repetition. Example: Washing Dishes. Stack dishes by sink. Fill sink with hot soapy water. While (there are more dishes) ...
  • Selection. Example: Sorting Mail. Get mail from mailbox. Put mail on table. While (more mail to sort)

What is an example of a structured text file? ›

Structured text files, such as TXT and CSV files, are stored in common row-wise format. In such a file, each row is a record and all rows have same columns.

What is meant by structured text? ›

6.3 Structured Text. Structured text is a programming language that strongly resembles the programming language Pascal. Programs are written as a series of statements separated by semicolons.

What are the elements of structured text? ›

A Structured Text program is organized into statements. Each ST statement consists of the following elements : label, comments, instructions. Each of these elements is optional, ie. it is possible to have an empty statement, a statement consisting only of comments or consisting only of a label.

What is structural typing in programming languages? ›

A structural type system means that the language decides whether types are compatible and/or equivalent based on the definition and characteristics of the types. Type checking determines whether and when types are verified. Static checking means that type errors are reported based on a program's text (source code).

What is the purpose of the sfc program? ›

The SFC standard is defined as Preparation of function charts for control systems, and was based on GRAFCET (itself based on binary Petri nets). It can be used to program processes that can be split into steps.

Is structured text a programming language? ›

Structured text (ST) is a recognized programming language within the IEC standard and is becoming more frequently used within automation.

Top Articles
Latest Posts
Article information

Author: Jeremiah Abshire

Last Updated:

Views: 6277

Rating: 4.3 / 5 (74 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Jeremiah Abshire

Birthday: 1993-09-14

Address: Apt. 425 92748 Jannie Centers, Port Nikitaville, VT 82110

Phone: +8096210939894

Job: Lead Healthcare Manager

Hobby: Watching movies, Watching movies, Knapping, LARPing, Coffee roasting, Lacemaking, Gaming

Introduction: My name is Jeremiah Abshire, I am a outstanding, kind, clever, hilarious, curious, hilarious, outstanding person who loves writing and wants to share my knowledge and understanding with you.