Page 1 of 1

Resolve dynamically the ObjectModel to be used for each new node

Posted: 11 Oct 2021, 15:24
by jramirez-jh
I'm working on a server that needs to create all the available nodes based on a custom xml file. The xml file basically contains two strings, one for the new node name and other for the name of the model object name that needs to be used for that node.

The client provided me the model .XML file exported from the UAModeler and also the Code classes (ModelClasses.cs ModelIdentifiers.cs ModelTypes.cs) but I'm a little lost trying to find a dynamic way to construct the ObjectModel instance for each specfic node.

Looking the sample code provided by the SDK I can see that the most common way is calling the concrete constructor for the required type (commonly located in the ModelClasses.cs) like this:

Code: Select all

NodeId myNodeId = new NodeId("mynewnodename", DefaultNamespaceIndex);
BaseObjectModel myNodeModelType = new UnifiedAutomation.Demo.Model.BoilerModel(); //This can't be done in my scenario
LinkModelToNode(myNodeId, myNodeModelType, null, null, 0);
But as my object model types are dynamic I can't just call it that way.

I need something like this:

Code: Select all

NodeId myNodeId = new NodeId("mynewnodename", DefaultNamespaceIndex);
BaseObjectModel myNodeModelType = ResolveObjectModelToBeUsed("nameofthemodeltype");
LinkModelToNode(myNodeId, myNodeModelType, null, null, 0);
Could you please guide my in how to resolve dinamically the object Model used in the LinkModelToNode method?

Re: Resolve dynamically the ObjectModel to be used for each new node

Posted: 01 Dec 2021, 15:42
by Support Team
Hello,
our DemoServer in DemoNodeManager.GenericDataTypes.cs provides example code of how to create generic DataTypes, Objects and Varialbes.
We hope this will help you to create your own generic model from your xml.