Skip to main content

ReadHistory

public IReadOnlyList<DataValue> ReadHistory(
string nodeId,
DateTime startTime,
DateTime endTime,
uint maxValues = 0);

The most commonly used history read, which returns the raw data points [startTime, endTime] within the specified range (the actual number of rows is subject to server maxValues limitations).

Preliminary / Supporting

Parameters​

ParametersTypeDefaultNote
nodeIdstring—Target; NodeId throws null or an empty string ArgumentNullException
startTimeDateTime—Range starts at (UTC)
endTimeDateTime—Range Stop (UTC)
maxValuesuint0Maximum number of rows returned per query; 0 = no limit (passed to the server as-is)

Returns IReadOnlyList<DataValue>,Not streaming — Load the entire range at once. To render while loading, use ReadHistoryStreamAsync(IAsyncEnumerable<DataValue>)。

Usage​

using System;
using DarraOpcUa_Client;

using var ua = new DarraOpcUa("opc.tcp://localhost:4840");
ua.Connect();

var dvs = ua.ReadHistory("ns=2;s=Temperature",
startTime: DateTime.UtcNow.AddHours(-1),
endTime: DateTime.UtcNow,
maxValues: 1000);

foreach (var dv in dvs) using (dv)
Console.WriteLine($"{dv.SourceTimestamp:O}: {dv.Value} ({dv.Status})");

DataValue Members: Value(Variant) / Status(StatusCode) / IsGood / SourceTimestamp(DateTime?) / ServerTimestamp(DateTime?) / Dispose(). Use to retrieve a value dv.Value.AsDouble; it returns double?, passing it directly to double the formal parameter will CS1503 Fails to Compile, ?? 0 or evaluate it as empty first.

Exception​

ExceptionTrigger Conditions
ArgumentNullExceptionnodeId null / empty string
OpcUaExceptionThe server returns a value other than; Good;ex.StatusCode —that is, the server returns the code exactly as it is.

The SDK does not rewrite the server's status codes. The most common one is BadHistoryOperationUnsupported (the server has no Historian); all other codes are determined by the server and are not predefined in this documentation.

Implementation Constraints​

  • None CancellationToken —— API In history, there is only ReadHistoryStreamAsync Bring the cancellation token—ReadHistory don’t bring it yourself. If you can cancel it, use the streaming version.
  • Synchronous Blocking: The calling thread waits until the function returns; there are no variants ReadHistoryAsync.
  • Automatically retry once in the event of a session-level failure(Only if present ReadHistory ): Session-level failure encountered (BadSessionClosed / BadSessionIdInvalid / BadServerNotConnected / BadConnectionClosed / BadSecureChannelClosed) Retry once after automatic reconnection; node-level errors (such as BadNodeIdUnknown) are not retried. ReadHistoryModified / AtTime / Processed / Events / UpdateHistory / DeleteHistoryRange None of them retry.
  • No exposure ContinuationPoint; a single call returns all points within the interval (subject to certain limitations maxValues ).
  • To use the version that "never throws exceptions ReadHistorySafe," return (StatusCode Status, IReadOnlyList<DataValue> Values) Tuple.

Performance and Best Practices​

  • High-frequency data (1000 Hz+) pulled for one day = 86 million+ points → Must use a maxValues limit or switch to ReadHistoryProcessed Aggregation

  • Each item in the list is DataValue IDisposable,Must Release:

    foreach (var dv in dvs) using (dv) { /* Release after use */ }
  • All timestamps must be set uniformly UTC; do not use local time.

Next Step​