Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Having a problem using the writeValues() method, need some help ;)
July 8, 2019
19:17, EEST
Avatar
joe.aleman
Member
Members
Forum Posts: 5
Member Since:
July 8, 2019
sp_UserOfflineSmall Offline

Hello,

New to the SDK I’m trying to update a group of opc tags using the writeValues() method. I’m receiving the mismatch error status code when I do the write:

Bad_TypeMismatch (0x80740000) “The value supplied for the attribute is not of the same type as the attribute’s value.”

Here is the method I’m using to the write;

private void writeValues(Map opcMap) {
try {
int i = 0;
NodeId[] arrNodes = new NodeId[opcMap.keySet().size()];
Variant[] values = new Variant[opcMap.values().size()];

for (Map.Entry entry : opcMap.entrySet()) {
arrNodes[i] = entry.getKey();
values[i] = entry.getValue().getTagValue().getValue();
i++;
}

StatusCode[] ret = client.writeValues(arrNodes, values);
for (StatusCode code : ret) {
log(“StatusCode = ” + code);
}

} catch (ServiceException e) {
printException(e);
} catch (StatusException e) {
printException(e);
}
}

OpcTag is a simple wrapper class that holds some information along with the DataValue object for the nodeId that I scrap when I first start the application.

When I update the value of the OpcTag.DataValue in my application I just create a Variant and pass a String into the object (i.e. object name is VarString). I then use the OpcTag.DataValue.setValue(VarString) to actually update the value in the map.

July 9, 2019
10:12, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 380
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

Basically that error is returned by the server when the data supplied to the Write service call was of wrong type. The value passed to Variant must match the DataType of the node in question.

July 9, 2019
16:55, EEST
Avatar
joe.aleman
Member
Members
Forum Posts: 5
Member Since:
July 8, 2019
sp_UserOfflineSmall Offline

Thank you for the reply.
Do you know is there an Enum that I can use for the builtin datatypes for OPC?

July 9, 2019
17:27, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 380
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

No. Generally the DataType (at least should be) stored and used as the NodeId which is the value of the DataType Attribute of the node (and when storing NodeIds it would be a good idea to store the namespace as uri and not the index).

Due to changes in 4.0.2 (https://downloads.prosysopc.com/opcua/Prosys_OPC_UA_SDK_for_Java_4_Release_Notes.html#version-4-0-2) the DataType NodeIds for the standard model can be found in DataTypeIdentifiers constants (previously they were just in the Identifiers which contains all well known NodeIds for the standard model), however note that these are only for the standard model. Other models define additional types and server can just have their full custom types. Note however that usually they are just custom Structure types i.e. combinations of other types.

However for simple cases you could just use the Java Class objects instead for type mapping. Depending on your application it might be just enough to Read the nodes once when your application starts and then just make sure to Write objects of the same Java class that you read.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 78

Currently Online:
14 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 89

pramanj: 86

ibrahim: 68

kapsl: 57

gjevremovic: 49

TimK: 41

Fransua33: 39

fred: 36

Rainer Versteeg: 32

peterrob45: 25

Member Stats:

Guest Posters: 0

Members: 847

Moderators: 11

Admins: 1

Forum Stats:

Groups: 3

Forums: 14

Topics: 868

Posts: 3664

Newest Members:

opcEasyAsAbc, Ns, kanewatson, aj, joe.aleman, dhirajsakariya, alexie347, pramodopc, augusthanks, uiuida

Moderators: Jouni Aro: 824, Otso Palonen: 32, Tuomas Hiltunen: 5, janimakela: 0, Pyry: 1, Terho: 0, Petri: 0, Bjarne Boström: 380, Heikki Tahvanainen: 402, Jukka Asikainen: 1, Teppo Uimonen: 15

Administrators: admin: 0