DataValue
DataValue All information returned by a single Read operation: value + status + timestamp.
- For the internal value container, please see Variant.
- For standard node constants, see well_known_nodes.
Public Methods
| Category | Property | Type | Access | Description |
|---|---|---|---|---|
| Value | variant() | Variant | R | Actual value (owns=false, borrowed) |
value() | Variant | R | Backward-compatible name; equivalent to variant() | |
| Status | status() | StatusCode | R | Data quality: Good / Bad* / Uncertain* |
is_good() | bool | R | == status().is_good() | |
| Timestamps | source_timestamp() | Option<SystemTime> | R | Timestamp applied by the data source |
server_timestamp() | Option<SystemTime> | R | Timestamp generated by the server | |
source_timestamp_ft() | i64 | R | FILETIME 100ns since 1601 (backward-compatible API) | |
server_timestamp_ft() | i64 | R | Same 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
| Value | Meaning |
|---|---|
| GOOD (0x00000000) | Everything is normal |
| UNCERTAIN (0x40000000) | Uncertain but usable (e.g., sensor out of range) |
| BAD (0x80000000) | Invalid data |
| BAD_COMMUNICATION_ERROR | Communication Failed |
| BAD_NODE_ID_UNKNOWN | The node does not exist |
| BAD_NOT_READABLE | This 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.