10:53, EEST
January 30, 2014
Hi,
I have next issue. I found some nodes (of class Variable) which DataType attribute differs from data type which need to be used for r/w of variable.
For example in UAExpert cpp demo server there is a node Demo.Static.Scalar.UInteger which attribute data type is UInteger.
UInteger is defined as super type of Byte, UInt16, UInt32 and UInt64.
So when I am using: (UaDataType) uaVariable.getDataType() it will return UInteger
but when I am using: uaVariable.getValue().getValue().getCompositeClass() it wil return UInt16
The question is what kind of nodes these are? Is it possible in opcua to have nodes which DataType is supertype and during runtime “real” type can be
subtypes or it must be one subtype all the time?
In example above I tried to write UInt32 instead UInt16 to Demo.Static.Scalar.UInteger but it does not work. It accepts only UInt16.
The similar example is Duration. I found that value for some servers are of type Int32 and for the most servers are Double.
Is it safe always to get type for writing by using uaVariable.getValue().getValue().getCompositeClass()?
Also I tried DataTypeConverter and get next result:
UaDataType dType = dtc.getDataTypeForJavaClass(UnsignedInteger.class);
System.out.println(dType.toString());
dType = dtc.getDataTypeForJavaClass(UnsignedLong.class);
System.out.println(dType.toString());
dType = dtc.getDataTypeForJavaClass(UnsignedShort.class);
System.out.println(dType.toString());
dType = dtc.getDataTypeForJavaClass(UnsignedByte.class);
System.out.println(dType.toString());
These lines print:
NodeId=i=28, NodeClass=DataType, BrowseName=UInteger, IsAbstract=false
NodeId=i=9, NodeClass=DataType, BrowseName=UInt64, IsAbstract=false
NodeId=i=5, NodeClass=DataType, BrowseName=UInt16, IsAbstract=false
NodeId=i=3, NodeClass=DataType, BrowseName=Byte, IsAbstract=false
Why only for UnsignedInteger is converted to super type? It should be UInt32.
Best regards,
Goran
12:07, EEST
April 3, 2012
The mapping between java and ua types are not 1:1, it is possible that multiple ua types are mapped to one java class, e.g. Double is mapped to both Double and Duration.
Hmm, not sure yet why this happens, but if you do
System.out.println(MultiDimensionArrayUtils.toString(dType2));
you get [NodeId=i=28, NodeClass=DataType, BrowseName=UInteger, IsAbstract=false, NodeId=i=7, NodeClass=DataType, BrowseName=UInt32, IsAbstract=false]
So the UInt32 mapping is there, but somehow there is also the mapping to UInteger too (the getDataTypeForJavaClass returns the first mapping, as indicated in the javadoc)
I will investigate more..
12:41, EEST
January 30, 2014
Thanks for fast answer.
Yes, this method which returns array of UaDataType for other Unsigned types will return only one value.
Also UInteger type is not in the table: OPC UA Part 4: Table 118 – Conversion Rules
Do you have a clue why for Variable which DataType is UInteger it is possible to write only UInt16 and it is not possible to write for example UInt32?
As both, UInt16 and UInt32 are subtypes of UInteger.
This is kind a tricky. How client side could choose appropriate type for write?
The only way that I found is to read the variable and than read from value “real” type.
uaVariable.getValue().getValue().getCompositeClass()
My main problem is that I need to store info about variable (type also) for later use. If I know that that variable will always be UInt16 than it is not problem.
Maybe this is stupid question but In which moment it is defined, for some node of DataType = UInteger, that value will be of type UInt16?
Best regards,
Goran
12:55, EEST
April 3, 2012
Seems we do initialize Identifiers.UInteger with UnsignedInteger.class and Identifiers.Integer with Integer.class in NodeCache, so that explains why there is 2 mappings. I need to check that with Jouni.
If I remember correctly, nodes with abstract DataType can have (and effectively must have) any subtypes of that as value. As to why the write fails, I would guess the server implementation checks that the datatype to be written is of the same type the node currently has and therefore fails.
Duration is subtype of Double, specification Part 3, 8.13 Duration states “This Simple DataType is a Double that defines…”, therefore servers having Int32 there are wrong.
You should be always able to write values of class returned by uaVariable.getValue().getValue().getCompositeClass().
– Bjarne
Most Users Ever Online: 1919
Currently Online:
25 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: 729
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1529
Posts: 6471
Newest Members:
PromotionToold, HypromeImpupe, toneylapham544, rondawolinski7, Marypof5711, roycedelargie91, kourtneyquisenbe, ellis87832073466, zkxwilliemae, gabriellabachusModerators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0
Administrators: admin: 1