0

I am trying to connect to a remote environment using the OPC UA java stack from the OPC Foundation. Reading values is working correct, for that I am using the following code:

NodeId nodeId= NodeId.get(IdType.String, 2, "TYPES!M!MULTIPLYER!MU_79.MULTIPLYER_BIAS");
ReadResponse res = mySessionChannel.Read(null, 500.0, TimestampsToReturn.Source, new ReadValueId(nodeId, Attributes.Value, null, null));

Now I am trying to use the write command to set this (input) variable as follows:

NodeId nodeId = NodeId.get(IdType.String, 2, "TYPES!M!MULTIPLYER!MU_79.MULTIPLYER_BIAS");
DataValue dataValue = new DataValue(new Variant(999));
WriteValue writeValue[] = new WriteValue[1];
writeValue[0] = new WriteValue(nodeId, Attributes.Value, "0", dataValue);

RequestHeader requestHeader = new RequestHeader(nodeId, null, null, null, null, null, null);
WriteRequest writeRequest = new WriteRequest(requestHeader, writeValue);
WriteResponse response = mySessionChannel.Write(writeRequest);

The write command runs without errors but the value never changes. Can somebody help me out?

Laurent LA RIZZA
  • 2,905
  • 1
  • 23
  • 41
user3083205
  • 1
  • 1
  • 1

1 Answers1

0

You are defining "0" as IndexRange (3rd param of WriteValue). I believe, you have a scalar variable, so you should just use null, instead.

Also you need to check the response to actually see if it succeeds or not.

E: The write parameter must match the DataType of the Variable node.

Jouni Aro
  • 2,099
  • 14
  • 30
  • I changed it to null, the value isnt changing and the response is:WriteResponse (id=1474131049) ResponseHeader=ResponseHeader (id=676105376) ServiceDiagnostics=DiagnosticInfo (id=967078155) localizedText=null locale=null innerDiagnosticInfo=null symbolicId=null innerStatusCode=null additionalInfo=null stringTable=null stringArray=class java.lang.String[0] namespaceUri=null StringTable=class java.lang.String[0] – user3083205 Dec 12 '13 at 14:14
  • RequestHandle=UnsignedInteger (id=1526310589) value=1 Timestamp=DateTime (id=1925333515) value=130393207472672000 AdditionalHeader=null ServiceResult=StatusCode (id=2163771) value=0 DiagnosticInfos=class org.opcfoundation.ua.builtintypes.DiagnosticInfo[0] Results=class org.opcfoundation.ua.builtintypes.StatusCode[1] [0]=StatusCode (id=2006760845) value=-2139881472 – user3083205 Dec 12 '13 at 14:15
  • It's better to print the StatusCodes as string: it will tell you the actual code, e.g. response.getResults()[0] – Jouni Aro Dec 13 '13 at 08:06
  • This indeed makes more sense to me: Bad_TypeMismatch (0x80740000) "The value supplied for the attribute is not of the same type as the attribute's value." Now see how I can fix this. – user3083205 Dec 16 '13 at 09:00
  • You need to find the DataType of the node you are writing to and provide a respective value. UA does not allow the server to convert data types automatically. – Jouni Aro Dec 18 '13 at 15:05