

12:43, EEST

November 24, 2020

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?
14:08, EEST

April 3, 2012

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).
14:46, EEST

November 24, 2020

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?
14:58, EEST

April 3, 2012

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.
17:12, EEST

November 24, 2020

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);
}
17:36, EEST

April 3, 2012

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.
Most Users Ever Online: 518
Currently Online:
9 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
hbrackel: 124
pramanj: 86
ibrahim: 74
rocket science: 71
kapsl: 57
Francesco Zambon: 54
Sabari: 51
gjevremovic: 49
Xavier: 43
fred: 41
Member Stats:
Guest Posters: 0
Members: 719
Moderators: 15
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1379
Posts: 5889
Newest Members:
Tayloromj, alexcarmack2708, HomeRenoToold, luismartin, maryloucline6, ezequieludz, roseclaborn, muoifairfield04, hilda50861, ramona90f00573Moderators: Jouni Aro: 970, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 910, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 25, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 271, Lusetti: 0
Administrators: admin: 1