This tutorial describes guidelines and procedures for changing the IP, subnet mask, and gateway of your PLC at runtime using function blocks provided by the SysSocket library of CODESYS in MasterTool.
Components
Software: MasterTool IEC XE 3.52;
PLC: XP340;
Firmware: 1.12.29.0
Tutorial Sections
1. ARCHITECTURE
2. DEVELOPMENT
2.1. Inserting the SysSocket_Implementation library in MasterTool IEC XE
2.2. Inserting the SysTypes2 Interfaces library in MasterTool IEC XE
2.3. Declaring the function blocks SysSockSetIpAddress and SysSockSetSubnetMask
2.4. Example using an XP3XXX programmable controller
2.5. Ethernet interface identification string
2.6. IMPORTANT final considerations
1. ARCHITECTURE
2. DEVELOPMENT
In this tutorial, we describe the steps to change your IP address, subnet mask, and gateway with the application running. It is necessary to insert a MasterTool library called SysSocket_Implementation to use the functions SysSockSetIpAddress, SysSockSetSubnetMask, and SysSockSetDefaultGateway.
2.1. Inserting the SysSocket library in MasterTool IEC XE
The change of IP address, subnet mask, and gateway can be performed at runtime by the PLC application using some functions available in the SysSocket library of MasterTool (more information can be found in the Online Help).
The first step is to include the SysSocket Implementation library in the project.
- Access the Library Manager in the device tree, as shown in the image below:
- When opened, select the option to add a library, as shown in the image below:
- A tab will open, click on the "Advanced..." option, as shown in the image below:
- Search for the "SysSocket Implementation" library and double-click to add it, as shown in the image below:
2.2. Inserting the SysTypes2 Interfaces library in MasterTool IEC XE
The SysTypes2 Interfaces library will also be needed, so repeat the previous steps with this other library.
2.2. Declaring the function blocks SysSockSetIpAddress, SysSockSetSubnetMask and SysSockSetDefaultGateway
As mentioned earlier, three functions from this library will be used: SysSockSetIpAddress, SysSockSetSubnetMask, and SysSockSetDefaultGateway.
2.3. Example using an XP3XXX programmable controller
Below is an example of use in ST language for an XP3xx controller:
In this example, when bChangeIp becomes TRUE, the ‘eth0’ interface (which represents NET1 of Xpress) will receive the IP, mask, and gateway settings. The functions are called in sequence, conditioned to their returns (Result, Result2, and Result3) because when zero, they indicate that the functions were executed successfully.
2.4. Ethernet interface identification string
The Ethernet interface identification string is specific to each controller model, as shown below:
2.5. IMPORTANT final considerations
It is important to consider that, when confirming the new configuration via application, there will be a disconnection from MasterTool (timeout). To log in again to the controller, it is necessary to rescan the Gateway and select the device. It is not necessary to change the NET1 configuration in the project.
If only the gateway address is changed, there will be no disconnection!
It should also be kept in mind that this configuration change is not retained, that is, when the controller is powered off and on, it will return with the IP configured in NET1 of the project.
Comments
0 comments
Please sign in to leave a comment.