TwinCAT stops sending notifications after a few seconds

263 Views Asked by At

using the ADS.NET Interface for TwinCAT (Package Beckhoff.TwinCAT.Ads 6.0.235) together with TwinCAT 3.1.4024.42 (as of today) we are experiencing an undesired effect.

When connecting to a variable by notification with a cycle of notification update of 1 ms, after a few seconds no more notifications are being sent, when the connected variable frequently updates.

Here is a sample how the notification is being setup:

 public bool ConnectVar(object userData)
    {
        bool ret = false;

        ConnectTc();                // Connect to TwinCAT, create _tcClient
        _vartype = GetVarType();
        if (!(_vartype is null))
        {
            NotificationSettings settings = new(_transmode, _cycleTimeMs, 0);

            _handle = _tcClient.AddDeviceNotificationEx(Varname, settings, userData, _vartype);
            _tcClient.AdsNotificationEx += _tcClient_AdsNotificationEx;

            _handleRw = _tcClient.CreateVariableHandle(Varname);
            if (_handle != 0 & _handleRw != 0)
            {
                ret = true;
                _connected = true;
            }
        }

        if (_connected)
        {
            _lastReceivedValue = Value;
            _lastReceivedValueTimeStamp = DateTimeOffset.Now;
        }

        return ret;
    }

And this is the notification handler

    private void _tcClient_AdsNotificationEx(object? sender, AdsNotificationExEventArgs e)
    {
        _lastReceivedValue = e.Value;
        _lastReceivedValueTimeStamp = e.TimeStamp;
    }

So when setting the Update Cycle time to 1 ms, after a few seconds (about 5) no notifications at all arriving anymore. No errors / exceptions are being created, the notifications just stop. When deleting the notification and adding it new, values are being received again - for 5 seconds. When increasing the cycle time to 2 ms, it seems to "work". Somehow this effect is hard to handle as one can not be sure, what conditions are necessary ...

So, did anyone experience a similar problem and know how to handle this ?

0

There are 0 best solutions below