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
Write a null value into a node
January 13, 2021
16:23, EET
Avatar
Thomas Reuther
Member
Members
Forum Posts: 33
Member Since:
September 18, 2017
sp_UserOfflineSmall Offline

Hello Support,

I am using SDK for Java 4.3.0.

I want to write a null value into a node of class “Variable”. The server is built on another toolkit but my client uses Prosys SDK. I tried it this way:

boolean status = client.writeAttribute(nodeId, Attributes.Value, (NodeId)null);

The data type of this node is NodeId. The server responds “Bad_TypeMismatch”. So I add a cast operator “(NodeId)” to that null value to specify a type. But it does not help.

I also tried another tool/kit: CTT. I wrote a user defined script. Here, in JavaScript, the Variant is a structure with properties DataType and ArrayType.

var dataValue = new UaDataValue();
// dataValue.Value is of type UaVariant and empty by default
dataValue.Value.DataType = BuiltInType.NodeId; // set the data type
dataValue.Value.ArrayType = VariantArrayType.Scalar; // and specify the dimension

When I do not set these properties together with a null value I also get a “Bad_TypeMismatch” error from the server. When I provide these properties then the value can successfully be written. When the value is non-null I do not need to set these properties.

How can I achieve this with the Java SDK? All I found is to set only the value bot not the type information.
Can you help?

Best regards
Thomas Reuther

January 13, 2021
17:16, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 581
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

Note that according to what I know, a Good StatusCode’d Value should never be directly “NULL”, if the value is null, the statuscode should always be bad (or maybe uncertain). Though, that being said, I think this still doesn’t exactly read anywhere in the specification. Anyway, if possible, can you explain why you would want to do this?

Anyway, here is some options.

Short answer:
Try NodeId.NULL instead of “java null”, see below for why.

A bit longer answer:
SDK’s Variant having directly null value is “typeless” and matches the “builtin-type 0” in the Part 6 encodings of the specification. Otherwise the java class (of the instance inside the Variant) directly maps to a builtin type, thus it is not needed to be separately settable. NodeId’s binary encodings define a null form (or well, 4 of them), thus that NodeId.NULL (that is same as NULL_NUMERIC) should be used. Not all types have a Null form, such as e.g. Int32; a Structure having an Int32 field (so java.lang.Integer), set to null would be written as 0 instead.

Long answer:
It is a bit complicated..

Spec links for DataValue, Variant, NodeId binary encoding:
– DataValue: https://reference.opcfoundation.org/v104/Core/docs/Part6/5.2.2/#5.2.2.17
– Variant: https://reference.opcfoundation.org/v104/Core/docs/Part6/5.2.2/#5.2.2.16
– NodeId: https://reference.opcfoundation.org/v104/Core/docs/Part6/5.2.2/#5.2.2.9, plus https://reference.opcfoundation.org/v104/Core/docs/Part3/8.2.4/ for NodeId Null Values definitions (for some reason they seem to not be in Part 6, but were already defined in Part 3)

There is multiple possible binary forms you might mean.

1. DataValue’ EncodingMask might directly indicate that the Value is Null (no type info), no Variant at all in the binary stream
2. Variant’s EncodingMask byte is 0, per above links:” A value of 0 specifies a NULL and that no other fields are encoded”. This is what you are getting now. Probably it should be more correct, that case 1. would happen instead, since it basically means the same thing as far as I can see.
3. Variant contains NodeId.NULL (or NULL_NUMERIC), namespace index 0, value part 0.
4. Variant contains NodeId.NULL_STRING, namespace index 0, value “”.
5. Variant contains NodeId.NULL_GUID, namespace index 0, value equal to ‘new UUID(0, 0)’.
6. Variant contains NodeId.Null_OPAQUE, namespace index 0, value as ByteString with length 0.

The server might want one of cases 3-6. Though I would say it would be best for servers to accept all options (though, here, for some reason the OPC Foundation decided to go with 4 different NULL values for the NodeId instead of just defining it as the numeric variant, so for 1+2 the server would have to chose one of the forms maybe).

January 13, 2021
17:28, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 581
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

P.S.

Java null is typeless, casting it wont change that. But if you have an overload of a method with multiple types the casting would chose which overload to call, but here it wont “change” the null type.

See e.g. https://stackoverflow.com/questions/18723596/no-exception-while-type-casting-with-a-null-in-java

January 13, 2021
22:51, EET
Avatar
Thomas Reuther
Member
Members
Forum Posts: 33
Member Since:
September 18, 2017
sp_UserOfflineSmall Offline

Thank you for that overwhelming answer!!! But it looks more complicated that I thought at first.

I need to discuss this with my team mates.

Thank you very much!!! Smile

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 267

Currently Online:
11 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 103

pramanj: 86

ibrahim: 70

kapsl: 57

gjevremovic: 49

TimK: 41

Fransua33: 39

fred: 38

Thomas Reuther: 33

Rainer Versteeg: 32

Member Stats:

Guest Posters: 0

Members: 1186

Moderators: 15

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1059

Posts: 4458

Newest Members:

gilbertvpj, ThoreB, Gwind, angleamohammad, steffenk41, smartin2k, peterjmf69, juliusdavidson, linettemacandie, RajiMenon

Moderators: Jouni Aro: 857, Otso Palonen: 32, Tuomas Hiltunen: 5, janimakela: 0, Pyry: 1, Terho: 0, Petri: 0, Bjarne Boström: 581, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Teppo Uimonen: 21, Markus Johansson: 28, Matti Siponen: 79, Lusetti: 0

Administrators: admin: 1