Saltar al contenido principal

HistoryReadEvents (C)

Si el servidor registra el historial de eventos, el cliente puede recuperar los eventos históricos (alarmas / condiciones) por intervalos de tiempo.

Accesorios

API​

#include <opcua/opcua_history.h>
#include <opcua/opcua_event.h>

OPCUA_API DarraUa_Status OPCUA_CALL DarraUa_Session_HistoryReadEvents(
DarraUa_SessionHandle h,
const char* node_id_str, /* Normalmente, "i=2253" Servidor */
DarraUa_DateTime start_time,
DarraUa_DateTime end_time,
uint32_t num_values_per_node,
DarraUa_Event*** out_events,
uint32_t* out_count);

DarraUa_Event* Estructura idéntica a Suscripción a eventos.

Integrado SelectClauses​

Fijar 4 campos estándar (coincidentes con los del «Subscription Event»):

  • Severity (UInt16)
  • Message (LocalizedText)
  • SourceName (String)
  • Time (DateTime)

whereClause Dejar en blanco = todos los eventos.

Liberación​

DarraUa_EventArray_Delete(events, count);

_EventArray_Delete Liberar el propio array, cada elemento de Event y los campos de cadena generados mediante strdup dentro de Event.

Modo de empleo​

#include <opcua/opcua_history.h>
#include <opcua/opcua_event.h>

DarraUa_DateTime end = utc_now_ft();
DarraUa_DateTime start = end - 864000000000LL; /* 24 horas */

DarraUa_Event** events = NULL;
uint32_t count = 0;

DarraUa_Status st = DarraUa_Session_HistoryReadEvents(
h, "i=2253",
start, end,
/*num*/ 0, /* Sin límite */
&events, &count);

if (UA_STATUS_IS_GOOD(st)) {
for (uint32_t i = 0; i < count; ++i) {
const DarraUa_Event* ev = events[i];
printf("[sev=%u] src=\"%s\" time=%lld msg=\"%s\"\n",
(unsigned)ev->severity,
ev->source_name ? ev->source_name : "",
(long long)ev->time,
ev->message ? ev->message : "");
}
}

DarraUa_EventArray_Delete(events, count);

Requisitos del servidor​

  • El servidor debe implementar la HistoryRead función ReadEventsDetails (Part 11 §6.4.4); si no es compatible, el código de estado del servidor se transmite tal cual.
  • El nodo de origen del evento debe tener activado el HistoryRead bit (0x02) del atributo EventNotifier (12).

Relación con la suscripción a eventos en tiempo real​

API¿Con qué?
DarraUa_Subscription_AddEventItem(...)Eventos en tiempo real (que se producen durante el periodo de suscripción)
DarraUa_Session_HistoryReadEvents(...)Acontecimientos históricos (archivados en el servidor)

Combinación habitual: al iniciarlo, ReadEvents se aplica durante 24 horas y, a continuación, la suscripción toma el relevo en tiempo real.

Siguiente paso​