ReadHistoryAtTime
Given a set of discrete time points, return the value at that time. Used for "timeline alignment."
Preliminary / Supporting
- To generate aggregated statistics, please use ReadHistoryProcessed.
- To select all origin points in a range, use ReadHistory.
Signature
public IReadOnlyList<DataValue> ReadHistoryAtTime(
string nodeId,
IReadOnlyList<DateTime> times,
bool useSimpleBounds = true);
| Parameters | Type | Default | Note |
|---|---|---|---|
| nodeId | string | — | Target; NodeId null / empty string exception ArgumentNullException |
| times | IReadOnlyList<DateTime> | — | List of discrete time points (UTC); throws null ArgumentNullException; returns an empty array if the list is empty |
| useSimpleBounds | bool | true | true = Use the most recent actual value; false = Linear interpolation (must be supported by the server) |
The number of results returned may be fewer than times
The result is IReadOnlyList<DataValue>,Length is not guaranteed to be equal to times.Count — The server can provide less.
Do not align values[i] and times[i] one-to-one, using your own DataValue alignment SourceTimestamp, or by iterating directly.
Use to retrieve a value dv.Value.AsDouble; returns double?; Directly pass formal parameter double = CS1503 Fails to Compile。
Usage
using System;
using System.Collections.Generic;
using System.Linq;
using DarraOpcUa_Client;
using var ua = new DarraOpcUa("opc.tcp://localhost:4840");
ua.Connect();
// Temperatures at every hour on the hour over the past 24 hours
var hours = Enumerable.Range(0, 25)
.Select(h => DateTime.UtcNow.Date.AddHours(h))
.ToList();
var values = ua.ReadHistoryAtTime("ns=2;s=Temperature", hours);
foreach (var dv in values) using (dv)
Console.WriteLine($"{dv.SourceTimestamp:HH:mm}: {dv.Value}");
Each one is DataValue IDisposable, Mustusing Release.
Difference from ReadHistoryProcessed
| API | Return |
|---|---|
| ReadHistoryAtTime | Each time point corresponds to an interpolated value (not aggregated) |
| ReadHistoryProcessed | One aggregate value (Avg / Min / Max / ...) per subinterval |
Example: "Pull data for 24 hours, one value per hour":
- ReadHistoryAtTime: Enter 25 integer points; return up to 25 interpolation points (the actual number may be less than 25)
- ReadHistoryProcessed: aggregate=Average, interval=1 h, one average value per subinterval
Exception
| Exception | Trigger Conditions |
|---|---|
ArgumentNullException | nodeId is null / an empty string; or times is null |
OpcUaException | The server returns a value other than; Good;ex.StatusCode this is the code returned by the server as-is. |
times An empty listNo errors, returns an empty list directly.
Implementation Constraints
- None
CancellationToken—— Only ReadHistoryStreamAsync Include the cancellation token. - Synchronous Blocking, No variants
Async. - Session-level failures are not automatically retried。
Use Cases
- Temporal Alignment: Different sensors have different sampling times; they must be synchronized to the same point in time to be compared.
- Database Export: On-the-hour sampling
- Reports: 24 lines per day