

13:04, EEST

July 22, 2014

I 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

I 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;
Most Users Ever Online: 518
Currently Online:
8 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
hbrackel: 130
pramanj: 86
ibrahim: 75
rocket science: 72
Sabari: 62
Francesco Zambon: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
fred: 41
Member Stats:
Guest Posters: 0
Members: 651
Moderators: 16
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1415
Posts: 6035
Newest Members:
u310498, ntd, francescac, yahya95, leomajoe, Gus, sdfsdfsdfsd, riatucckerModerators: Jouni Aro: 988, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 941, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 25, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 288, Lusetti: 0, Ari-Pekka Soikkeli: 5
Administrators: admin: 1