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 decode byte array of ExtensionObject
October 11, 2021
1:32, EEST
Avatar
dipankar.dey@softwareag.com
Member
Members
Forum Posts: 4
Member Since:
December 6, 2018
sp_UserOfflineSmall Offline

Hi Team,

We had developed our application using prosys-opc-ua-java-sdk-client-3.2.0-690 back in 2018.
When we are trying to “Read” the value attribute of a Structure type data, it is returning as ExtentionObject having the data as follows :

ExtensionObject :
object >> byte array
encodeType >> Binary
typeId >> some node id

Now our concern is, how do we decode this byte array we received as part of the extension object? We have noticed that in a newer version of the prosys java stack it returns the data in the expected format (not byte array) . For us, it is very difficult to upgrade the prosys stack at this moment. Could you please tell us how can we resolve this issue ? We want to read(decode) the value attribute of Structure type data in a human-readable format.

Thanks,
Dipankar

October 11, 2021
11:43, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 684
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

This is one of the most complicated things in OPC UA.

In short, you can try

uaClient.getTypeDictionary().decode(ExtensionObject)

but note that it might no longer work with all servers, as OPC UA 1.04 defined a new way for the Structure’s metadata with the new DataTypeDefinition Attribute. Also it added e.g. support for multidimensional array field encoding, which cannot be represented with the old DataTypeDictionary concept (which in SDK 3.x the TypeDictionary is using; in 4.x it will abstract to using DataTypeDefinition first and then DataTypeDictionaries as a backup).

If the TypeDictionary.decode worked, it will output a DynamicStructure that you can use to get the information, modify the data, and TypeDictionary.encode(…) it back to ExtensionObject.

October 11, 2021
13:11, EEST
Avatar
dipankar.dey@softwareag.com
Member
Members
Forum Posts: 4
Member Since:
December 6, 2018
sp_UserOfflineSmall Offline

Hi Bjarne Boström,

Thanks for your response.

I have tried the code you mentioned but it is giving the following error, Frown

Bad_DecodingError (0x80070000) “Decoding halted because of invalid data in the stream.”

Could you please guide me if there’s any other way(other than upgrading prosys java stack) to resolve this?
Could you also tell us if prosys-opc-ua-java-sdk-client-3.2.0-690 honors/follows OPC spec 1.04 or OPC spec 1.03?

Thanks,
Dipankar

October 11, 2021
14:40, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 684
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Was there an explanation in any nested exception in the full stacktrace?

Do you have an information model (as a NodeSet2 XML file) that would contain the structure type in question?
Or do you in general know what Structure it is?
Can you check the address space with e.g. our Browser tool or with UaExpert?
Does the server have a node in Root/Types/DataTypes/OPC Binary/ that has the same namespace in the NodeId as the typeId of the ExtensionObject?
Can you paste the TypeId here?

It can be a bit hard to locate what node it is, since the encoding id is not the datatype nodeId, but the node below it (but it is also nonhierarchical so not typically visible in tree views, though our Browse has a toggle to show them as well). But if you check them all manually so that you know whose DataType ‘Default Binary’ node that is you would then know the DataType (or do an inverse Browse with the SDK from the encoding node). Then you could check does it have a DataTypeDefinition Attribute. Or in general, does any Structure type in the server have that? Note that you must be running our Browser or a somewhat recent version of UaExpert to see that 1.04 specific Attribute in the first place.

Technically IF you have the type in a NodeSet2 XML you could also codegenerate that type with the Codegen of the SDK, but that would not work in a generic case (since it is an offline tool). Also would not help if it e.g. had multidimensional array field since that would require 1.04 knowledge for decoding.

But in general, IF you have an option to try with 4.x and if that would work, then pretty much upgrading to 4.x is the solution.

