Topic RSS13:04, EEST
July 22, 2014
OfflineI am trying to use the client writeAttribute() function to write a value to my (Kepware) OPC UA server.
However, I am constantly getting the error:
com.prosysopc.ua.StatusException: Bad_TypeMismatch(0x80740000) “The value supplied for the attribute is not of the same type as the attribute’s value.”
StatusCode=Bad_TypeMismatch(0x80740000) “The value supplied for the attribute is not of the same type as the attribute’s value.”
From the erroor message, I am assuming that the problem is that the value I am trying to write does not match the server node’s attribute data type.
When the value of the attribute is read, it is a Variant. However, the writeAttribute() function seems to expect an Object.
The node attribute that I am trying to write to on the (Kepware) OPC UA server is listed, on the server, as “Word”. Reading the DatatType using the SDK yields “i=5”. I tried casting my new value to Long and int but neither case was successful (i.e. both cases yielded the above error).
What is the proper process for converting a value to the corresponding attribute data type so that it can be written to the node’s attribute? 
16:24, EEST
July 22, 2014
OfflineI found the section in the SimpleConsoleClient. Thanks.
For anyone who was running into the same problem, here is the code:
UaDataType dataType = null;
UaVariable uaVar = (UaVaraiable) uaNode;
if(uaVar.getDataType()==null){uaVar.setDataType(client.getAddressSpace().getType(uaVar.getDataType()));}
dataType = (uaDataType) uaVar.getDataType();
Object convertedValue = dataType != null ? client.getAddressSpace().getDataTypeConverter().parseVariant(newValue,dataType) : newValue;

1 Guest(s)

Log In
Register