SIMATIC Automation Tool API for .NET framework
6.7 The IProfinetDevice interface
SIMATIC Automation Tool V2.1 user guide
Manual, V2.1.1 07/2016, A5E33042676-AC
95
The ProgressChanged event is supported on the IProfinetDevice interface.
This event allows the program to monitor the progress of methods that take a long time.
FirmwareUpdate is one example of such a method.
To utilize the event, an event handler is attached to the event. The event handler is then
automatically called when there is a change in the progress of the operation.
The following example shows how this can be used. This example shows a method that is
updates the firmware for a device on the network. This operation may take noticeable time.
To monitor the progress of the action, an event handler is defined and attached to the
ProgressChanged event. Once the firmware update is complete, the event handler is detached
from the event.
private void UpdateCpuAtAddress(IProfinetDeviceCollection devices,
uint targetIPAddress, string updateFile)
{
IProfinetDevice dev = devices.FindDeviceByIP(targetIPAddress);
if (dev != null)
{
dev.ProgressChanged += new
ProgressChangedEventHandler(Dev_ProgressChanged);
dev.FirmwareUpdate(new EncryptedString(""), updateFile, dev.ID, true);
dev.ProgressChanged -= new
ProgressChangedEventHandler(Dev_ProgressChanged);
}
}
private void Dev_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
IProfinetDevice device = sender as IProfinetDevice;
double percent = 0;
if (device != null)
{
if (e.Count != 0)
{
percent = (double)e.Index / (double)e.Count;
string sPercent = e.Action.ToString() + " -> " +
"Index = " +
e.Index.ToString() +
" Count = " +
e.Count.ToString() +
" progress " +
(percent * 100).ToString("0.##") + "%";
}
}