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
UaType "issue"
April 15, 2016
10:53, EEST
Avatar
gjevremovic
Member
Members
Forum Posts: 49
Member Since:
January 30, 2014
sp_UserOfflineSmall Offline

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:

DataTypeConverter dtc = client.getAddressSpace().getDataTypeConverter();
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

April 15, 2016
12:07, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

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

UaDataType[] dType2 = dtc.getDataTypesForJavaClass(UnsignedInteger.class);
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..

April 15, 2016
12:41, EEST
Avatar
gjevremovic
Member
Members
Forum Posts: 49
Member Since:
January 30, 2014
sp_UserOfflineSmall Offline

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

April 15, 2016
12:55, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

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

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
16 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 77

Ibrahim: 76

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

fred: 41

Member Stats:

Guest Posters: 0

Members: 683

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6261

Newest Members:

digitechroshni, LouieWreve, Kickbiche, karrimacvitie5, graciela2073, sagarchau, elviralangwell4, Donnavek, Eddiefauth, DonaldPooma

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