Skip to main content

DataValue

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

Supporting

Public Methods​

CategoryPropertyTypeAccessDescription
Valuevariant()VariantRActual value (owns=false, borrowed)
value()VariantRBackward-compatible name; equivalent to variant()
Statusstatus()StatusCodeRData quality: Good / Bad* / Uncertain*
is_good()boolR== status().is_good()
Timestampssource_timestamp()Option<SystemTime>RTimestamp applied by the data source
server_timestamp()Option<SystemTime>RTimestamp generated by the server
source_timestamp_ft()i64RFILETIME 100ns since 1601 (backward-compatible API)
server_timestamp_ft()i64RSame as above

Usage​

use darra_opcua::StatusCode;

let dv = s.read("ns=2;s=Temperature")?;

// Quality Inspection
if !dv.is_good() {
eprintln!("Bad value: {}", dv.status());
return Ok(());
}

// Check Value
let v = dv.variant();
if matches!(v.data_type(), darra_opcua::BuiltinType::Null) {
eprintln!("Null value");
return Ok(());
}

// Value
let temp = v.try_get_f64().unwrap_or(0.0);
let t = dv.source_timestamp();
println!("{:?}: {} °C", t, temp);

StatusCode Key Value​

ValueMeaning
GOOD (0x00000000)Everything is normal
UNCERTAIN (0x40000000)Uncertain but usable (e.g., sensor out of range)
BAD (0x80000000)Invalid data
BAD_COMMUNICATION_ERRORCommunication Failed
BAD_NODE_ID_UNKNOWNThe node does not exist
BAD_NOT_READABLEThis attribute is not readable.

Business logic must be verified status(); you cannot simply assume it is correct.

let dv = s.read("ns=2;s=X")?;
if dv.status() != StatusCode::GOOD {
eprintln!("uncertain data: {}", dv.status());
}

Meaning of Timestamps​

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

If the server does not have a SourceTimestamp set, it is a copy of ServerTimestamp.

SystemTime vs FILETIME​

source_timestamp() / server_timestamp() Returns Option<SystemTime> — None Indicates that the server is not configured (FILETIME=0).

If you want the raw ticks 100ns (without the 1601→1970 conversion), use this version *_ft():

let ft: i64 = dv.source_timestamp_ft();   // 0 if not set

Memory Ownership (Drop)​

DataValue Hold resource handles; implement Drop. From s.read / s.read_history / s.read_many All returns are automatically released, Will not leak.

In the subscription callback, if owns=false DataValue is detected wrap_borrowed, do not free the resource; the resource becomes invalid once the callback returns, so do not retain it for use outside the callback.

{
let dv = s.read("ns=2;s=T1")?;
let v = dv.variant(); // borrowed Variant, dv is valid for the duration of its lifecycle
println!("{}", v);
} // <- dv Drop, Resource Release
// Batch
let dvs = s.read_many(&nodes, AttributeId::Value)?;
for dv in &dvs {
if let Some(d) = dv {
println!("{:?}", d.variant());
}
}
// dvs goes out of scope; on each Drop DataValue , all resources are released

Cross-thread​

DataValue is Send + Sync, you can pass owned values between threads DataValue. Do not pass borrowed values ( DataValue obtained from the subscription callback) across threads or use them outside the callback; they become invalid once the callback returns.

Relationship with Subscription Callbacks​

In the subscription callback, the DataValue fields SDK have been extracted into a flat structure ( DataChangeEventArgs containing value_string, data_type_name, status, source_timestamp, server_timestamp), soThe subscription callback does not require an object DataValue .. For more information, see DataChange Callback.

Next Step​