

8:00, EEST

July 2, 2020

Hi all, I just execute the sampleclient to read some values. The method readValue can retrieve correct value from simulator,but when I change it to readValues it seems doesn’t work. I got status_code “Bad_NodeIdUnknown” in response.
I wonde Is there a known issue or something wrong with my code ? Thanks in advance.
sdk version : Prosys OPC UA SDK for Java v4.3.0-1075
code :
public static void main(String[] args) throws Exception {
UaClient client = new UaClient(“opc.tcp://192.168.0.109:53530/OPCUA/SimulationServer”);
client.setSecurityMode(SecurityMode.NONE);
initialize(client);
client.connect();
DataValue value = client.readValue(Identifiers.Server_ServerStatus_State);
setVarsNode(client);
System.out.println(metrics.size());
DataValue v2 = client.readValue(metrics.get(0));
// v2 returned correct value. DataValue(value=1.0453014, statusCode=GOOD (0x00000000) “”, sourceTimestamp=07/02/20 04:09:01.0000000 GMT, sourcePicoseconds=0, serverTimestamp=07/02/20 04:09:01.9120000 GMT, serverPicoseconds=0)
System.out.println(v2);
// values and values2 both return “Bad_NodeIdUnknown”
DataValue[] values = client.readValues(new ExpandedNodeId[metrics.size()], null, TimestampsToReturn.Both, 0d);
for (DataValue data : values) {
System.out.println(data.getValue());
}
DataValue[] values2 = client.readValues(new NodeId[metrics2.size()], null, TimestampsToReturn.Both, 0d);
for (DataValue data : values2) {
System.out.println(data.getValue());
}
client.disconnect();
}
// metrics structure
public static List metrics = new ArrayList();
public static List metrics2 = new ArrayList();
//—————-
I found the problem, nothing to do with sdk. It’s a code issue.
11:43, EEST

Moderators
February 11, 2020

Hello,
Based on this code, it seems that you’re using empty arrays of ExpandedNodeId and NodeId in client.readValues calls for values and values2. After creating an array you must add entries to it with metrics.toArray(metricsArray), where metricsArray is
ExapndedNodeId[] metricsArray = new ExpandedNodeId[(metrics.size()]
1 Guest(s)
