OPC UA Subscription in a C# Client app doesn't trigger event handlers|OPC UA Implementation: Stacks, Tools, and Samples|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
OPC UA Subscription in a C# Client app doesn't trigger event handlers
Avatar
Benjamin Hodzic_1
Member
Members
Forum Posts: 3
Member Since:
06/22/2023
sp_UserOfflineSmall Offline
1
06/22/2023 - 05:21
sp_Permalink sp_Print

I have a FactoryTalk server with some nodes and I need to monitor several attribute values.

I made a client which reads and writes data succesfully, but I can't get the subscription to work.

Here's the subscription configuration:

subscription = new Subscription(session.DefaultSubscription)
{
DisplayName = "Test subscription",
PublishingEnabled = true,
PublishingInterval = 500,
LifetimeCount = 0,
};

My monitored items:

monitoredItems = nodeAttrs
.Select(nodeId => new MonitoredItem(subscription.DefaultItem)
{
StartNodeId = nodeId,
AttributeId = Attributes.Value,
QueueSize = 1,
SamplingInterval = 500,
MonitoringMode = MonitoringMode.Reporting,
})
.ToList();

And I assign them the notification handler (I need the protocol object instance here, so I tweaked it):

MonitoredItemNotificationEventHandler monitoredItemEventHandler = (monitoredItem, e) => AttributeNotification(monitoredItem, e, protocol);

Then I add the event handlers:

foreach (var monitoredItem in monitoredItems)
{
monitoredItem.Notification += monitoredItemEventHandler;
}

And I add the items to the subscription and create it:

subscription.AddItems(monitoredItems);
session.AddSubscription(subscription);
subscription.Create();

I've checked through the console and the subscription gets created and assigned an ID by the server. I check all the monitored items as well, CreateMonitoredItems service call succeeds, and they also get client handles assigned, NodeId's are correctly resolved, with no error StatusCodes.

I make changes to the attributes via a 3rd party client application called UaExpert.

Yet I can't get the notification event handler to fire off.

Did I do something wrong?
Does anyone have advice on how to resolve/debug this?

Avatar
Randy Armstrong
Admin
Forum Posts: 1537
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
06/22/2023 - 21:05
sp_Permalink sp_Print

1) Do they fire if you write from your client?

2) Can poll the LastValue on MonitoredItems to see if the value changes but he notification is not being raised?

3) Sometimes notifications can be blocked in windows forms applications due to threading issues. Can you make sure the handler is something simple like Console.Write?

4) The Subscription has a notification handler as well. Check if that one is being called.

Avatar
Benjamin Hodzic_1
Member
Members
Forum Posts: 3
Member Since:
06/22/2023
sp_UserOfflineSmall Offline
3
07/25/2023 - 05:09
sp_Permalink sp_Print

Randy Armstrong said
1) Do they fire if you write from your client?

2) Can poll the LastValue on MonitoredItems to see if the value changes but he notification is not being raised?

3) Sometimes notifications can be blocked in windows forms applications due to threading issues. Can you make sure the handler is something simple like Console.Write?

4) The Subscription has a notification handler as well. Check if that one is being called.

  

Hi Randy, thank you for the reply.

1) No, they do not.

2) The value actually changes I've checked.

3) I've tried and the event handler doesn't fire.

4) This was actually a solution I implemented, not sure why this handler fires off upon the client startup though.

Also, just out of curiosity, what could be the reason why individual notification handlers on MonitoredItems don't work?

Avatar
Randy Armstrong
Admin
Forum Posts: 1537
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
4
07/26/2023 - 06:58
sp_Permalink sp_Print

Don't have any more suggestions. You should try here:

https://github.com/OPCFoundati.....iscussions

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 29
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1415
Posts: 4778