Adjustment of the IP Adress through TAG`s

iP adress modification through TAG

In this tutorial we described the orientations and procedure to change the IP adress and the subnet mask of your PLC while executing the application. This adjustment is possible through the use of function blocks available by the library SysSocket, from Codesys.  


Software:  MasterTool IEC XE 3.34;

CLP:  XP340 

Seções do Tutorial



2.1.  Inserting the library SysSocket_Implementation on MasterTool IEC XE

2.2.  Declaring the function blocks SysSockSetIpAddress and SysSockSetSubnetMask

2.3. Example using PLC XP3XXX

2.4. String identification of the Ethernet interface

2.5. Final observations




In this tutorial is described the steps to change the IP adress when the application is executing. It is necessary to insert the library  SysSocket_Implementation from MasterTool, to use the functions SysSockSetIpAddress and SysSockSetSubnetMask. 

2.1. Inserting the library SysSocket_Implementation on MasterTool IEC XE

The IP adress and subnet mask alteration can be configured while the application is executing. The library SysSocket from Codesys provides the functions needed (To additional information is possible to acess online help from Codesyse máscara de rede pode ser realizada em tempo de execução pela aplicação do PLC utilizando algumas funções disponíveis na biblioteca SysSocket do CODESYS (maiores informações podem ser consultadas Online Help).

The firs step is to include the library SysSocket Implementation in the project. 

Acess the Library Manager, at the treeview. 


When opened, select the option "Add library" and the button "Advanced".

Search for the library SysSocket Implementation, on Advanced > System > SysLibs. 

 2.2.  Declaring the function blocks SysSockSetIpAddress and SysSockSetSubnetMask

As mentioned before, both functions SysSockSetIpAddress and SysSockSetSubnetMask, from this librray, will be used. 

2.3. Example using PLC XP3XXX

An example of the function in the programming language ST (Structured text) with a controller XP3XX: 

In ths example, when bChangeIp isTRUE, the interface ‘eth0’ (that represents NET1 from the Xpress) will  receive the IP and subnet mask configurations. The functions will be executed in sequel conditioned by the returns Result and Result2 because when the value is 0, the functions were successfully executed. 

2.4. String identification of the Ethernet interface

The string identification of the ethernet interface is particular to every model, as showed in the image below:  

2.5.  Final observations

It is important to consider that, when the IP adress is modified, the connection with Mastertool will be lost (time out) and the applicattion will be stopped. Will be necessary to scan the gateway on easy connection and select the respective device. The configurations of NET1 don`t need to be updated.

It is also extremely necessary to know that this configuration is not retentive so, if the PLC has a power failure, when connected again the adress tha will return is the one configured on NET1. 

Do you have any questions? Then talk to us!


Was this publication relevant to you? Evaluate the material so we can continue to improve.

Click to save rating
Liked? Then share

Subscribe to our newsletter and learn all about automation!

Receive news about the automation market, our solutions and the latest actions involving Altus directly in your e-mail.