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
Incorrect Generated Code for DataVariable Type With Structured DataType
March 30, 2022
19:28, EEST
Avatar
hbrackel
Member
Members
Forum Posts: 135
Member Since:
February 21, 2014
sp_UserOfflineSmall Offline

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:

  1. create custom structured dataType with 4 optional element
  2. have UaModeler automatically create a variableTypeDefinition for the structured dataType
  3. create custom ObjectType definition with mandatory variable component from step 2)
  4. export nodesets.xml

in a custom ProsysSDK server:

  1. load/register models
  2. create instance of custom object
  3. 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

April 1, 2022
12:37, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 321
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

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

April 1, 2022
13:15, EEST
Avatar
hbrackel
Member
Members
Forum Posts: 135
Member Since:
February 21, 2014
sp_UserOfflineSmall Offline

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

April 1, 2022
16:01, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

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) .

April 4, 2022
10:33, EEST
Avatar
hbrackel
Member
Members
Forum Posts: 135
Member Since:
February 21, 2014
sp_UserOfflineSmall Offline

On the part of the initialization of the array variable with a scalar value…

A closer look at the exported UaModeler nodeset indeed showed that UaModeler already generates the scalar initial value. So the incorrect behaviour has been caused by the nodeset.xml and not by the Java SDK.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
12 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 77

ibrahim: 75

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

fred: 41

Member Stats:

Guest Posters: 0

Members: 685

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6259

Newest Members:

fidelduke938316, Jan-Pfizer, DavidROunc, fen.pang@woodside.com, aytule, rashadbrownrigg, christi10l, ahamad1, Flores Frederick, ellenmoss

Moderators: Jouni Aro: 1009, 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