Read Value from OPCUA Array

Hello i can´t figure out how to read a value from an array.
I have this array

It is a Variant Array with the size of 20 and it has different Datatypes.

I tried reading just one array element

				Sprintf(etest->OPCUA.ReadCalibration.ServerEndpointUrl,"opc.tcp://172.16.0.60:48010");
				Sprintf(etest->OPCUA.ReadCalibration.NodeID.Identifier,"TestResult.MeasurementResult.LastResult");
				etest->OPCUA.ReadCalibration.NodeID.IdentifierType = 1;
				etest->OPCUA.ReadCalibration.NodeID.NamespaceIndex = 2;
				Sprintf(etest->OPCUA.ReadCalibration.Variable,"e_test:Etest[0].OPCUA.Result.sResult");
				etest->OPCUA.ReadCalibration.pNodeAddInfo = &etest->OPCUA.AddInfo;
				etest->OPCUA.AddInfo.AttributeId = UAAI_Value;
				etest->OPCUA.AddInfo.IndexRangeCount = 1;
				etest->OPCUA.AddInfo.IndexRange[0].StartIndex = 0;
				etest->OPCUA.AddInfo.IndexRange[0].EndIndex = 0;				

Doesn´t work.

I also tried reading the whole array with StartIndex=0 EndIndex=19 and Variable Value changed to e_test:Etest[0].OPCUA.Result. e_test:Etest[0].OPCUA.Result is also an array with the same 20 elements like on the OPCUA Server. Variables are also in the same order and datatypes. Also doesn´t work. Reading a value which is not an array works so there is nothing wrong with server configuration etc.

How is the correct way to read either the whole array or just one element?

Hello Markus @Markus_Trapp welcome to the B&R Community

It looks like the array isn’t enabled to show each index separately!
When you enable a variable, structure or array on the server there are different levels of “visibility”. You can either just enable the array as one piece or as individual elements.

Right click the array variable and select Recursive, that should make all elements visible.

It’s also possible that you may need to update your OpcUa InformationModel but for that please let us know what AS version and runtime you are using!

1 Like

Hi.

I have no experience with variant arrays, so this is a wild guess, but have you tried explicitly setting “Show array elements” to TRUE?
This is also needed for arrays of struct types.

1 Like

It runs on a third party machine. I don´t have access to it. Also just writting TestResult.MeasurementResult.LastResult[0] or TestResult.MeasurementResult.LastResult[3] was my first guess but dosen´t work.

We made our own Variant Array on our OPCUA Server and it worked right away. So there is something wrong with the configuration on the 3rd party server. In conclusion if you want to read an element from an array you have to use UANodeAdditionalInfo.

				etest->OPCUA.AddInfo.AttributeId = UAAI_Value;
				etest->OPCUA.AddInfo.IndexRangeCount = 1;
				etest->OPCUA.AddInfo.IndexRange[0].StartIndex = 0;
				etest->OPCUA.AddInfo.IndexRange[0].EndIndex = 0;				

set AttributeId to UAAI_Value. IndexRangeCount is the array dimension not the size. And then use StartIndex and EndIndex for the array index you want to read.

1 Like