SIMATIC Automation Tool API for .NET framework
6.6 The IProfinetDeviceCollection class
SIMATIC Automation Tool V2.1 user guide
Manual, V2.1.1 07/2016, A5E33042676-AC
77
The IProfinetDeviceCollection class
6.6.1
Iterating items in the collection
The ScanNetworkDevices method outputs an object of type IProfinetDeviceCollection. This
class provides the ability to iterate the items in the collection in multiple ways. It also
provides methods to "filter" the items in the collection based on certain criteria. The following
sections describe the functionality available for the collection.
Consider the example code from the ScanNetworkDevices method:
IProfinetDeviceCollection scannedDevices = new IProfinetDeviceCollection();
Result retVal = myNetwork.ScanNetworkDevices(out scannedDevices);
For those programmers that prefer array-like syntax, the items in
scannedDevices can be
accessed as follows:
if (retVal.Succeeded)
{
for (int deviceIdx = 0; deviceIdx < scannedDevices.Count; deviceIdx++)
{
//----------------------------------------------------------
// Each item in the collection is an IProfinetDevice.
//----------------------------------------------------------
IProfinetDevice dev = scannedDevices[deviceIdx];
}
}
The collection also supports iteration using the
foreach syntax. The following example shows
the same collection iterated using this syntax:
foreach (IProfinetDevice dev in scannedDevices)
{
//-----------------------------------------------------------
// The variable "dev" now represents the next collection item
//-----------------------------------------------------------
}