OPC UA ValueRank and ArrayDimensions Decoding|OPC UA Standard|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
OPC UA ValueRank and ArrayDimensions Decoding
Avatar
Jothi Sankarraj
Member
Members
Forum Posts: 29
Member Since:
04/09/2019
sp_UserOfflineSmall Offline
1
08/09/2019 - 01:10
sp_Permalink sp_Print

I have a few questions around reading and parsing the ValueRank and ArrayDimensions. So referring to Part 3, version 1.04 of the Spec., on page number 27, Table 13, I see the following:

ValueRank:

This Attribute indicates whether the Value Attribute of the Variable is an array and how many dimensions the array has. It may have the following values:
n > 1: the Value is an array with the specified number of dimensions.
OneDimension (1): The value is an array with one dimension. OneOrMoreDimensions (0): The value is an array with one or more dimensions.
Scalar (−1): The value is not an array.
Any (−2): The value can be a scalar or an array with any number of dimensions.
ScalarOrOneDimension (−3): The value can be a scalar or a one dimensional array.
All DataTypes are considered to be scalar, even if they have array-like semantics like ByteString and String.

ArrayDimensions:

This Attribute specifies the maximum supported length of each dimension. If the maximum is unknown the value shall be 0. The number of elements shall be equal to the value of the ValueRank Attribute. This Attribute shall be null if ValueRank ≤ 0.

For example, if a Variable is defined by the following C array: Int32 myArray[346];

then this Variable’s DataType would point to an Int32 and the Variable’s ValueRank has the value 1 and the ArrayDimensions is an array with one entry having the value 346.

The maximum number of elements of an array transferred on the wire is 2147483647 (max Int32).

I have the following sample data. For simplicity, I have discarded some data and the sample given below starts from ValueRank:

255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 5, 0, 0, 0, 95, 116

So the first 4 bytes which is 255, 255, 255, 255 would be the ValueRank which then evaluates to -1. The spec also says that if the ValueRank is <= 0 which in my case is, the ArrayDimensions shall be null. I'm not sure what this means, but looking at my example., I have another 4 bytes of 255, 255, 255, 255 which would also evaluate to -1. So does this mean that the ArrayDimensions is -1? Should I understand it like this?

Please help!

Avatar
Randy Armstrong
Admin
Forum Posts: 1451
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
08/09/2019 - 14:42
sp_Permalink sp_Print

Where is this data from?

If this is UABinary encoding of a structure with an array then -1 means an array with no elements and the second -1 would be a second array  (or string) with no elements.

Avatar
Jothi Sankarraj
Member
Members
Forum Posts: 29
Member Since:
04/09/2019
sp_UserOfflineSmall Offline
3
08/09/2019 - 21:49
sp_Permalink sp_Print

The data is from an actual device! This is the OPC UA Pub Sub binary structure!

So the ValueRank in my case is -1 and you say the next set of elements with 255 255 255 255 could be a String? But what String is this? I thought I have to go sequentially as per the Specification when parsing the binary data. So the next element to be parsed as per Spec is the ArrayDimensions. So how do you say that this could be a second array? Where in the Spec is this said?

Avatar
Randy Armstrong
Admin
Forum Posts: 1451
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
4
08/12/2019 - 14:58
sp_Permalink sp_Print

The ValueRank does not appear as a literal value on the wire. It tells you what is put on the wire.

If the ValueRank >= 0 the wire encoding is a Int32 value with the Length followed by that number of elements.
In this case, -1 for the length means the array has no elements.

If the ValueRank == -1 then there is no Int32 length.

Avatar
Jothi Sankarraj
Member
Members
Forum Posts: 29
Member Since:
04/09/2019
sp_UserOfflineSmall Offline
5
08/12/2019 - 21:23
sp_Permalink sp_Print

@Randy: Thanks for the reply, but I still could not fully understand! Can you please give me a simple example?

Avatar
Randy Armstrong
Admin
Forum Posts: 1451
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
6
08/13/2019 - 07:13
sp_Permalink sp_Print

You can create as many examples as you need by building a console app with the BinaryEncoder which is part of the .NET standard stack.

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 19
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1349
Posts: 4579