Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Sample server code
August 28, 2023
12:48, EEST
Avatar
mgrenier
Member
Members
Forum Posts: 13
Member Since:
February 4, 2021
sp_UserOfflineSmall Offline

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.

August 28, 2023
16:18, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1026
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

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”:

CacheProperty property1 = new CacheProperty(this, new NodeId(getNamespaceIndex(), "ExtraProperty1"),
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:

UaProperty property2 = (UaProperty) createInstance(Identifiers.PropertyType, "ExtraProperty2");
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).

August 31, 2023
12:44, EEST
Avatar
mgrenier
Member
Members
Forum Posts: 13
Member Since:
February 4, 2021
sp_UserOfflineSmall Offline

Hi,

Thank you. it is exactly what I need.
Thank you again for your quick detail answer .

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
29 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Heikki Tahvanainen: 402

hbrackel: 144

rocket science: 88

pramanj: 86

Francesco Zambon: 83

Ibrahim: 78

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

Member Stats:

Guest Posters: 0

Members: 734

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1523

Posts: 6449

Newest Members:

christamcdowall, redaahern07571, nigelbdhmp, travistimmons, AnnelCib, dalenegettinger, howardkennerley, Thomassnism, biancacraft16, edgardo3518

Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1026, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0

Administrators: admin: 1