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).
- Switch to this when there are too many high-frequency data points ReadHistoryProcessed Aggregation.
- If you want to include revision history, please use ReadHistoryModified.
Parameters
| Parameters | Type | Default | Note |
|---|---|---|---|
| nodeId | string | — | Target; NodeId throws null or an empty string ArgumentNullException |
| startTime | DateTime | — | Range starts at (UTC) |
| endTime | DateTime | — | Range Stop (UTC) |
| maxValues | uint | 0 | Maximum 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
| Exception | Trigger Conditions |
|---|---|
ArgumentNullException | nodeId null / empty string |
OpcUaException | The 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—ReadHistorydon’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 asBadNodeIdUnknown) are not retried.ReadHistoryModified/AtTime/Processed/Events/UpdateHistory/DeleteHistoryRangeNone of them retry. - No exposure
ContinuationPoint; a single call returns all points within the interval (subject to certain limitationsmaxValues). - 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
maxValueslimit or switch to ReadHistoryProcessed Aggregation -
Each item in the list is
DataValueIDisposable,Must Release:foreach (var dv in dvs) using (dv) { /* Release after use */ } -
All timestamps must be set uniformly UTC; do not use local time.