TcAdsClient.AddDeviceNotificationEx Method (String, AdsTransMode, TimeSpan, TimeSpan, Object, Type)
Connects a variable to the ADS client. The ADS client will be notified by the AdsNotification event.
Namespace: TwinCAT.Ads
Assembly: TwinCAT.Ads (in TwinCAT.Ads.dll)
Version: 4.3.0.0
Syntax
C#
public int AddDeviceNotificationEx(
string variableName,
AdsTransMode transMode,
TimeSpan cycleTime,
TimeSpan maxDelay,
Object userData,
Type type
)
VB
Public Function AddDeviceNotificationEx (
variableName As String,
transMode As AdsTransMode,
cycleTime As TimeSpan,
maxDelay As TimeSpan,
userData As Object,
type As Type
) As Integer
Parameters
variableName |
Type: System.String |
transMode |
Type: TwinCAT.Ads.AdsTransMode |
cycleTime |
Type: System.TimeSpan |
maxDelay |
Type: System.TimeSpan |
userData |
Type: System.Object |
type |
Type: System.Type |
Return Value
Type: Int32
The handle of the notification.
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;
}