Skip to main content

ReadHistoryProcessed

Given a range, an aggregate function, and the width of each subrange, the server returns the aggregate result for each subrange.

Preliminary / Supporting

Signature​

public IReadOnlyList<DataValue> ReadHistoryProcessed(
string nodeId,
DateTime start,
DateTime end,
TimeSpan processingInterval,
string aggregateNodeId);
ParametersTypeDefaultNote
nodeIdstring—Target; NodeId null / empty string exception ArgumentNullException
startDateTime—Range starts at (UTC)
endDateTime—Range Stop (UTC)
processingIntervalTimeSpan—Length of a single aggregation interval;<= TimeSpan.Zero Discard ArgumentOutOfRangeException
aggregateNodeIdstring—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​

ConstantsNodeIdMeaning
HistoryAggregate.Averagei=2342Arithmetic Mean
HistoryAggregate.Minimumi=2346Minimum Value
HistoryAggregate.Maximumi=2347Maximum value
HistoryAggregate.Counti=2352within the range "Good" status Number of data points
HistoryAggregate.Totali=2348Cumulative (Algebraic Sum)
HistoryAggregate.StandardDeviationSamplei=11427Sample standard deviation (denominator of n-1)
HistoryAggregate.TimeAveragei=11285Time-Weighted Average (Weighted by SamplingInterval)
HistoryAggregate.Rangei=2353Within the interval (maximum value − minimum value)
HistoryAggregate.Deltai=11286End 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​

ExceptionTrigger Conditions
ArgumentNullExceptionnodeId or aggregateNodeId null / an empty string
ArgumentOutOfRangeExceptionprocessingInterval <= TimeSpan.Zero
OpcUaExceptionThe 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

Next Step​