Recommended way to model a nullable value|OPC UA Standard|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
Recommended way to model a nullable value
Avatar
EG
Member
Members
Forum Posts: 35
Member Since:
12/06/2021
sp_UserOfflineSmall Offline
1
08/24/2022 - 23:49
sp_Permalink sp_Print

What is the recommended way to model a value that is either a built-in type, or null?

For example, a variable that needs to show the DateTime that something occurred, or alternatively indicate that the event has never occurred?

My reading of OPC 10000-6 is that I can't rely on actual NULL values as the data encoding scheme may not support them.

My idea is to return GoodNoData to indicate a null, but the documentation for this status code states:

No data exists for the requested time range or event filter.

Is it OK to use status code in this way, even though the documentation indicates it is related to historical events?

Avatar
Paul Hunkar
Cleveland, Ohio, USA
Moderator
Members

Moderators-Specifications

Moderators-Companion

Moderators-Implementation

Moderators-Certification

Moderators-COM
Forum Posts: 109
Member Since:
02/24/2014
sp_UserOfflineSmall Offline
2
09/14/2022 - 05:16
sp_Permalink sp_Print

Generally you can apply a more specific use for an error code not not a broader use - so this error code is about historical data and should not be used for a current value.

If I understand your question, I think the code would be typically be a BadWaitingForInitialData  - you don't have a value for this item

Paul Hunkar - DSInteroperability

Avatar
EG
Member
Members
Forum Posts: 35
Member Since:
12/06/2021
sp_UserOfflineSmall Offline
3
09/14/2022 - 05:23
sp_Permalink sp_Print sp_EditHistory

This is unfortunate because I really don't want to use a "Bad" status code as it may give the user an impression that the server is malfunctioning, when in fact this is a normal condition.

To give a concrete example, let's say I want to display the last login date of a user. If the user has been created but never actually logged in, there is no date for this property - but I wouldn't say that's bad.

What other value could I return from such a property?

Also BadWaitingForInitialData documentation states that the server is waiting for data from an underlying source, so this wouldn't be accurate in any case. The problem is the underlying source is a nullable datetime, but the OPC UA property cannot express this.

Avatar
Paul Hunkar
Cleveland, Ohio, USA
Moderator
Members

Moderators-Specifications

Moderators-Companion

Moderators-Implementation

Moderators-Certification

Moderators-COM
Forum Posts: 109
Member Since:
02/24/2014
sp_UserOfflineSmall Offline
4
09/14/2022 - 06:14
sp_Permalink sp_Print

A good code still needs to have a value, a bad does not. 

DateTime considers a 0 as a null value, I don't believe this is an issue on any platform, so you can encode it as just a zero if you don't want to indicate that no value has been received for this variable. 

I guess the decision is dependent on what you want a client to display - a zero would be an initial time that a person should understand, but an application might not (with out being coded for it).  a bad the application would understand as would the operator (not data for this value).  this is also the case where the error string could be extend to say "user has not logged in, thus no data" or "waiting on first login"   [being more specific for an error]

Paul Hunkar - DSInteroperability

Avatar
Randy Armstrong
Admin
Forum Posts: 1450
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
5
09/15/2022 - 14:06
sp_Permalink sp_Print

To give a concrete example, let's say I want to display the last login date of a user. If the user has been created but never actually logged in, there is no date for this property - but I wouldn't say that's bad.

Good with DateTime.MinValue (the null value for DateTime values).

https://reference.opcfoundatio.....rt6/5.1.4/

Avatar
EG
Member
Members
Forum Posts: 35
Member Since:
12/06/2021
sp_UserOfflineSmall Offline
6
09/19/2022 - 06:07
sp_Permalink sp_Print

In general then, are you saying then that the recommended way to model a null value is to find some sentinel value for the given data type to represent null?

Do all data types have sentinel values to represent null? I couldn't actually see in that link where it says DateTime.MinValue is the null value.

Avatar
Randy Armstrong
Admin
Forum Posts: 1450
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
7
09/19/2022 - 17:06
sp_Permalink sp_Print

See https://reference.opcfoundatio.....rt6/5.1.2/

The Nullable column indicates whether a ‘null’ value exists for the DataType in all DataEncodings. A ‘null’ value is a value that is equivalent ‘no value specified’. A nullable type with a default value means the default value shall be interpreted equivalent to a null.

DateTime is a special case for a value type where the default value is can be used as 'null' value because the DateTime.MinValue is never a legitimate value.

For non-nullable types there is no canonical way represent a 'Good' but 'not-set' value.

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1348
Posts: 4575