9:02, EET
January 5, 2024
Hi All
I am trying to create a method with one optional input argument. I found on ua specs that HasOptionalInputArgumentDescription can be used to achieve this but I didn’t find any example server that is supporting this.
Can anyone help me to understand how to create a optional input argument and how the client and server will process the HasOptionalInputArgumentDescription reference type to understand that current input argument is optional or not.
Thanks
10:39, EET
April 3, 2012
Hi,
Do you have an actual need for this or are you just asking in general?
In short, the SDK doesn’t support that feature yet, but you might be able to get it to work with instructions below. If you try, let us know how it goes.
The optional method arguments were added the OPC UA Specification in version 1.04, in Amendment 3. (And 1.05 included all previous amendments). In OPC UA lifetime scale this is quite recent. I’m not aware (but my view of the world is limited) of any actual server or client that would support this; you might be the first to ask this. In general OPC UA has way more features in the spec than what is actually implemented by servers and clients or supported by SDKs.
Anyway, please see the Figure 16 near the end of the page: https://reference.opcfoundation.org/Core/Part3/v105/docs/5.7, you would need to make similar instances using com.prosysopc.ua.server.NodeManagerUaNode.createInstance(…) (see e.g. com.prosysopc.ua.samples.server.MyNodeManager in sampleconsoleserver example for usage of createInstance). And then add using those reference types with com.prosysopc.ua.nodes.UaNode.addReference(…) to make the address space look similar to the figure.
The client side would process this information, in our SDK e.g. (UaClient) client.getAddressSpace().getNode(…) and then using the UaNodes and UaReferences to get the info. But this is all manual process that you would need to code yourself, i.e. there is nothing out of the box. If we talk about any “generic client” out there, my guess would be that it doesn’t support optional arguments, unless specifically built for a case as this is so recent addition to the spec.
You must also make the following things on the server side: For the NodeManagerUaNode (where you have the Method), you must make a subtype of com.prosysopc.ua.server.MethodManagerUaNode and set it via NodeManagerUaNode.setMethodManager(MethodManager). In the subtype override these:
1. com.prosysopc.ua.server.MethodManagerUaNode.checkInputArguments(Variant[], StatusCode[], DiagnosticInfo[], UaMethod):
You will need to validate the parameters manually, since SDK’s (i.e. if you call super) ones will throw if not all arguments were provided, or you can “fake” the optional parameters with some default values (you will need to make a new Variant[]) and then call super (Variant.NULL probably should work as the fake value).
2. com.prosysopc.ua.server.MethodManagerUaNode.callMethod(ServiceContext, NodeId, NodeId, Variant[], StatusCode[], DiagnosticInfo[])
To handle the Method call. You can see e.g. com.prosysopc.ua.samples.server.MyMethodManagerListener.onCall(ServiceContext, NodeId, UaNode, NodeId, UaMethod, Variant[], StatusCode[], DiagnosticInfo[], Variant[]) for a short example (that uses the CallableListener that can be added to the MethodManagerUaNode, typically that would be enough for handing a Method manually, but you need the whole subtyping of MethodManagerUaNode for the argument validation part; technically you can handle the Call part via a listener if you wish)
Please note that we have not tested this ourselves. And note that our Codegen tool that comes with the SDK also doesn’t understand optional arguments, thus it must be handled manually like this.
Most Users Ever Online: 1919
Currently Online:
44 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: 726
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1529
Posts: 6471
Newest Members:
gabriellabachus, Deakin, KTP25Zof, Wojciech Kubala, efrennowell431, wilfredostuart, caitlynfajardo, jeromechubb7, franciscagrimwad, adult_galleryModerators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0
Administrators: admin: 1