Automatically instantiating OPC UA object types at startup

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

Moderator: uasdkcpp

Post Reply
Etmund
Jr. Member
Jr. Member
Posts: 1
Joined: 12 Apr 2023, 20:08

Automatically instantiating OPC UA object types at startup

Post by Etmund »

Hello,

We're developing an OPC UA server based on the C++ SDK. The server loads an arbitrary nodeset.xml, defined by the user of our product. And during the startup and we need to automatically instantiate some of the object types defined in the nodeset. We managed to get this working, but the solution feels rather hacky and cumbersome. This might be due to our lack of experience with the SDK...

Could someone explain the proper way of doing something like that?

Here are some further details of what we do: We have our custom node manager. The node manager implements the objectTypeCreated method, where we get notified about the created types. Later on, in the allNodesAndReferencesCreated method we iterate through these types, traverse through their hierarchical references and more-or-less clone the object type node with all its child nodes under the Objects folder.

And here are some examples of the things that bother us:
  • The hierarchical references of the type node (e.g. 'HasComponent') are stored in the m_lstFullReferences of the UaBase::ObjectType. But this member seems to have no getter. We had to implement our own sub-class where this member is exposed.
  • To instantiate the type and its children, we need to "clone" the given nodes, so that the instance has the same properties as the type. It would be nice to use a copy constructor of UaBase::BaseNode, instead of getting-setting each attribute one by one. There is however only the generated copy-constructor and we're not sure if we can trust it.
  • When using the SDK functions we often need to "convert" between UaBase::BaseNode and UaNode. They both seem to represent OPC UA nodes but somehow in a different way. Not sure how they meant to be used, or if it's okay to keep switching between the two.
  • Some functions we'd like to use (e.g. Browse) require a session. However during startup we don't have any. Is there a way to call such methods without a real OPC UA session?
Thanks,
Etmund

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

Re: Automatically instantiating OPC UA object types at startup

Post by Support Team »

Hello Etmund,

I'm not sure if I understand the overall scenario. Is your custom NodeManager derrived from NodeManagerNodeSetXml? If yes after loading the NodeSet all nodes should already be there without the need to manually go through the BaseNodes. So I assume you only get information about the types from the NodeSet but not about the instances to create?
Since we currently don't provide a generic mechanism to instantiate arbitrary types there's not really a way to avoid going through the hierarchie and follow the references (that part you already solved).
Instead of adding that code in allNodesAndReferencesCreated you could add the code to create instances in the afterStartUp method of your nodemanager. That at least solves all issues related to dealing with BaseNodes and not having access to browse functionality.
Background:
The BaseNodes are used to build an intermediate model when parsing the nodeset. The SDK then uses that model to create the UaNodes in the address space.
Best regards
Unified Automation Support Team

Post Reply