

10:23, EET

January 30, 2014

Hi,
I would like to avoid calling the read methods for individual items like:
DataValue shorttext = client.readAttribute(nodeId, Attributes.DisplayName);
DataValue longtext = client.readAttribute(nodeId, Attributes.Description);
DataValue value = client.readAttribute(nodeId, Attributes.Value);
e.g. I would like for one node to read set of specified attributes.
I read from prosys javadoc next sample usage examples:
Sample usage:
ReadValueId[] nodesToRead = new ReadValueId[2];
// Scalar value or complete array
nodesToRead[0] = new ReadValueId(nodeId1, Attributes.Value, null, null);
// Part of an array
NumericRange range = new NumericRange(1, 3);
nodesToRead[10] = new ReadValueId(nodeId2, Attributes.Value, range.toString(), null);
final ReadResponse readResponse = read(UaClient.MAX_CACHE_AGE, TimestampsToReturn.Both, nodesToRead);
final DataValue[] values = readResponse.getResults();
// Use the values:
if (values[0].getStatusCode().isGood()) System.out.println(values[0].getValue());
if (values[1].getStatusCode().isGood()) System.out.println(values[1].getValue());
but I stuck with opc foundation docs. Could you please provide simple example to read set of attribs of one node. Tnks
11:13, EET

December 21, 2011

Simple answer:
Internally, this translates to
for (int i = 0; i < attributeIds.length; i++)
nodesToRead[i] = new ReadValueId(nodeId, attributeIds[i], null,
null);
final ReadResponse readResponse = read(MAX_CACHE_AGE,
TimestampsToReturn.Both, nodesToRead);
final DataValue[] values = readResponse.getResults();
12:01, EET

January 30, 2014

12:33, EET

December 21, 2011

9:23, EET

December 21, 2011

11:29, EET

January 30, 2014

Hi,
(1) Regards reading performance is
the same as:
e.g. it is one call to server in both cases, right?
(2) Regards data type
System.out.println(dataValue.getValue());
prints
i=7
Is it possible by using prosys api (or opc fond classes) to transform data type value returned in the form
i=7 directly in java.lang.Class, like Float.class, Double.class, String.class, Integer.class … ?
BR
12:18, EET

December 21, 2011

(1) Not quite. AddressSpace.getNode() makes a couple of readAttributes: first to determine the node class and then read UaNode.supportedAttributes(). After that it will also read node references and properties – to make the node more complete for use in the application.
Regarding performance, getNode() will put the node into a local cache, but will reread the node, if it’s “too old” anyway. The AddressSpace.getCache().setNodeMaxAgeInMillis() can be used to define what is “too old”.
The nodes are store in the cache with WeakReferences, and will be removed when necessary.
(2)
You can convert Variant values with
but it does not expose the Java class corresponding to the type. It does provide the opposite, though:
Instead, you can get it directly from
dt.getJavaClass();
Note that these are “manually” initialised in the SDK and may be null for some types. But in general they are available both on the client and server side.
12:44, EET

December 21, 2011

20:21, EET

January 30, 2014

Thanks Aro for directions, helps me related to UaDataType.
UaVariable v = (UaVariable) uaNode;
dataType = (UaDataType) v.getDataType();
System.out.println("JavaClass: " + dataType.getJavaClass());
I still didn’t find more elegant way with client.read() method except to parse returned value of attribute Attributes.DataType which is not big deal.
DataValue[] arrayOfValues = client.readAttributes(node_id, attribs);
String dataTypeString = arrayOfValues[2].getValue().toString();
int dataTypeIdentifier = Integer.parseInt(dataTypeString.substring(dataTypeString.indexOf("=") + 1));
UaDataType dt = (UaDataType) client.getAddressSpace().getType(new NodeId(0, dataTypeIdentifier));
System.out.println(dt.getJavaClass());
or instead of client.getAddressSpace() maybe it is faster to use:
So, regards performances what you prefer
UaVariable v = (UaVariable) uaNode;
dataType = (UaDataType) v.getDataType();
…
UnsignedInteger[] attribs = v.getSupportedAttributes();
…
or simplier:
?
BR
8:33, EET

December 21, 2011

You can get the DataTypeId “simply” as:
DataValue[] arrayOfValues = client.readAttributes(node_id, attribs);
NodeId dataTypeId = (NodeId) arrayOfValues[2].getValue().getValue();
I wouldn’t consider performance too much at an early stage. Although it is making several calls to the server, unless you need to read a lot of nodes, it won’t matter very much, I think. A call to a local server will take just a couple of ms (depending on the server, of course).
9:35, EET

January 30, 2014

Most Users Ever Online: 1919
Currently Online:
28 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 90
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 765
Moderators: 8
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1543
Posts: 6510
Newest Members:
jodiexae492966, fayetozer72, anglea06o05589, matsa, Jameshax, Jeffreyfledy, lilliefalconer, Olpsom, shastaappleton, hildred39iModerators: Jouni Aro: 1029, Pyry: 1, Petri: 0, Bjarne Boström: 1042, Jimmy Ni: 26, Matti Siponen: 353, Lusetti: 0, Elias: 0
Administrators: admin: 1