![Avatar](https://opcfoundation.org/wp-content/uploads/sp-resources/forum-avatars/defaults/userdefault.png)
06/22/2023
![sp_UserOfflineSmall](https://opcfoundation.org/wp-content/sp-resources/forum-themes/reboot/images/darkpack/sp_UserOfflineSmall.png)
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](https://opcfoundation.org/wp-content/uploads/sp-resources/forum-avatars/defaults/admindefault.png)
05/30/2017
![sp_UserOfflineSmall](https://opcfoundation.org/wp-content/sp-resources/forum-themes/reboot/images/darkpack/sp_UserOfflineSmall.png)
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](https://opcfoundation.org/wp-content/uploads/sp-resources/forum-avatars/defaults/userdefault.png)
06/22/2023
![sp_UserOfflineSmall](https://opcfoundation.org/wp-content/sp-resources/forum-themes/reboot/images/darkpack/sp_UserOfflineSmall.png)
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?
1 Guest(s)