12/06/2021
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?
Moderators-Specifications
Moderators-Companion
Moderators-Implementation
Moderators-Certification
Moderators-COM
02/24/2014
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
12/06/2021
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.
Moderators-Specifications
Moderators-Companion
Moderators-Implementation
Moderators-Certification
Moderators-COM
02/24/2014
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
05/30/2017
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).
12/06/2021
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.
05/30/2017
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.
1 Guest(s)