14:12, EEST
July 7, 2016
Hello.
I have a problem with generated classes from my NodeSet2.xml. I have a test model with only TestObjectType, TestEventType and two objects, one from each type as you can see here
[img=https://s31.postimg.org/e0hpxho6f/Capture.png]
Now I want first of all to poll a sensor and then to send an event to all subscribers if the value changes. I tryed to call a handcoded method poll() in the afterCreate() but it doesn’t seem to work. Also there is no skeleton for event and subscribtion handling. But, since I am able to subscribe with a client to any of my objects my question is: is there maybe some predifiend methods to handle subscriptions and events? Also how do I get values from sensors without to call a special method with a client? Am I totally on the wrong way maybe?
Best regards,
Waldemar B.
16:29, EEST
April 3, 2012
Hi,
Subscriptions and events work out of the box (events are one form of Subcription). The codegenerated classes do extend the “basic” UaNode implementations which do handle this. The only reason why there is specific handling generated for methods is that we cannot know what a custom method would do, but the others are specified in the UA specification.
You can use setValue methods to set new value for a node, either directry to a node which has a Variable NodeClass or via the generated methods for object types. See e.g. MyNodeManager.simulate method in the samples. If the node is subscribed from a client, then it will receive the new value.
For events see the MyNodeManager.triggerEvent method in the samples, the event fields are the Properties/Components of the event node that is in the address space, see e.g. MyNodeManager.activateAlarm. In case you have a “one-shot” event that is not a node in the address space, create it with NodeManagerUaNode.createEvent methods, see MyNodeManager.sendEvent sample.
– Bjarne
14:50, EEST
July 7, 2016
Hello and thank you for the fast response.
Sorry for the previous question, it wasn’t clear what I really want.
My problem is: form Nodeset2.xml I have a generated class MySensorTypeNode. There I have a TwoStateVariable MyValue. The value of this variable should represent the sensor data. Now my question: how do I get this data? I tried it with a poll() method in the afterCreate in MySensorTypeNode, like
public void afterCreate(){
super.afterCreate();
poll();
}
pivate void poll(){
…..
}
Didn’t worked. My next idea was to poll the sensor within the SampleConsoleServer and to write the value to the variable in the object but how do I get the right object since I dont have only one sensor of MySensorTypeNode? I mean since it’s xml, it is only known to runtime if the object really exists and what it contains, so I cant just call setValue for e.g. NorthSensor2. Also I don’t want the setValue method for a sensor to visible for clients…..
Sorry for asking again, but I really don’t see an easy solution and would be happy for any help here.
Best regards,
Waldemar B.
16:07, EEST
April 3, 2012
I suppose this is one area of improvement for the future releases (2.3 or later; I would like to have some kind of Dependency Injection style options here, i.e. some kind of custom SDK user given contex to afterCreate or something).
If you create the instance of the MySensorTypeNode via a NodeManagerUaNode.createInstance(….) methods, the afterCreate method should be called normally. It is currently not called for instances defined in the XML (I suppose it could theoretically be done, but it is a bit hard to know if a node is toplevel node of a type and not a subnode, because the aftercreate is called for the top-level first and then it will call it automatically for subnodes, after those calls return, it could theoretically override those). Should probably be documented better..
Assuming you meant how to actually find the TwoStateVariable subnode from the aftercreate method (or elsewhere), see the generated classes more closely. The codegen generates 5 .java files for a type. An interface, which contains get/set/getnode methods for the subnodes. In addition to the interface, 2 classes are generated for each side (client/server): XXXTypeImplBase, XXXTypeImpl, XXXTypeNodeBase, XXXTypeNode. The Base classes implement the interface methods, the Impl/Node classes extend the Base class in order to provide possible additional methods, mainly used to allow implementations of the server side of the Methods defined for a type. Idea is that the Interface and Base files can be generated again easily while the Impl/Node classes contain custom code and wont be generated again normally.
The generated classes itself extend implementations of the UaNode interface that do most of the internal work (i.e. I’m trying to say that those implementations existed long before we did the codegen and that the codegenerated classes sort of provide more convinience methods of accessing the data, everything is possible to create/model using the “basic” implementations of UaNode(s), i.e. if there is no “special overload” for a given ObjectType registered via calling registerModel, the server would use instances of UaObjectNode class when creating instances of the ObjectType, but would need to find the subnodes e.g. via .getComponent(QualifiedName parameter that would be name given for the sub-componet. The codegenerated Base classes do have these “queries” generated in the get/set/getnode methods.
You can use the generated methods to set the value of the sub-node or alternatively get the node and call .setValue for it directly. Also to be clear I mean a Java method .setValue for the object returned in .getXXXNode() so it is not a UA method and therefore not visible in the address space (I would assuming this is what you mean by ‘client’).
Each Ua Node instance has several Attributes, one of them is NodeId which does give it an unique address so it can be found in the Address Space. You can find a node via UaClient/UaServer.getAddressSpace().getNode(NodeId) and also in server side via NodeManagerUaNode.getNode, see MyNodeManager in the samples. Currently you do need to cast the retuned node to correct type, but when you create the node via NodeManagerUaNode.createInstance that take a Class parameter in returns the node directly in correct java type (future 2.3 version will contain additional getNode methods that also take a Class parameter and does the casting automatically if possible)
– Bjarne
Most Users Ever Online: 1919
Currently Online:
24 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: 737
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1524
Posts: 6450
Newest Members:
fannielima, kristiewinkle8, rust, christamcdowall, redaahern07571, nigelbdhmp, travistimmons, AnnelCib, dalenegettinger, howardkennerleyModerators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1026, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0
Administrators: admin: 1