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: 836
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: 836
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: 836
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: 267

Currently Online:
5 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 122

pramanj: 86

ibrahim: 74

rocket science: 65

kapsl: 57

gjevremovic: 49

Sabari: 46

Xavier: 42

fred: 41

TimK: 41

Member Stats:

Guest Posters: 0

Members: 3344

Moderators: 17

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1300

Posts: 5561

Newest Members:

UPtato42, fblvicky6629601, elliebloomer44, Manuelagibe, justinafavenc54, sarlaman9, nancymcneal1, elztaim591797, JeffreyAidet, sameisenhower7

Moderators: Jouni Aro: 946, Otso Palonen: 32, Tuomas Hiltunen: 5, janimakela: 0, Pyry: 1, Terho: 0, Petri: 0, Bjarne Boström: 836, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 25, Teppo Uimonen: 21, Markus Johansson: 41, Niklas Nurminen: 0, Matti Siponen: 221, Lusetti: 0

Administrators: admin: 1