DataValue
DataValue All information returned by a single Read operation: value + status + timestamp.
- Please see the container Variant.
- For standard node constants, see WellKnownNodes.
Public Attributes
| Category | Property | Type | Access | Description |
|---|---|---|---|---|
| Value | Value | Variant | R | Actual value |
| Status | Status | StatusCode | R | Data quality: Good / Bad* / Uncertain* |
IsGood | bool | R | Whether it is Good (equivalent to Status == StatusCode.Good) | |
| Timestamps | SourceTimestamp | DateTime? | R | Timestamp applied by the data source (UTC) |
ServerTimestamp | DateTime? | R | Timestamp applied when the server received the request (UTC) | |
| Life Cycle | Dispose() | 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:
| Source | Return |
|---|---|
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 / ReadHistoryProcessed | IReadOnlyList<DataValue> |
ua.ReadRange(nodeId, range, attr) | DataValue |
ua.ReadSafe(nodeId, attribute) | (StatusCode Status, DataValue Value) |
ua.ReadHistorySafe(...) | (StatusCode Status, IReadOnlyList<DataValue> Values) |
Note:
ReadRangeIt is an extension method ofNumericRangeExtensions, not an instance memberDarraOpcUaof; non-integer range operations currently throw an exceptionNotImplementedException; see NumericRange。ReadHistoryEventsThe result isIReadOnlyList<HistoryEventArgs>, NoDataValue。ReadSafeReturns 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):
| Value | Meaning |
|---|---|
| Good (0x00000000) | Everything is normal |
| Uncertain (0x40000000) | Uncertain but usable (e.g., sensor out of range) |
| Bad (0x80000000) | Invalid data |
| BadCommunicationError | Communication Failed |
| BadNodeIdUnknown | The node does not exist |
| BadNotReadable | This 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.