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
Simplest method examples
April 24, 2017
11:03, EEST
Avatar
Stegr
Member
Members
Forum Posts: 6
Member Since:
April 24, 2017
sp_UserOfflineSmall Offline

Hi,

I am trying to implement a simplest method in the SDK.

– No type information – I add an UAMethod directly
– No complex types – Method uses i=12 Strings as input and output values
– Method is completely described in a NodeSet XML file and loaded via .getAddressSpace().loadModel

Now the question, how should I add the actual implementation of the method? I have already tried to use codegen – no stubs are generated there…

April 24, 2017
12:07, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

Codegen creates java types to match UA ObjectTypes and VariableTypes, i.e. the method must part of an ObjectType with a direct HasComponent Reference for a stub to be generated for it. This the same principle as in object oriented programming languages, i.e. in java you have class files, which have methods, which you can then call on instances of that class.

Assuming the method is not part of a type, then currently you need to react to method calls with a listener, see SampleConsoleServer example and classes MyNodeManager and MyMethodManagerListener.

– Bjarne

April 24, 2017
12:26, EEST
Avatar
Stegr
Member
Members
Forum Posts: 6
Member Since:
April 24, 2017
sp_UserOfflineSmall Offline

okay, and i only have to add the generated type-class to my project? Will it automatically “attach” to instances that are described in the xml file?

April 24, 2017
13:54, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

We really need to create a FAQ for this as it is now asked often enough and this is a complex subject.

See SampleConsoleServer.loadInformationModels(). You need to call UaServer.registerModel before loading the model with UaServer.getAddressSpace().loadModel (or use UaServer.registerAndLoad).

Currently it is better to create instances in the code than in the XML file. You can create instances with NodeManagerUaNode.createInstance. There are some edge-cases where instances wont work 100% correctly when loaded from the XML. However, If the instances do not require “anything special” then they should work also when loaded from the XML. As long as there is no event&alarm instances or instances of TwoStateVariableType loading instances from the XML should work.

Eventually the idea is that loading instances from the XML would be the same as creating them with NodeManagerUaNode.createInstance.

– Bjarne

April 24, 2017
22:23, EEST
Avatar
Stegr
Member
Members
Forum Posts: 6
Member Since:
April 24, 2017
sp_UserOfflineSmall Offline

Thank you, I took the code generation path and it worked

April 25, 2017
12:13, EEST
Avatar
Stegr
Member
Members
Forum Posts: 6
Member Since:
April 24, 2017
sp_UserOfflineSmall Offline

Well, a FAQ is something which I miss a lot, there some simple use-cases for a start up an opc ua integration:

– How to expose a java variable (attribute, typed opc ua variable)
– How to expose a java method
– How to handle user-access (access levels, sessions)

April 25, 2017
15:10, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Did you read the readmes, tutorials and the SampleConsoleServer example? Also please read the OPC UA Specification on how the address space works (Part 3).

From the SampleConsoleServer:
– How to expose a java variable (attribute, typed opc ua variable): See MyNodeManager and code related handling myLevel field.
– How to expose a java method: See MyNodeManager and code related to myMethod field and MyMethodManagerListener class.
– How to handle user-access (access levels, sessions): See MyUserValidator, MyIoManagerListener and read the comments in the code.

In general it is not possible to “expose” e.g. a simple java double, in case you are thinking something along e.g. JAXB, JPA, Jackson annotations. The reason that in UA there is currently 22 possible Attributes for a node. Depending on the NodeClass Attribute, some of these are mandatory, optional and not applicable. And there are 8 different NodeClasses. In addition there are References to other nodes. In short there is lots of information modelling data in addition to the Value Attribute.
However see MyBigNodeManager sample, it might be what you want or at least close (but I would recommend using NodeSet XML -> codegen -> NodeManagerUaNode.createInstance workflow if possible). Otherwise I would need a more in depth explanation what you mean by “expose”.

Ua Methods (NodeClass Method) nodes have Input/OutputArguments subnodes which defines the parameters, which have Value Attribute of Argument Structure DataType, which defines name, description, data type, possible dimensions and their sizes of the input parameters. Currently the options are codegen and MyMethodManagerListener style. If we find a better way then it could be done for next major version.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
14 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 77

Ibrahim: 76

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

fred: 41

Member Stats:

Guest Posters: 0

Members: 683

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6261

Newest Members:

digitechroshni, LouieWreve, Kickbiche, karrimacvitie5, graciela2073, sagarchau, elviralangwell4, Donnavek, Eddiefauth, DonaldPooma

Moderators: Jouni Aro: 1010, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 983, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 26, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 321, Lusetti: 0, Ari-Pekka Soikkeli: 5

Administrators: admin: 1