NotifierParent

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

Moderator: uasdknet

Post Reply
christoph_krekels
Jr. Member
Jr. Member
Posts: 3
Joined: 29 Nov 2018, 10:08

NotifierParent

Post by christoph_krekels »

Hello,

I've got some problems in monitoring events with the UaExpert Client.
I modeled Objects with the UaModeler and generated the code.
Normally I create Objects manually by code with the CreateObjectSetting, where it is possible to set the NotifierParent like this:

Code: Select all

CreateObjectSettings settings = new CreateObjectSettings()      
                {
                    ParentNodeId = new NodeId(1000, InstanceNamespaceIndex),
                    ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
                    RequestedNodeId = new NodeId("CNC", DefaultNamespaceIndex),
                    BrowseName = new QualifiedName("CNC", InstanceNamespaceIndex),
                    TypeDefinitionId = new NodeId(ObjectTypes.MachineToolType, TypeNamespaceIndex),
                   
                    // need to create a notifier hierarchy for events to propagate.
                    [b]NotifierParent = UnifiedAutomation.UaBase.ObjectIds.Server,[/b]
                    EventNotifier = UnifiedAutomation.UaBase.EventNotifiers.SubscribeToEvents, //

                };
                ObjectNode InterNode = CreateObject(Server.DefaultRequestContext, settings);
with this object I have no problems in monitoring events.

But when I try to monitor the UaModeler created Object I can not monitor the events. In the modeler I set the EventNotifier of the specific Object to 1 (EventNotifierSubscribeToEvents), but it is not possible to set the NotfierParent for this Object.

Do you have any example code how to set the NotifierParent to an existing / UaModeler created Object? (Do I have to add it in the XML file?)
Or is there anything else what I can do?

Thank you in advanced.

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

Re: NotifierParent

Post by Support Team »

Hello Christoph,

you don´t need to add any code, the creation of a event hierarchy is a bit different in the UaModeler. In the Modeler the NotifierParent will not set at the object. You have to set a reference at the parent itself.
Setting the EventNotifier of the specific object to 1 is correct, but in addition you have to set a HasNotifier reference at the parent to the specific object.
Best regards
Unified Automation Support Team

User avatar
baldo
Hero Member
Hero Member
Posts: 22
Joined: 19 Nov 2019, 12:15

Re: NotifierParent

Post by baldo »

What if you created the object through the xml but you want to add the HasNotifier reference afterwards through code?

In particular I noticed that BaseNodeManager has a AddReference and a AddNotifier methods. I would like to add a forward HasNotifier reference from the 0:Server node to my object that was imported through the xml (but also a reverse reference from my object to 0:Server). How should I do that?

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

Re: NotifierParent

Post by Support Team »

Hello Baldo,

yes the AddReference method is right way to do it.

Let me explain how to use it in two examples.
  • First for References managed by the same NodeManager and
  • second for References to nodes managed by another NodeManager.
Syntax:

Code: Select all

AddReference(context, sourceNodeId, referenceTypeId, isInverse, targetNodeId, addBiDirectional)
Example 1: (creates a normal forward reference)
  • For context use the Server.DefaultRequestContext
  • sourceNodeId will be your ObjectIds.YourSourceNode (would be the server node in your case but because of the server node is normaly not in the same namespace look at Example 2)
  • referenceTypeId is ReferenceTypeIds.HasNotifier
  • isInverse = false ( will be used for backwards references, look at Example 2)
  • targetNodeId will be your ObjectIds.YourTargetNode
  • addBiDirectional should be true (set to true will create the reverse reference NotifierOf at the sourceNode, which can be used for browse)

Code: Select all

AddReference(Server.DefaultRequestContext, ObjectIds.YourSourceNode, ReferenceTypeIds.HasNotifier, true, ObjectIds.YourTargetNode, true)
To set the IsEventNotifier bit use the following code.

Code: Select all

var node = FindInMemoryNode(targetNode)as ObjectNode;
lock(InMemoryNodeLock)
{
    node.EventNotifier = ((byte)(node.EventNotifier | EventNotifiers.SubscribeToEvents));
}
Example 2: (creates an inverse reference)
  • For context use the Server.DefaultRequestContext
  • sourceNodeId in this case is your ObjectIds.YourTargetNode (because of the inverse refernce creation)
  • referenceTypeId is ReferenceTypeIds.HasNotifier
  • isInverse = true
  • targetNodeId will be your Server node ObjectIds.Server
  • addBiDirectional should be true (set to true will create the reverse reference NotifierOf at the sourceNode, which can be used for browse)

Code: Select all

AddReference(Server.DefaultRequestContext, ObjectIds.Your"Target"Node, ReferenceTypeIds.HasNotifier, false, ObjectIds.Server, true)
To set the IsEventNotifier bit use the code from Example 1.

You have to create the reference to the server node inverse (Example 2) because your NodeManager will not find the server node within its namespace.
Best regards
Unified Automation Support Team

User avatar
baldo
Hero Member
Hero Member
Posts: 22
Joined: 19 Nov 2019, 12:15

Re: NotifierParent

Post by baldo »

I never thank you because maybe it's best practice to avoid posting for such a thing in a forum, so I implicitly do even if I do not reply. But in this case I'm taking the occasion to thank you, this was really helpful!

I have a further question about this. As I mentioned I also see that there is an AddNotifier method (very little mention here: https://documentation.unified-automation.com/uasdkdotnet/3.0.9/html/L2ServerSdkServerManBaseNodeMan.html#L3ServerSdkServerManBaseNodeManIEventManagerEtc ). Playing around with it I think I managed to obtain the same that I was able to do with the AddReferences that you explained to me, but the way I should rather use (because our CS does not have those references), I mean creating a event notifier hierarchy without adding explicit references. In fact it should be possible to propagate events from an event source to the notifying nodes above it, without the need of a HasNotifier reference, because the event notifier hierarchy can be implicit according to the tree structure. And of course, what I just said only applies to the nodes in between this hierarchy that have the EventNotifier set to SubscribeToEvents, that makes them actually able to propagate the Events.

So, I created a hierarchy from node to subnode with that method, for example from the Server node to the Machines folder (from Machinery Companion Specification):

Code: Select all

AddNotifier(VDMA.McBase.ObjectIds.Machines.ToNodeId(Server.NamespaceUris), UnifiedAutomation.UaBase.ObjectIds.Server);
And so on from the Machines node to the machine instance in it, and then from the machine instance to the node that is source of events, using this very same approach. Now looks like it works perfectly, except if an Event is sent with UnifiedAutomation.UaBase.ObjectIds.Server as SourceNode. It used to work with your approach: I was able to send events of DeviceFailureEventType with that as SourceNode, but looks like with this kind of hierarchy creation i need to be explicit for the whole tree. My guess is that I need to call the AddNotifier method also from Server to something above it, maybe calling it from Server.CoreNodeManager?

Let me please know if this could be a viable way and if so, if I should add an AddNotifier to make the Server node propagate Events as well when it is also a source of events.

Thank you in advance!

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

Re: NotifierParent

Post by Support Team »

Hi Baldo,

can you tell us what you think at when you say "from Server to something above it". What is above your server node?
Best regards
Unified Automation Support Team

Post Reply