readHistoryEvents
Si el servidor registra el historial de eventos (HistoryRead Events), el cliente puede recuperar los eventos históricos por intervalos de tiempo.
Accesorios
- Para suscribirse a eventos en tiempo real, utilice Suscripción a eventos.
- Para los datos históricos de las variables, utilice ReadRaw / ReadProcessed.
Firma
public List<OpcUaEventSubscription.EventArrivedEventArgs> readHistoryEvents(
String nodeId, // Normalmente, i = 2253, servidor
Instant start,
Instant end,
int maxEvents);
Devuelve el mismo tipo que el de la suscripción a eventos en tiempo real EventArrivedEventArgs reutilizada (alineación de campos).
EventArrivedEventArgs Campo
| Campo | Tipo | Explicación |
|---|---|---|
| severity | int | 1-1000 |
| message | String | Texto del suceso |
| sourceName | String | Nombre de la fuente del evento |
| timeFt | long | FileTime, 0 = null |
| eventType | String | Tipo de incidente NodeId |
Modo de empleo
import java.time.Instant;
import java.time.Duration;
List<OpcUaEventSubscription.EventArrivedEventArgs> events = ua.readHistoryEvents(
WellKnownNodes.SERVER,
Instant.now().minus(Duration.ofDays(1)),
Instant.now(),
0);
for (OpcUaEventSubscription.EventArrivedEventArgs e : events) {
long ft = e.timeFt;
Instant t = (ft > 0)
? Instant.ofEpochMilli((ft - 116444736000000000L) / 10000L)
: Instant.now();
System.out.printf("[%d] %s: %s @ %s%n",
e.severity, e.sourceName, e.message, t);
}
Personalizar EventFilter
Actualmente, se muestran de forma SDK predeterminada 4 campos (Severity / Message / SourceName / Time). Los filtros complejos (por EventType / Severity / SourceNode) se implementarán en versiones posteriores mediante un generador API.
Requisitos del servidor
- Debe ser compatible con HistoryRead Events (banderas ServerCapabilities del servidor)
- El nodo de origen del evento debe tener activado el bit 1 (HistoryRead) del atributo EventNotifier (12).
Relación con la suscripción a eventos en tiempo real
| API | ¿Con qué? |
|---|---|
| subscribeEvents(...) | Eventos en tiempo real (que se producen durante el periodo de suscripción) |
| readHistoryEvents(...) | Acontecimientos históricos (archivados en el servidor) |
Combinación habitual: al iniciarse, se readHistoryEvents aplica durante 24 horas y, a continuación, se subscribeEvents activa en tiempo real.