P.S.
Very unlikely, but it could also be the 1.04 new DataType ‘Decimal’, which is not a Structure, but only encoded as such. Then the encoding typeId would be exactly i=50 in the standard base namespace (so index 0 or uri http://opcfoundation.org/UA/).

October 11, 2021
20:37, EEST
Avatar
dipankar.dey@softwareag.com
Member
Members
Forum Posts: 4
Member Since:
December 6, 2018
sp_UserOfflineSmall Offline

Hi Bjarne Boström,

Thanks for the detailed explanation.

In this scenario, we are using our in-house developed opc client which uses prosys-opc-ua-java-sdk-client-3.2.0-690, and testing it against the sample server that came with (prosys-opc-ua-sdk-for-java-4.6.0-1594 package). We are trying to read the custom structure “MyStructure” which is also from
the sample server code.

Our customer has a requirement of reading the “value” attribute of a custom structure node which our in-house client which uses prosys-opc-ua-java-sdk-client-3.2.0-690 not able to read properly and giving a byte array as mentioned.

ExtensionObject details :
______________________________________________________________________________________________________
object = {byte[12]@26555} >>
{
0 = 57
1 = 5
2 = 0
3 = 0
4 = 4
5 = 0
6 = 0
7 = 0
8 = 84
9 = 101
10 = 115
11 = 116
}
typeId = {ExpandedNodeId@26556} “nsu=http%3A%2F%2Fwww.prosysopc.com%2FOPCUA%2FSampleAddressSpace;i=12345”
encodeType = {EncodeType@26557} “Binary”
________________________________________________________________________________________________________

Error stack trace doesn’t contain any traces from the prosys java stack but the following is the detailed error :
________________________________________________________________________________________________________________________________________
result = {DecodingException@26419} Method threw ‘org.opcfoundation.ua.encoding.DecodingException’ exception.
statusCode = {StatusCode@26421} “Bad_DecodingError (0x80070000) “Decoding halted because of invalid data in the stream.””
text = “Unknown encoding: http://www.prosysopc.com/OPCUA/SampleAddressSpace:12345
detailMessage = null

cause = {DecodingException@26419} “org.opcfoundation.ua.encoding.DecodingException: Bad_DecodingError (code=0x80070000, description=”Unknown encoding: http://www.prosysopc.com/OPCUA/SampleAddressSpace:12345“)”
statusCode = {StatusCode@26421} “Bad_DecodingError (0x80070000) “Decoding halted because of invalid data in the stream.””
text = “Unknown encoding: http://www.prosysopc.com/OPCUA/SampleAddressSpace:12345
detailMessage = null
cause = {DecodingException@26419} “org.opcfoundation.ua.encoding.DecodingException: Bad_DecodingError (code=0x80070000, description=”Unknown encoding: http://www.prosysopc.com/OPCUA/SampleAddressSpace:12345“)”

stackTrace = {StackTraceElement[22]@26423}
suppressedExceptions = {Collections$UnmodifiableRandomAccessList@23007} size = 0
________________________________________________________________________________________________________________________________________

Could you please tell us if there’s a way to read the custom structure node in this scenario without upgrading the prosys libs?

Thanks,
Dipankar

October 12, 2021
13:47, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 684
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

OH! Well, that makes an answer much easier.

That part of the sample only works with 1.04 clients, as mentioned in the comments:

private void createCustomStructure() throws StatusException {
// This creates a simple custom Structure type and an instance using it.
// NOTE! This wont create DataTypeDictionaries, thus only 1.04 clients capable of using 1.04
// introduced Attribute DataTypeDefinition can handle this.

And that is because it only makes the DataTypeDefinition (the new 1.04 Attribute; StructureSpecifications are converted to it internally) and not the old DataTypeDictionaries.

Similarly, you might encounter a 1.04 Server in the real world that does the same. In that case the only option is to start to use SDK 4.x.

While technically it would be possible to edit the sample with some non-trivial amount of work to add the dictionary nodes, it would not help for a generic client. The only situation where it would help is if you would all the servers you are connecting to. Plus you could not use e.g. multidimensional array fields in Structures, since that 1.04 concept cannot be represented by any rule in the old dictionary system.

October 13, 2021
8:33, EEST
Avatar
dipankar.dey@softwareag.com
Member
Members
Forum Posts: 4
Member Since:
December 6, 2018
sp_UserOfflineSmall Offline

Hi Bjarne Boström,

Thanks for your response.

We came to know that prosys latest libraries doesn’t rely on opc-ua-stack anymore. Since we developed our application using prosys-opc-ua-java-sdk-client-3.2.0-690,
we need to make changes in our code as well since the new changes in the prosys libraries are not backward compatible. We have gone through the migration guide as well.
But for the time being is there a prosys-opc-ua-java-sdk-client version which supports Structure type data decoding as well as backward compatible (i.e uses opc-ua-stack like the older versions) ?

Thanks,
Dipankar

October 13, 2021
16:02, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 684
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

In short: there is no version of 4.x (nor there ever be a version of the SDK) that would use “the stack” anymore, since it basically doesn’t anymore exist.
Note on https://github.com/OPCFoundation/UA-Java-Legacy (and note that the repo name is *-Legacy nowadays)
“This repository is provided by OPC Foundation as legacy support for an Java version for OPC UA. It will not receive further features and updates.

The OPC Foundation will continue maintenance of the .NET Stack which is based on .NET Standard. It can be found here.”

In longer:
No, as the stack was effectively discontinued we cannot use it anymore, thus in 4.x there is no longer a concept of a “stack”. As explained in the migration guide: “The OPC UA Stack is now integrated as part of the Prosys OPC UA SDK. It is based on the open source OPC Foundation Java Stack, but based on our agreement with the OPC Foundation we can provide it under the Prosys OPC UA SDK license.” Due to that it is the way it is.

But it should be noted, that there is no longer a separation of the “stack level” and “SDK level” in the code. Things that were previously “in the stack” do nowadays depend on “SDK level” classes. For example, the Structure has the same API mostly as the DynamicStructure and it has the .specification etc. that returns SDK class StructureSpecification. This allows handling of all Structures in a dynamic manner.

That being said, the migration process from 3.x to at least 4.0.0 should be relatively simple with mostly renaming imports. There are a few areas that might require a bit more code, such as e.g. AccessLevel etc. “OptionSetLike” types (in OPC UA 1.04 the OPC Foundation added subtypes for the Attributes that are now proper types thus it required some changes as we didn’t want to have effectively duplicate classes in the SDK). IF there is a problem with it please let us know..

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 267

Currently Online: aneeta.antony@bakerhughes.com
13 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 111

pramanj: 86

ibrahim: 74

kapsl: 57

gjevremovic: 49

TimK: 41

fred: 41

Xavier: 40

Fransua33: 39

rocket science: 36

Member Stats:

Guest Posters: 0

Members: 1458

Moderators: 17

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1178

Posts: 4983

Newest Members:

ThomasM, louiecrews, wyattcutler005, kristin3354, augustawalpole3, everettpulver, arron51869, roseannagoldschm, moosm, islamaddox

Moderators: Jouni Aro: 906, Otso Palonen: 32, Tuomas Hiltunen: 5, janimakela: 0, Pyry: 1, Terho: 0, Petri: 0, Bjarne Boström: 684, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 24, Teppo Uimonen: 21, Markus Johansson: 36, Niklas Nurminen: 0, Matti Siponen: 151, Lusetti: 0

Administrators: admin: 1