Skip to main content

ReadHistoryEvents

If the server logs event history, the client can retrieve historical events by time range.

Supporting

Signature​

public IReadOnlyList<HistoryEventArgs> ReadHistoryEvents(
string nodeId,
DateTime start,
DateTime end,
uint maxEvents = 0);
ParametersTypeDefaultNote
nodeIdstring—Event source node NodeId(default WellKnownNodes.Server = "i=2253"); throws null / empty string ArgumentNullException
startDateTime—Range starts at (UTC)
endDateTime—Range Stop (UTC)
maxEventsuint0Maximum 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).

FieldTypeNoteMay be left blank
SeverityushortSeverity Level—
MessagestringEvent TextMay be null
SourceNamestringEvent Source NameMay be null
TimeDateTime?Event Time (UTC)May be null (when the server has not provided a time)
EventTypestringEvent TypeMay 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.

Field Filtering

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​

ExceptionTrigger Conditions
ArgumentNullExceptionnodeId null / empty string
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。
  • 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​

APIWhat 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.

Next Step​