AdsClient.AdsSumNotification Event

Occurs when Notifications are send (bundled notifications)

Namespace:  TwinCAT.Ads
Assembly:  TwinCAT.Ads (in TwinCAT.Ads.dll) Version: 6.0.328+39e3229

Syntax

C#

public event EventHandler<AdsSumNotificationEventArgs> AdsSumNotification

Value

Type: System.EventHandler.AdsSumNotificationEventArgs.

Implements

IAdsNotifications.AdsSumNotification

Remarks

As an optimization, this event receives all ADS Notifications that occurred at one point in time together. As consequence, the overhead of handler code is reduced, what can be important if notifications are triggered in a high frequency and the event has to be synchronized to the UI thread context. Because multiple notifications are bound together, less thread synchronization is necessary. The AdsNotification and AdsNotificationEx events shouldn't be used when SumNotifications are registered, because they have an performance side effect to this AdsSumNotification event. The full performance is reached only, when all notifications are handled on this event.

Examples

Example of receiving AdsSumNotification events.

Trigger on changed values by ADS Notifications

private async Task RegisterSumNotificationsAsync()
{
    CancellationToken cancel = CancellationToken.None;

    using (AdsClient client = new AdsClient())
    {
    // Add the Notification event handler
    client.AdsSumNotification += Client_SumNotification;

    // Connect to target
    client.Connect(AmsNetId.Local, 851);
    uint notificationHandle = 0;

    // Notification to a DINT Type (UINT32)
    // Check for change every 200 ms

    //byte[] notificationBuffer = new byte[sizeof(UInt32)];

    ResultHandle result = await client.AddDeviceNotificationAsync("MAIN.nCounter", sizeof(UInt32), new NotificationSettings(AdsTransMode.OnChange, 200, 0), null, cancel);

    if (result.Succeeded)
    {
        notificationHandle = result.Handle;
        await Task.Delay(5000); // Wait asynchronously without blocking the UI Thread.
                    // Unregister the Event / Handle
        ResultAds result2 = await client.DeleteDeviceNotificationAsync(notificationHandle, cancel);
    }
    client.AdsNotification -= Client_AdsNotification2;
    }
}

private void Client_SumNotification(object sender, AdsSumNotificationEventArgs e)
{
    // Timestamp of the Notification List
    DateTimeOffset dateTime = e.TimeStamp;

    // List of Raw ADS Notifications
    IList<Notification> notifications = e.Notifications;

    foreach(Notification notification in notifications)
    {
    // Notifications can be handled more efficiently, because they occur togeterh
    // handler and can be transformed/synchronized in one step compared to AdsClient.AdsNotifcation events.
    }
}

Reference

AdsClient Class

TwinCAT.Ads Namespace

AdsClient.AdsNotification