ReadHistoryProcessed
Given a range, an aggregate function, and the width of each subrange, the server returns the aggregate result for each subrange.
Preliminary / Supporting
- To pull all original points, please use ReadHistory.
- For interpolation at a specific point in time, please use ReadHistoryAtTime.
Signature
public IReadOnlyList<DataValue> ReadHistoryProcessed(
string nodeId,
DateTime start,
DateTime end,
TimeSpan processingInterval,
string aggregateNodeId);
| Parameters | Type | Default | Note |
|---|---|---|---|
| nodeId | string | — | Target; NodeId null / empty string exception ArgumentNullException |
| start | DateTime | — | Range starts at (UTC) |
| end | DateTime | — | Range Stop (UTC) |
| processingInterval | TimeSpan | — | Length of a single aggregation interval;<= TimeSpan.Zero Discard ArgumentOutOfRangeException |
| aggregateNodeId | string | — | Aggregate functions NodeId: Choose from the constants HistoryAggregate; throw null or an empty string. ArgumentNullException |
Returns IReadOnlyList<DataValue>:One aggregate value per subinterval, where the number of rows is determined by the interval length ÷ processingInterval
; the server may return fewer. Each DataValue is IDisposable, Mustusing Release.
Use to retrieve a value dv.Value.AsDouble; returns double?; Directly pass formal parameter double = CS1503 Fails to Compile。
HistoryAggregate Constants
| Constants | NodeId | Meaning |
|---|---|---|
HistoryAggregate.Average | i=2342 | Arithmetic Mean |
HistoryAggregate.Minimum | i=2346 | Minimum Value |
HistoryAggregate.Maximum | i=2347 | Maximum value |
HistoryAggregate.Count | i=2352 | within the range "Good" status Number of data points |
HistoryAggregate.Total | i=2348 | Cumulative (Algebraic Sum) |
HistoryAggregate.StandardDeviationSample | i=11427 | Sample standard deviation (denominator of n-1) |
HistoryAggregate.TimeAverage | i=11285 | Time-Weighted Average (Weighted by SamplingInterval) |
HistoryAggregate.Range | i=2353 | Within the interval (maximum value − minimum value) |
HistoryAggregate.Delta | i=11286 | End of Interval − Start of Interval |
If the server does not support a particular aggregation, the call returns a failure OpcUaException; see OpcUaException.StatusCode
—— SDK Do not modify the server's code.
Usage
Hourly average of the 24-hour temperature
using System;
using DarraOpcUa_Client;
using var ua = new DarraOpcUa("opc.tcp://localhost:4840");
ua.Connect();
var values = ua.ReadHistoryProcessed(
nodeId: "ns=2;s=Temperature",
start: DateTime.UtcNow.Date.AddDays(-1),
end: DateTime.UtcNow.Date,
processingInterval: TimeSpan.FromHours(1),
aggregateNodeId: HistoryAggregate.Average);
foreach (var dv in values) using (dv) // One aggregate value per subinterval (24 segments in this example)
Console.WriteLine($"{dv.SourceTimestamp:HH:mm}: {dv.Value}");
Highest Temperature Each Day of the Week
var today = DateTime.UtcNow.Date;
var maxes = ua.ReadHistoryProcessed("ns=2;s=Temperature",
start: today.AddDays(-7), end: today,
processingInterval: TimeSpan.FromDays(1),
aggregateNodeId: HistoryAggregate.Maximum);
foreach (var dv in maxes) using (dv)
Console.WriteLine($"{dv.SourceTimestamp:yyyy-MM-dd}: {dv.Value}");
Total traffic in one hour
var now = DateTime.UtcNow;
var totals = ua.ReadHistoryProcessed("ns=2;s=FlowRate",
start: now.AddHours(-1), end: now,
processingInterval: TimeSpan.FromHours(1),
aggregateNodeId: HistoryAggregate.Total);
foreach (var dv in totals) using (dv)
Console.WriteLine($"{dv.SourceTimestamp:HH:mm}: {dv.Value}");
Exception
| Exception | Trigger Conditions |
|---|---|
ArgumentNullException | nodeId or aggregateNodeId null / an empty string |
ArgumentOutOfRangeException | processingInterval <= TimeSpan.Zero |
OpcUaException | The server returns a value other than; Good;ex.StatusCode this is the code returned by the server as-is. |
Implementation Constraints
- None
CancellationToken—— Only ReadHistoryStreamAsync Include the cancellation token. - Synchronous Blocking, No variants
Async. - Session-level failures are not automatically retried。
- Aggregated byServer-side In short, the client does not perform any secondary calculations; whether the server actually supports a particular Aggregate is determined by the server.
Performance Advantages
- Avoid fetching a large number of raw data points and then processing them on the client side.
- Standard Solutions for Cross-Day and Cross-Week Reports