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
writeValues autoConvert
January 30, 2020
16:47, EET
Avatar
bvanseveren
Member
Members
Forum Posts: 3
Member Since:
January 30, 2020
sp_UserOfflineSmall Offline

Hi,

Currently I’m using the ‘writeValue’ method in UaClient to write an OPC value. I set autoConvert to true, because then I don’t have to care about the data type of the value.

As I have to write quite a lot of tags, I’m planning to use writeValues, but this method has no ‘autoConvert’ flag. Can htis be added or how should the converison be done?

Kind regards,
Bram

January 31, 2020
9:36, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1026
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

We can consider that for a future version. In the meantime you could try to do it more manually (and let us know if that is convinient enough). Internally the autoConvert will do following:

1. Read the DataType Attribute of the node to be written. This must be done each time, since on that API level we don’t have it otherwise (UaVariableImpl would know; see below). Thus there is a small performance hit due to that.

2. Convert the given value with (UaClient).getAddressSpace().getDataTypeConverter().convert(Variant, NodeId of the datatype). This includes first a check if the initial Object was DataValue, Variant or raw value (DataValue.getValue, Variant as-is, and new Variant(object) for raw values.

3. Delegate to other non-autoConvert methods.

So you should be able to convert them individually first and then use the writeValues(NodeId[], Object[]). However you will need to read the DataTypes of all the nodes once (assuming they do not change, you could cache that). Alternatively you could get the UaNodes via client.getAddressSpace().getNodes(). Cast the UaNodes to UaVariable(Impl). And then you can .getDataTypeId() to get the DataType (or .getDataType, to pass the UaDataType node directly to DataTypeConverter.convert(Variant value, UaDataType dataType)).

P.S.
While the autoConvert option is easy to use (that’s why it was added), I would say the “more proper” and performant way would be to conversion manually like this as 1) no need to Read the DataType all the time (assuming you can cache them) 2) A bit more separation on conversion errors from write error (the method does throw DataTypeConversionException though, however that will be also thrown e.g. if the DataType Attribute cannot be Read.).

P.S.2.
There is also UaVariableImpl.writeValue(Object value, boolean autoConvert), but that too will write only one value at a time (but that doesn’t need to read the DataType all the time). Maybe at some point we can get a write API to use those instead of NodeIds in bulk.

January 31, 2020
16:17, EET
Avatar
bvanseveren
Member
Members
Forum Posts: 3
Member Since:
January 30, 2020
sp_UserOfflineSmall Offline

Ok, this is clear how to solve.

Thanks for the input!

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
18 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: 736

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1524

Posts: 6450

Newest Members:

kristiewinkle8, rust, christamcdowall, redaahern07571, nigelbdhmp, travistimmons, AnnelCib, dalenegettinger, howardkennerley, Thomassnism

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

Administrators: admin: 1