Browse FAQs

How to dynamically change the IP address of a M251 controller using SoMachine?

Published date: 08 December 2018

Issue:
This is a step by step procedure on how to write a small program in SoMachine to dynamically change the IP address of a M251 controller

Product Line:
M251 controllers

Environment:
SoMachine v4.3

Cause:
To have a project that will help a customer dynamically change the IP address of a M251 controller

Resolution

The changeIPAddress function block provides the capability to change dynamically a controller IP address, its subnet mask and its gateway address. The function block can also save the IP address so that it will be used in subsequent reboots of the controller.
NOTE: Changing the IP address is only possible if the IP mode is configured to fixed IP address

1. Start a new project in SoMachine and select a M251 controller
2. In the Devices window right-click on the Application / Add object / Pou. For this example the Implementation Language is Continuous Function Chart
3. Add this POU to the MAST Task
4. The library containing the ChangeIPaddress function block will have to be added to the project: go to Devices window / Library Manager / Add Library / uncheck Group by Category / select and add Ethernet Util Library
5. In your POU add a box and type changeIPaddress instead of the ???. Hit Enter and then Enter again to autodeclare the function block instance.
6. Create the input variables for the changeIPaddress. In the declaration window we declared the following variables:


PROGRAM POU
VAR
    changeIPAddress_0: changeIPAddress;
    Execute_0: BOOL;
    Save_0: BOOL;
    IPAddress_0: ARRAY [0..3] OF BYTE := [192, 168, 100, 50];
    IPMask_0: ARRAY [0..3] OF BYTE := [3(255), 0];
    IP_Gateway_0: ARRAY [0..3] OF BYTE := [192, 168, 100, 1];
END_VAR

Notes:
- The new IP address, subnet mask and Gateway IP address were initialized with values to be used by the function block
- The input eChannel is the Ethernet port to be configured. Depending on the number of the ports available on the controller, it will be either 0 or 1. It this example 0 was used for Ethernet_1

7. In the Device window double-click on Ethernet_1 and set the IP Address, Subnet Mask and Gateway Address for Ethernet_1 using a fixed IP Address setting. This is the address that will be part of the project and the one that we will change using the changeIPaddress function block
8. Download the program to the controller and then login
9. Turn on the xExecute bit of the changeIPaddress function block and wait for the Done bit to turn on, it may take a few seconds. After the Done bit is ON, the controller has a new IP address. However, this IP address is temporary, if the M251 is rebooted, it will revert back to the IP address in the project
10. To
save the new IP Address, Subnet Mask and Gateway Address for subsequent reboots of the controller, turn on the xSave bit and then execute the changeIPAddress by tuning on the xExecute bit. This will create a Machine.cfg file on the controller with this new parameters. They will overwrite the parameters in the SoMachine project. You can locate that file while you are online at the following location: in the Device window double-click on MyController / Files tab / click on Refresh in the right Runtime window and navigate to the Cfg folder.



This completes the step by step procedure on how to write a small program in SoMachine to dynamically change the IP address of a M251 controller

 

Was this helpful?

What can we do to improve the information ?

Can't find what you are looking for?

Reach out to our customer care team to receive information on technical support, assistance for complaints and more.