EasyManua.ls Logo

Siemens SIMATIC S7 - Setip Method

Siemens SIMATIC S7
134 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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
6.7.2.5
SetIP method
Return type
Method name
Result
SetIP
Parameters
Name
Data type
Parameter type
Description
nIP
uint
In
New encoded IP address
nSubnet
uint
In
New encoded subnet address
nGateway
uint
In
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);
}
}
Note
The
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

Table of Contents

Other manuals for Siemens SIMATIC S7

Related product manuals