TcAdsClient.AdsNotificationEx Event

Occurs when the ADS devices sends an (extended) notification to the client.

Namespace:  TwinCAT.Ads
Assembly:  TwinCAT.Ads (in TwinCAT.Ads.dll) Version: 4.3.0.0

Syntax

C#

public event AdsNotificationExEventHandler AdsNotificationEx

VB

Public Event AdsNotificationEx As AdsNotificationExEventHandler

Value

Type: TwinCAT.Ads.AdsNotificationExEventHandler

Implements

IAdsNotifications.AdsNotificationEx

Remarks

In most implementations, these notifications indicate changed values on the client target. These 'ADS notifications' will be received asynchronously from the target system and distributed via this AdsNotification event. IMPORTANT: The Default setting of the Synchronize property has changed to 'false' from Version 4.2.XX on. This has the effect that - by default - the notifications events and AdsNotificationEx are not synchronized into the UI thread anymore. To re-enable the obsolete behavior for legacy applications set to 'true'.AdsNotificationSynchronize

Examples

The following sample shows how to use AdsNotificationEx events.

Receive AdsNotifications

//AdsStream readStream = new AdsStream(sizeof(UInt32));

private void ReceiveNotifications()
{
    using (TcAdsClient client = new TcAdsClient())
    {
    // Add the Notification event 'Ex' handler
    client.AdsNotificationEx += Client_AdsNotification;

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

    try
    {
        // Notification to a ZDINT Type (UINT32)
        // Check for change every 200 ms
        notificationHandle = client.AddDeviceNotificationEx("MAIN.nCounter",AdsTransMode.OnChange, 200, 0, null,typeof(uint));
        Thread.Sleep(5000); // Sleep the main thread to get some (asynchronous Notifications)
    }
    finally
    {
        // Unregister the Event / Handle
        client.DeleteDeviceNotification(notificationHandle);
        client.AdsNotificationEx -= Client_AdsNotification;
    }
    }
}

private void Client_AdsNotification(object sender, AdsNotificationExEventArgs e)
{
    // Or here we know about UDINT type --> can be marshalled as UINT32
    uint nCounter = (uint)e.Value;
}

Reference

TcAdsClient Class

TwinCAT.Ads Namespace

TcAdsClient.AddDeviceNotificationEx(Int64, Int64, AdsTransMode, Int32, Int32, Object, Type)

TcAdsClient.DeleteDeviceNotification(Int32)

TcAdsClient.AdsNotification

TcAdsClient.AdsNotificationError