Skip to main content

DataValue

DataValue All information returned by a single Read operation: value + status + timestamp.

Supporting

Public Attributes​

CategoryPropertyTypeAccessDescription
ValueValueVariantRActual value
StatusStatusStatusCodeRData quality: Good / Bad* / Uncertain*
IsGoodboolRWhether it is Good (equivalent to Status == StatusCode.Good)
TimestampsSourceTimestampDateTime?RTimestamp applied by the data source (UTC)
ServerTimestampDateTime?RTimestamp applied when the server received the request (UTC)
Life CycleDispose()void—Release resources (IDisposable)

Authentic signature:

public sealed class DataValue : IDisposable
{
public Variant Value { get; } // Value Container
public StatusCode Status { get; } // Quality code returned by the server
public bool IsGood { get; } // Status == StatusCode.Good
public DateTime? ServerTimestamp { get; } // Server timestamp (UTC), null if no value is provided
public DateTime? SourceTimestamp { get; } // Source Timestamp (UTC), null if no value
public void Dispose();
}

Value Each request returns aBorrowVariant — It does not need to be released separately, nor can it be; the outer layer handles the release all at once DataValue.Dispose().

How to Obtain​

DataValue The constructor is not exposed to the outside (it is internal), and users do not create instances themselves. Instances are always obtained from the return value of API the reader class:

SourceReturn
ua.Read(nodeId, attribute = AttributeId.Value)DataValue
ua.ReadMany(nodeIds, attribute) / ua.ReadMany(items)IReadOnlyList<DataValue>
ua.ReadHistory(nodeId, startTime, endTime, maxValues = 0)IReadOnlyList<DataValue>
ua.ReadHistoryModified / ReadHistoryAtTime / ReadHistoryProcessedIReadOnlyList<DataValue>
ua.ReadRange(nodeId, range, attr)DataValue
ua.ReadSafe(nodeId, attribute)(StatusCode Status, DataValue Value)
ua.ReadHistorySafe(...)(StatusCode Status, IReadOnlyList<DataValue> Values)

Note:

  • ReadRange It is an extension method of NumericRangeExtensions, not an instance member DarraOpcUa of; non-integer range operations currently throw an exception NotImplementedException; see NumericRange。
  • ReadHistoryEvents The result is IReadOnlyList<HistoryEventArgs>, No DataValue。
  • ReadSafe Returns on an exception (StatusCode, null); does not throw.

When you need to submit a history write, place the retrieved data into the array values exactly as is DataValue; do not modify it locally:

public IReadOnlyList<StatusCode> UpdateHistory(
string nodeId, HistoryUpdateType updateType, IReadOnlyList<DataValue> values);

Usage​

using System;
using DarraOpcUa_Client;

using var dv = ua.Read("ns=2;s=Temperature");

// Quality Inspection
if (!dv.IsGood)
{
Console.WriteLine($"Bad value: {dv.Status}");
return;
}

// Value
double? temp = dv.Value.AsDouble;
if (temp is null)
{
Console.WriteLine("Null value");
return;
}

DateTime t = dv.SourceTimestamp ?? DateTime.UtcNow;
Console.WriteLine($"{t:O}: {temp} °C");

StatusCode Key Value​

The member's name is PascalCase (Not in ALL CAPS):

ValueMeaning
Good (0x00000000)Everything is normal
Uncertain (0x40000000)Uncertain but usable (e.g., sensor out of range)
Bad (0x80000000)Invalid data
BadCommunicationErrorCommunication Failed
BadNodeIdUnknownThe node does not exist
BadNotReadableThis attribute is not readable.

Business logic must be verified Status; you cannot simply assume it is correct.

Meaning of Timestamps​

  • SourceTimestamp — Actual Time the Data Was Generated (Sensor sampling time / calculation time). Use this for history, trends, and synchronization.
  • ServerTimestamp — Server Receive/Processing Time. Used to diagnose network latency. Generally not used for business purposes.

Both properties are DateTime?: the server not supplying a timestamp (file time 0) yields null, and the SDK does not back-fill the other one. Whether back-filling happens is up to the server implementation; when the client receives null it must fall back itself, e.g. dv.SourceTimestamp ?? dv.ServerTimestamp ?? DateTime.UtcNow.

Memory Ownership​

DataValue Implement IDisposable. Anything returned ua.Read / ua.ReadHistory / ua.ReadMany from this method must call Dispose.

Best Practices:

using System;
using DarraOpcUa_Client;

// Single
using (var dv1 = ua.Read("ns=2;s=T1"))
{
// Use dv1
}

// Batch
var nodes = new[] { "ns=2;s=T1", "ns=2;s=T2" };
var dvs = ua.ReadMany(nodes);
try
{
foreach (var dv2 in dvs) { /* Use dv2 */ }
}
finally
{
foreach (var dv2 in dvs) dv2?.Dispose();
}

Failing to call Dispose will cause a memory leak.

Next Step​