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
writing a Short array to a tag gives DataTypeConversionException
September 7, 2022
12:43, EEST
Avatar
evervondel
Member
Members
Forum Posts: 4
Member Since:
November 24, 2020
sp_UserOfflineSmall Offline

Using java OPCUA client library 4.8.0.25
In kepware server we are reading / writing a ShortArrayTag

reading the tag return a Short array with 4 elements.

Trying to write the same value back with a write always throws the same error
com.prosysopc.ua.DataTypeConversionException: Cannot convert array of length 4 to scalar

client.writeValue(nodeId, pValue, true);
nodeId = nodeId of same tag we were reading
pValue = Short array of 4 elements

should I use some other call to write a java array?? of is the automatic dataconversion wrong?

September 7, 2022
14:08, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 994
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

Thanks for the note.

It wont work for arrays (autoConvert=true, I mean). It can be categorized as a bug, sort of (skipping details for now), and is probably fixed in a future version (i.e. there would have been nothing to convert in this case so it should not fail).

Is there a reason you need the autoConvert=true here? Basically you could just use false there or use the writeValue(NodeId nodeId, Object value).

September 7, 2022
14:46, EEST
Avatar
evervondel
Member
Members
Forum Posts: 4
Member Since:
November 24, 2020
sp_UserOfflineSmall Offline

writing the Short Array Directly throws the following Exception:

com.prosysopc.ua.StatusException: Bad_TypeMismatch (0x80740000) “The value supplied for the attribute is not of the same type as the attribute’s value.” StatusCode=Bad_TypeMismatch (0x80740000) “The value supplied for the attribute is not of the same type as the attribute’s value.”

Is there some piece of example code available on how to wirte an array to a tag?

maybe an extract of how the Prosys OPC Client is handling this?

September 7, 2022
14:58, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 994
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Can you tell what is the ValueRank and DataType Attributes of that node? (And we might need to continue via email if you show them via screenshots etc.)

Basically if it is ValueRank of 1 i.e. 1-dim array, and the DataType is i=4 i.e. “Int16” i.e. in Java Short, the DataValue you read (as you said you read and then write it back) should contain a Variant that contains a Short[] (the boxed type, primitives are not used in the SDK in the value mappings), thus you would then write that same Short[] back and that should work. This is assuming there is not an error in the server that it would return wrong datatype’d Value.

September 7, 2022
17:12, EEST
Avatar
evervondel
Member
Members
Forum Posts: 4
Member Since:
November 24, 2020
sp_UserOfflineSmall Offline

Writing an array without conversion is working now… as no conversion can be done, I have to write the exact array type… so to a Short[] opc tag I can only write a Short array and not an Integer array…

Finally I have changed my code to the following bypass the array conversion issue:

if ((pValue != null) && (pValue.getClass().isArray()))
{
// Write array value as is
serverEntry.client.writeValue(nodeId, pValue);
}
else
{
// Write the value with autoconvert
serverEntry.client.writeValue(nodeId, pValue, true);
}

September 7, 2022
17:36, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 994
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Maybe I was a bit confused since you mentioned “Trying to write the same value back” so I assumed you would have already have the data in the correct type.

Technically you can get the type mapping at runtime via client.getAddressSpace().getDataType(DataTypeId here).getJavaClass() if you must make a new array dynamically. Though note that it is the scalar type (and that you must give it the node’s DataType Attribute’s value, i.e. the NodeId of the DataType, not the node to which you are writing) (basically this is the issue at the moment why the array conversions fail). Though, NOTE, we did release 4.9.0 last week https://downloads.prosysopc.com/opcua/Prosys_OPC_UA_SDK_for_Java_4_Release_Notes.html#version-4-9-0 and that functionality was made better, but requires changes if you looped supertypes before).

And I guess a Integer[] -> Short[] conversion could be useful in the future as using shorts in java code can be a bit clunky.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
20 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Heikki Tahvanainen: 402

hbrackel: 142

pramanj: 86

Francesco Zambon: 83

rocket science: 82

Ibrahim: 76

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

Member Stats:

Guest Posters: 0

Members: 704

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1482

Posts: 6316

Newest Members:

samui, TommyDab, wross, Jeremyknock, Pedromon, DonaldEdism, Miguelplese, Scotanine, katesalas95, Petertum

Moderators: Jouni Aro: 1015, Pyry: 1, Petri: 0, Bjarne Boström: 994, Jimmy Ni: 26, Matti Siponen: 330, Lusetti: 0

Administrators: admin: 1