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
DataType Conversion from Java to OPC UA
March 16, 2016
14:44, EET
Avatar
Ibrahim
Member
Members
Forum Posts: 78
Member Since:
August 20, 2014
sp_UserOfflineSmall Offline

Hi,
we want to write Data from a Ua Client (Java SDK) to any Node of a Ua Server. What is the best way to handle the dataTypes from Java to OPCUA? I read about the DataTypeConverter and have tried it out. I Tried the method: getDataTypeForJavaClass(). This worked for primitive types like int, double, float etc. But it’s not working for arrays. How should i handle a java array, which i want to write to an array variable in the UaServer?

Thanks

Best Regards
Ibrahim

March 16, 2016
15:57, EET
Avatar
Heikki Tahvanainen
Member
Members
Forum Posts: 402
Member Since:
April 17, 2013
sp_UserOfflineSmall Offline

Hello,

How about finding out the data type of components in the array and then using the DataTypeConverter? See this link for details: http://download.oracle.com/jav…..Type%28%29

March 16, 2016
16:45, EET
Avatar
Heikki Tahvanainen
Member
Members
Forum Posts: 402
Member Since:
April 17, 2013
sp_UserOfflineSmall Offline

Actually, the getDataTypeForJavaClass() method should work also with array types. Can you provide some code example of data type conversion not working?

Also, the convert-methods in DataTypeConverter might be what you are looking for.

March 16, 2016
17:57, EET
Avatar
Ibrahim
Member
Members
Forum Posts: 78
Member Since:
August 20, 2014
sp_UserOfflineSmall Offline

Hi,
this is a sample from our code, which does not work:

double[] dArray = new double[2];
dArray[0] = 3.6;
dArray[1] = 5.7;
DataTypeConverter converter = client.getAddressSpace().getDataTypeConverter();

UaDataType dataTypeValue = converter.getDataTypeForJavaClass(dArray.getClass());

The method getDataTypeForJavaClass() throws: java.lang.IllegalArgumentException: Cannot find data type of double

March 17, 2016
10:42, EET
Avatar
Heikki Tahvanainen
Member
Members
Forum Posts: 402
Member Since:
April 17, 2013
sp_UserOfflineSmall Offline

Hi,

In this case, the issue isn’t related to arrays. Instead, the problem is that primitive type double is used. Primitive types do not work, because they aren’t Objects.

Try changing the array to Double[], the code should be fine otherwise.

March 17, 2016
12:24, EET
Avatar
Ibrahim
Member
Members
Forum Posts: 78
Member Since:
August 20, 2014
sp_UserOfflineSmall Offline

Hi,
thanks.
Does it mean, that i cannot write primitive Java arrays to a UA Server Node?

March 17, 2016
13:04, EET
Avatar
Heikki Tahvanainen
Member
Members
Forum Posts: 402
Member Since:
April 17, 2013
sp_UserOfflineSmall Offline

Yes. Primitive types cannot be used, just use the wrapper classes.

March 17, 2016
15:32, EET
Avatar
Ibrahim
Member
Members
Forum Posts: 78
Member Since:
August 20, 2014
sp_UserOfflineSmall Offline

Hi,
i found a way to make it work with primitive types:

double[] dArray = new double[2];
dArray[0] = 3.6;
dArray[1] = 5.7;
Double[] d = ArrayUtils.toObject(dArray);
client.writeValue(nodeId, d);

This works fine. I don’t know how performant this is, but it works and it is just for very few cases.
Thanks anyway.. Laugh

Ibrahim

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
12 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Heikki Tahvanainen: 402

hbrackel: 144

rocket science: 88

pramanj: 86

Francesco Zambon: 83

Ibrahim: 78

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

Member Stats:

Guest Posters: 0

Members: 730

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1529

Posts: 6471

Newest Members:

PromotionToold, HypromeImpupe, toneylapham544, rondawolinski7, Marypof5711, roycedelargie91, kourtneyquisenbe, ellis87832073466, zkxwilliemae, gabriellabachus

Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0

Administrators: admin: 1