SIMATIC Automation Tool API for .NET framework
6.7 The IProfinetDevice interface
SIMATIC Automation Tool V2.1 user guide
92 Manual, V2.1.1 07/2016, A5E33042676-AC
New encoded subnet address
New encoded gateway address
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)
{
retVal = dev.SetIP(0xC0A80001, 0xFFFFFF00, 0x0);
}
}
SetIP method expects the addresses to be in encoded format (as shown above). 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