What is Structured Text

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. All of the languages share IEC61131 Common Elements. The variables and function calls are defined by the common elements so different languages within the IEC 61131-3 standard can be used in the same program. Complex statements and nested instructions are supported.

At first it may seem better to use a graphical programming language for PLC programming but there are pros and cons in each case. Like me, I have come to PLC from higher level programming language such as C/C++, so this fits to me better. Same general compilation process is used here.
We shall use Visual Studio for program development and download to PLC or simulator.

Memory Management

Library contains a number of functions which provide direct access to memory areas in the PLC runtime system of the PLC Controller. Default editor includes the library by default.


The fact that these functions allow direct access to the physical memory of the PLC. Misuse of such functions can result in a system crash, or in access to forbidden memory areas. So we need to be careful when we are using these function.


MEMCMP Compares the values of variables in two memory areas


MEMCPY Copies the values of variables from one memory area to another


MEMSET Sets the variables in a memory area to a particular value

Memcpy example




org : DINT :=12;

dest : DINT :=13;

another : DINT := 14;

myTimer : TON;

startTimer : BOOL := FALSE;




myTimer(IN:= startTimer, PT:=T#1S);


MEMCPY(ADR(dest), ADR(org),4);

MEMCPY(ADR(another), ADR(dest),4);


IF myTimer.Q = TRUE THEN

myTimer(IN:= FALSE);

org:= org +1;



How to add route for searching Beckhoff PLC


There are two methods to add  ADS route. If we don’t add the ADS route  then our PLC/PLC can’t communicate.

Method 01:

If you are developer this would be preferable way via visual studio as shown in the following image.

Choose Target will offer another dialog where we press on “Search Ethernet”  and this will give us the following dialog. If you have used the device previously then the first dialog will offer you an option to select that device.

Method 2:

Basically this is same like the verification process of Method 1. If we don’t have the Visual Studio environment then we can use this method. 

Click on the show hidden icon (small triangle) on bottom right corner and find the TwinCAT icon.

Press on the TwinCAT icon  Router | Edit Route

This will provide a dialog as shown in the following image.


If you press on the Add button that will open a dialog as shown in the method 1. The same process can be applied to complete the method.After adding the route our program can communicate with the PLC and we can read write any variable to the PLC.

We shall add a video tutorial soon here, so please visit us again



The Automation Device Specification (ADS) describes a device-independent and fieldbus-independent interface governing the type of access to ADS devices. The TwinCAT system architecture allows the individual modules of the software (e.g. TwinCAT PLC, TwinCAT NC, …) to be treated as independent devices: For every task there is a software module (“Server” or “Client”).

The messages between these objects are exchanged through a consistent ADS interface by the “message router”. This manages and distributes all the messages in the system and over the TCP/IP connections. TwinCAT message routers exist on every TwinCAT PC and on every Beckhoff BCxxxx Bus Controller.

This allows all TwinCAT server and client programs to exchange commands and data. 

ADS routes are used for communication on both sides by the respective ADS applications. ADS library (provided by Beckhoff) is used to communicate between PC (a TwinCAT device) with the Beckhoff PLC (another TwinCAT device). The ADS library wraps TCP/IP protocol so we don’t need to do anything with the communication.

We need to know the IP address of the target PLC device. If we know this will give us quick setup, if we don’t know the IP address then we can try Broadcast Search option. Even if we want to use this option we need to make sure that the PLC has the same network part. If you don’t know the IP address you can set the IP address and get the by directly connecting the monitor to the PLC and check it.

Put the IP address (not the AMS Net Id) in the edit box near the button Enter Host Name and press on the button. This will give the connection information of the PLC.

Select the found device and press on the IP Address radio button and Add Route (it will ask a password of the PLC). Press Close and OK. Done!

We can verify if the route has been added by opening little icon in the right hand corner of the PC and by opening the TwinCAT icon.

If we press on the icon then Router  then edit route will provide a info. If our PLC is visible there then it has been added correctly.

For network related issue please visit hemelix.com/network/


Visual studio may mess up sometime then it may be difficult to add route, in this case we need to follow this tips.

01: Clean the route from the PLC and the PC

02: Rebuild the project for target (for x86 PLC build it for x86)

03: Also check in which computer SCADA is running if SCADA can’t connect over ADS

How to change AMS Net Id

The AMS Net ID is the address of the local computer in the TwinCAT network. The AMS Net ID consists of 6 bytes and is represented in a dot notation. The “Net IDs” must be assigned by the project planner and must not be repeated in the TwinCAT network. By default, the installation generates an AMS NetID from the IP address of the system (if available) + “1.1”. If no IP address can be determined during the installation, the AMS NetID “” is created.

TwinCAT system generates AMS NetID which is difficult to remember. So we can build it by adding “.1.1” to the IP address.

For example, if the IP address is  then AMS net ID would be

We need to change the AMS net ID in the PLC side as well. 

Click on the bottom right corner TwinCAT Icon | Router | Change AMS Net ID

A dialog will be visible, add the AMS net ID (IP address + .1.1)

We shall add a video tutorial for this so please visit us again