ReadHistoryEvents
If the server logs event history, the client can retrieve historical events by time range.
- To subscribe to real-time events, please use Event Subscription.
- Please use the following historical variable data: ReadHistory / ReadHistoryProcessed.
Signature
public IReadOnlyList<HistoryEventArgs> ReadHistoryEvents(
string nodeId,
DateTime start,
DateTime end,
uint maxEvents = 0);
| Parameters | Type | Default | Note |
|---|---|---|---|
| nodeId | string | — | Event source node NodeId(default WellKnownNodes.Server = "i=2253"); throws null / empty string ArgumentNullException |
| start | DateTime | — | Range starts at (UTC) |
| end | DateTime | — | Range Stop (UTC) |
| maxEvents | uint | 0 | Maximum number of rows; 0 = No limit (passed to the server as-is) |
HistoryEventArgs Fields
Each returned event consists of a fixed set of fields; custom field lists are not supported (the fixed set consists of the 4 standard event fields: Severity, Message, SourceName, and Time).
| Field | Type | Note | May be left blank |
|---|---|---|---|
| Severity | ushort | Severity Level | — |
| Message | string | Event Text | May be null |
| SourceName | string | Event Source Name | May be null |
| Time | DateTime? | Event Time (UTC) | May be null (when the server has not provided a time) |
| EventType | string | Event Type | May be null |
Message / SourceName / EventType May be null; it is also null if no time is provided on Time the server side. Check for null before use.
HistoryEventArgs It is a regular class, No IDisposable, No need to release it.
Filter historical events by EventType / Severity. This feature is currently SDK not available—events are retrieved ReadHistoryEvents only by time range, and filtering is performed on the client side after the full dataset is retrieved.
Usage
using System;
using DarraOpcUa_Client;
using var ua = new DarraOpcUa("opc.tcp://localhost:4840");
ua.Connect();
var now = DateTime.UtcNow;
var events = ua.ReadHistoryEvents(WellKnownNodes.Server,
start: now.AddDays(-1),
end: now);
foreach (var e in events)
Console.WriteLine($"[{e.Severity}] {e.SourceName}: {e.Message} @ {e.Time}");
Exception
| Exception | Trigger Conditions |
|---|---|
ArgumentNullException | nodeId null / empty string |
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。
- Do not expose
ContinuationPoint; do not filter EventId by Severity / EventType /. - The returned event object is managed SDK by; the caller does not need to release it.
Server Requirements
- Must support reading event history
- The event source node must have the EventNotifier attribute (12), and its HistoryRead Position (
0x02, Position 1) Set (0x01= Subscribable event,0x02= History is readable,0x04= History is writable)
Relationship to Real-Time Event Subscriptions
| API | What to bring |
|---|---|
SubscribeEvents(nodeId, existingSubscription) | Real-time Events (Occurring During the Subscription Period) |
ReadHistoryEvents(...) | Historical Events (Archived on the Server) |
Typical setup: ReadHistoryEvents Run it for 24 hours at startup, then SubscribeEvents switch to real-time operation.