read_history (Raw)
pub fn Session::read_history(
&self,
node_id: &str,
start_utc: SystemTime,
end_utc: SystemTime,
max_values: u32,
) -> Result<Vec<DataValue>, OpcUaError>;
The most commonly used historical read, which returns all raw data points within the specified [start_utc, end_utc] interval.
Preliminary / Supporting
- Switch to this when there are too many high-frequency data points ReadProcessed Aggregation.
- If you want to include revision history, please use ReadModified.
Parameters
| Parameters | Type | Note |
|---|---|---|
| node_id | &str | Objective NodeId |
| start_utc | SystemTime | Range starts at (UTC) |
| end_utc | SystemTime | Range Stop (UTC) |
| max_values | u32 | Maximum number of results per query; 0 = unlimited |
Usage
use std::time::{Duration, SystemTime};
let now = SystemTime::now();
let dvs = s.read_history(
"ns=2;s=Temperature",
now - Duration::from_secs(3600),
now,
1000,
)?;
for dv in &dvs {
println!("{:?}: {:?} ({})",
dv.source_timestamp(),
dv.variant().try_get_f64().unwrap_or(0.0),
dv.status());
}
Error
| StatusCode | Meaning |
|---|---|
| BAD_HISTORY_OPERATION_UNSUPPORTED | There is no Historian on the server |
| BAD_NOT_READABLE | The node does not have permission HistoryRead. |
| BAD_COMMUNICATION_ERROR | Network Outage |
| INVALID_ARGUMENT | node_id contains NUL |
When dealing with large amounts of data
When there are many return items, a single call returns the complete list, No need for manual pagination or "Read More" links.
Performance and Best Practices
- High-frequency data (1000 Hz+) pulled for one day = 86 million+ points → Must use a
max_valueslimit or switch to ReadProcessed Aggregation DataValueImplementedDrop; automatically released when it goes out of scope, No manual release is required- All timestamps must be consistent UTC; do not use local time.
{
let dvs = s.read_history("ns=2;s=T", t0, t1, 0)?;
for dv in &dvs {
// Using a DV ...
}
} // <- When `dvs Vec` goes out of scope, each `Drop DataValue ` fully releases the resources
Pull in batches over a large range
Avoid pulling too much at once; divide it into smaller sections and work through them in cycles:
use std::time::{Duration, SystemTime};
let mut cur = start_time;
let chunk = Duration::from_secs(3600); // 1 hour per segment
let mut all: Vec<darra_opcua::DataValue> = Vec::new();
while cur < end_time {
let end = (cur + chunk).min(end_time);
let mut batch = s.read_history("ns=2;s=Temperature", cur, end, 100_000)?;
all.append(&mut batch);
cur = end;
}