All Connected OPCUA clients received event notification.

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
skjangra
Full Member
Full Member
Posts: 9
Joined: 02 Jan 2017, 12:47

All Connected OPCUA clients received event notification.

Post by skjangra »

Hi,

whenever my opcua client connects to server, All connected clients receive event notification.
I require, the clients who call the refresh method should only get notified, not all connected clients.
while connecting server i am calling refresh method. because i want all events & alarms which is currently on server.

Code: Select all

 List<MonitoredItem> monitoredItems = new List<MonitoredItem>();
 EventMonitoredItem monitoredItem = new EventMonitoredItem(ObjectIds.Server);
            monitoredItem.SamplingInterval =250;
            monitoredItem.QueueSize =1000;
            monitoredItem.DiscardOldest = true;
            monitoredItem.MonitoringMode = MonitoringMode.Reporting;
            monitoredItem.Filter = new UnifiedAutomation.UaClient.ItemEventFilter(Subscription.Session.NamespaceUris);

           
            monitoredItem.Filter.SelectClauses.Add(ObjectTypeIds.ConditionType, (QualifiedName[])null, NodeClass.Object);
            monitoredItem.Filter.SelectClauses.Add(BrowseNames.EventId);
            monitoredItem.Filter.SelectClauses.Add(BrowseNames.EventType);
            monitoredItem.Filter.SelectClauses.Add(BrowseNames.ConditionName);
            monitoredItem.Filter.SelectClauses.Add(BrowseNames.ConditionClassId);
            monitoredItem.Filter.SelectClauses.Add(BrowseNames.Time);
            monitoredItem.Filter.SelectClauses.Add(BrowseNames.Severity);
            monitoredItem.Filter.SelectClauses.Add(BrowseNames.Comment);
            monitoredItem.Filter.SelectClauses.Add(BrowseNames.EnabledState);
           monitoredItem.Filter.WhereClauses.Add(FilterOperator.OfType, new LiteralOperand() { Value = new Variant(ObjectTypeIds.ConditionType) });
                monitoredItems.Add(monitoredItem);
                List<StatusCode> results = Subscription.CreateMonitoredItems(monitoredItems);
                List<Variant> inputArguments = new List<Variant>();
                inputArguments.Add(new Variant(Subscription.SubscriptionId));

                List<StatusCode> inputArgumentErrors;
                List<Variant> outputArguments;

                Subscription.Session.Call(
                    ObjectTypeIds.ConditionType,
                    MethodIds.ConditionType_ConditionRefresh,
                    inputArguments,
                    new RequestSettings() { OperationTimeout = 10000 },
                    out inputArgumentErrors,
                    out outputArguments);
can you tell me, whats wrong with above code.

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re: All Connected OPCUA clients received event notification.

Post by Support Team »

Hello,

Your code on client side is correct. It is a bug in the server if all connected clients receive the refresh events and the current alarms. What server are you using? We tried to reproduce the issue with .NET DemoServer. Here the events are reproted to the correct client.
Best regards
Unified Automation Support Team

skjangra
Full Member
Full Member
Posts: 9
Joined: 02 Jan 2017, 12:47

Re: All Connected OPCUA clients received event notification.

Post by skjangra »

hi,

Thank for reply. definitely i will share my server side code with you. But when i connect client using UA expart to my server, that time my other client(my application) not received any notification.
kindly check server side code.

Code: Select all

  public override void ConditionRefresh(RequestContext context, NodeId notifierId, MonitoredItemHandle itemHandle, EventNotificationEventHandler callback)
        {
            try
            {
                base.ConditionRefresh(context, notifierId, itemHandle, callback);
                List<GenericEvent> events = new List<GenericEvent>();

                // check list of alarms.
                foreach (AlarmConditionModel alarm in OffNormalAlarmList)
                {
                    GenericEvent e = null;
                    lock (alarm)
                    {
                        if (alarm.Retain && IsNotifierForSource(itemHandle.NotifierHandle, alarm.SourceNode))
                            e = alarm.CreateEvent(Server.FilterManager);
                    }
                    if (e != null)
                        events.Add(e);
                }
//etc....
          
                // report alarms after releasing all locks.
                foreach (GenericEvent e in events)
                {

                    ReportEvent(notifierId, e);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re: All Connected OPCUA clients received event notification.

Post by Support Team »

Hello,

Your implementation of ConditionRefresh creates the events. These events are reported to all clients, since you call ReportEvent instead of reporting the event by the callback.
However in the most use cases the implementation of the base class is sufficient, in these cases overriding is not required.

Please doublecheck your implementation. In our tests the alarms are reported to all connected clients including UaExpert if your implementation is used. With the implementation of the base class the events are only reported via the correct subscription.
Best regards
Unified Automation Support Team

skjangra
Full Member
Full Member
Posts: 9
Joined: 02 Jan 2017, 12:47

Re: All Connected OPCUA clients received event notification.

Post by skjangra »

Thanks for your support, your solution worked for me. i Used callback for notify event.

Regards,
Suresh

Post Reply