

12:48, EEST

February 4, 2021

Hello,
I follow the useful sample code to create dynamically instance of a node in the server address space.
I can’t find the way to add programmatically a property in the server (in this sample or in this forum).
Could you help me?
For example, how to add a property (nodeClass:variable, dataType: string…) in the myLevel node ?
Thank you.
16:18, EEST

April 3, 2012

Hi,
Generally we recommend using the createInstance of NodeManagerUaNode, but for Property it is a bit special since SDK handles them separately thus there is no direct PropertyType class (compared to the other codegenerated ones where SDK does have a class based on the OPC UA type).
You can either use the “pre-codegen style”:
new QualifiedName(getNamespaceIndex(), "ExtraProperty1"), LocalizedText.english("ExtraProperty1"));
myLevel.addProperty(property1);
or the createInstance works as well, but you must use NodeId based version of that:
myLevel.addProperty(property2);
The lines assume run within com.prosysopc.ua.samples.server.MyNodeManager.createAddressSpace() i.e. no exception handling etc. and they refer the MyLevel UaNode constructed earlier in the method.
For other reference types you would use UaNode.addReference methods (it can also be used for adding Property as that is just ReferenceTypeIdentifiers.HasProperty).
1 Guest(s)
