Skip to main content

Briefly about Structured Text (ST) programming

Structured Text, often abbreviated as ST, stands as a PLC programming language outlined by the IEC-61131 standard. It bears a closer resemblance to conventional programming languages like Python or Java rather than using graphical language blocks typical of LAD or FBD. Essentially, Structured Text is purely textual!

Basic rules of syntax of the ST language

Structured Text syntax follows several basic rules:

  • Initially, every statement in program ends with a semicolon.
  • While the use of spaces and tabs isn’t mandatory, a proficient programmer will employ them to enhance readability.
  • Furthermore, ST does not differentiate between uppercase and lowercase letters, yet adopting camelCase for variable naming (such as xValve1) is considered a best practice.
  • Variable names are typically defined using Hungarian notation, which involves adding a prefix that indicates the variable’s type, for example, xLight for a BOOL type, and iTemperature for an INT type.

Creating first project in Codesys

1. Open Codesys and click New project…

2. Choose a Standard project.

3. Type a name of your project, for example, “Project1”. And click the OK button.

4. Choose a device, as in the photo below, and choose Structured Text language.

5. Open your program by double clicking on PLC_PRG on the left-side menu.

6. Let’s configure a project – go to Tools -> Options…

7. Select SmartCoding -> Check “Enable for ST editor”. This option will allow us to quickly declare variables.

8. Write the first line of code– if xPbutton1 and xPbutton2 are pressed, enter “TRUE” into xLamp.
In ST this looks
like this:

xLamp := xPbutton_1 AND xPbutton_2;

9. Now, we have a code, but our variables are not declared. Click ENTER on the keyboard, and you will see declaring windows. Choose the type “BOOL” for all of variables by clicking OK

10. Now, let’s start our program on PLC simulator. Go to Online -> Login

11. Click Yes. Now our program will be uploaded to the PLC simulator.

12. We have started the simulations and see the current states of the variables.

13. Click > icon to set the PLC in RUN mode.

14. By double clicking left mouse button you can force a value of the variable to “TRUE”. To force values click Ctrl+F7.

15. Change a value of two buttons and your program will be working properly!

You have already created your first working program in ST. Now start writing your own programs. Below you will find materials with useful knowledge. Good luck with your programming!

Check out sample Structured Text instructions below

Now u can join to our PLC programming course and boost your knowledge and skills in Codesys!
https://controlbyte.tech/basic-structured-text-plc-programming-in-codesys/

Author

Simon Adamek

Author Simon Adamek

More posts by Simon Adamek

Leave a Reply