SIMATIC Automation Tool API for .NET framework
6.7 The IProfinetDevice interface
6.7.2.5
SetIP method
Return type
Method name
Result
SetIP
Name
Data type
nIP
uint
nSubnet
uint
nGateway
uint
This method is used to set or modify the IP address of a device.
For this operation to be successful, the device port configuration must be "Set IP address on
the device". This option may be named "SET IP address using a different method",
depending on the TIA portal version that you use.
The following example searches for a device at a specified MAC address, and sets its IP
address.
ulong targetMACAddress = 0x112233445566; // 11:22:33:44:55:66
IProfinetDeviceCollection scannedDevices = new IProfinetDeviceCollection();
Result retVal = myNetwork.ScanNetworkDevices(out scannedDevices);
if (retVal.Succeeded)
{
//------------------------------------------------
// Search for the device at that MAC, and Set IP
//------------------------------------------------
IProfinetDevice dev = scannedDevices.FindDeviceByMAC(targetMAC);
if (dev != null)
{
}
}
Note
The
addresses can be converted from string format to encoded uint using the following C# code:
string userEnteredAddress = @"192.168.0.1"; // For example
//-------------------------------
// Convert string address to uint
//-------------------------------
System.Net.IPAddress ip = IPAddress.Parse(userEnteredAddress);
byte[] bytes = ip.GetAddressBytes();
Array.Reverse(bytes);
uint encodedIp = BitConverter.ToUInt32(bytes, 0); // encodedIP can now be used
92
retVal = dev.SetIP(0xC0A80001, 0xFFFFFF00, 0x0);
method expects the addresses to be in encoded format (as shown above). The
SetIP
Parameters
Parameter type
In
In
In
Description
New encoded IP address
New encoded subnet address
New encoded gateway address
SIMATIC Automation Tool V2.1 user guide
Manual, V2.1.1 07/2016, A5E33042676-AC