19:28, EEST
February 21, 2014
Good evening,
The title should have be named “Incorrect VariableTypes of Instantiated components of a custom BaseDataVariableType with a structured DataType”
I created an OPC UA data model using UaModeler, which contains a custom structure data type with 4 optional components. In UaModeler I selected to also automatically create a respective VariableType, containing the BaseDataVariable with the structure DataType and 4 (optional) BaseDataVariableType components, representing the individual structure elements.
Now another custom ObjectType definition contains the aforementioned automatically created Variable (mandatorily) and some other variables.
After generating code from the exported nodeset.xml, loading the nodesets and registering the models and instantiating the custom object, the server actually instantiates BaseVariableType instances for the underlying variables of the structured DataType variable instead of instances of BaseDataVariableType. As the generated code tries to cast the node to BaseDataVariableType, this cast fails and exceptions are thrown.
I tried to find out where those BaseVariabletype instances are created, but could not identify the spot.
Because the description above may be somewhat difficult to follow, here are the steps in short:
in UaModeler:
- create custom structured dataType with 4 optional element
- have UaModeler automatically create a variableTypeDefinition for the structured dataType
- create custom ObjectType definition with mandatory variable component from step 2)
- export nodesets.xml
in a custom ProsysSDK server:
- load/register models
- create instance of custom object
- try to set value of the variable instance from step 2 above
=> com.prosysopc.ua.types.opcua.server.BaseVariableTypeNode cannot be cast to com.prosysopc.ua.types.opcua.server.BaseDataVariableTypeNode
The createInstance method actually creates BaseVariableType instances instead of BaseDataVariableType instances.
The generated nodesets have the correct types.
Another related question would be, why all 4 component variables have been created by the createInstance() method, despite the fact that all of them are optional, the values had not been set, and no custom configuration for the node creation had been setup. Shouldn’t only mandatory nodes be instantiated automatically?
SDK v4.6.0
12:37, EEST
Moderators
February 11, 2020
Hello,
Could you provide a stack trace for this cast error?
Have you set InstanceDeclarationHierarchy.addInstanceDeclarationsTypeDefinitionOptionals to true? That would explain why optional Nodes are created by createInstance method.
If the NodeSet XML has correct VariableTypes, there could be a bug in the SDK and/or the CodeGenerator. Could you please send us the generated NodeSet XML file and the CodeGen configuration file used to generate code from it for testing? You can send the files to uajava-support@prosysopc.com
13:15, EEST
February 21, 2014
Hi,
I did not explicitly set the value of InstanceDeclarationHierarchy.addInstanceDeclarationsTypeDefinitionOptionals – the server is using whatever the default value for this variable is.
I will send you a subset of the nodesets to the address above.
NB: the generated classes contain the correct BaseDataVariableType nodes. So I assume that the code generator works correctly. Also, all optional nodes are annotated as such. Only the instances from createInstance() provide BaseVariableTypes
Thanks,
Hans-Uwe
16:01, EEST
April 3, 2012
Adding a note here as well of the general issue.
SDK automatically makes subnodes for ValueRank Scalar VariableType instances that have DataType which is a Structure type (and it will sync those nodes; there are some limits with arrays). The nodes in this case are nodes from that system, not the “general createInstance” (though the nodes are made as part of the process, i.e. they are not directly “modellingrule-based”). It would be a separate thing that should this logic be configurable.
Seems we have used BaseVariableTypeNode for the components for which there was not already an existing node. Since it is an abstract type this is wrong and BaseDataVariableTypeNode would be the correct one to use. And it is also sort of an error that the java type BaseVariableTypeNode itself is not abstract.
And using those subnodes via generated methods might … be sort of a scenario that has not though, but BaseDataVariableType is most likely what modelling tools would use (i.e. there is no direct knowledge of what type to use, or it could be quite complicated to get) .
Most Users Ever Online: 1919
Currently Online:
22 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: 735
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1523
Posts: 6449
Newest Members:
rust, christamcdowall, redaahern07571, nigelbdhmp, travistimmons, AnnelCib, dalenegettinger, howardkennerley, Thomassnism, biancacraft16Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1026, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0
Administrators: admin: 1