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
How to determine if a data type is an array
June 20, 2022
18:05, EEST
Avatar
rocket science
Member
Members
Forum Posts: 77
Member Since:
March 16, 2017
sp_UserOfflineSmall Offline

Hi,

I wonder how to determine exactly that a data type is an array.

According to the reference (https://reference.opcfoundation.org/v104/Core/docs/Part3/5.6.2/) the value rank can be used to determine if the data type is an array or a scalar type.

For valueRank == -1 it is a scalar data type, for valueRank == 1 it is a one dimensional array and for valueRank > 1 it is an array with the specified number of dimensions-

But for others like 0, -2, -3 the reference points out that it can be scalar, one dimensional or any number of dimensions.

So if I have a node on the server, where the DataType is String and the ValueRank is -2, how can I find out if it will be a scalar data type or an array with how many dimensions?

Thanks!

June 21, 2022
10:39, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

We have some helpers in the Variant class:

Variant.getDimension() (delegates to MultiDimensionArrayUtils.getDimension(class), returns 0 if scalar)
Variant.getArrayDimensions() (delegates to MultiDimensionArrayUtils.getArrayLengths(value), return dimensions in array with length of dimensions or 0 if scalar)

It should be noted that apparently these wont work for null value (results NPE; could probably be improved in a future version), thus please check that first.

This is to say, you only know after you have Read it. As for Writing, it shouldn’t need to be the same dimension, if ValueRank allows (what will actually happen would be server-specific though, but spec-wise any of them should like work).

P.S.
Also I would guess most of the time it will be a scalar, since -2 is the default (it has to be) in the basic VariableTypes, thus an instantiation of those would result in -2 unless changed after that.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
24 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: 681

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6261

Newest Members:

graciela2073, sagarchau, elviralangwell4, Donnavek, Eddiefauth, DonaldPooma, fidelduke938316, Jan-Pfizer, DavidROunc, fen.pang@woodside.com

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