EventFilter
Überblick
OPC UA Part 4 §7.18 EventFilter:
- select_clauses — Welche Felder sollen erfasst werden?
- where_clause — Filterkriterien (V1 bitte einfach „NULL“ belassen)
DarraUa_SimpleAttributeOperand Felder: type_definition_id / browse_path / attribute_id / index_range.
Ereignisfilterung API in SDK Erweiterungsheadern (nicht in Protokollstapel-Headern ABI):
#include <opcua/opcua.h>
#include "../include/opcua_filter.h"
API
typedef struct {
/** Ereignistyp NodeId Zeichenkette, z. B. "i=2041" (BaseEventType). NULL = Platzhalter BaseEventType. */
const char* type_definition_id;
/** Feld BrowsePath (jeder Abschnitt BrowseName). NULL Oder count == 0 bedeutet, dass alle Ereignisse ausgewählt werden. */
const char* const* browse_path;
size_t browse_path_count;
/** Eigenschaft ID, Standard UA_ATTR_VALUE. */
DarraUa_AttributeId attribute_id;
/** Indexbereich des Arrays (NumericRange Zeichenkette). NULL = Nicht festgelegt. */
const char* index_range;
} DarraUa_SimpleAttributeOperand;
typedef struct {
const DarraUa_SimpleAttributeOperand* select_clauses;
size_t select_clauses_count;
const char* where_clause; /* NULL = Keine WHERE-Klausel */
} DarraUa_EventFilter;
| Funktion | Kategorie | Lesen und Schreiben | Erläuterung |
|---|---|---|---|
| DarraUa_EventSubscription_SubscribeWithFilter(sub, object_node_id, filter, cb, user_context, out_mi) | Funktion | Schreiben | Ereignis mit benutzerdefiniertem Filter erstellen MI |
UA_SDK_API DarraUa_Status UA_SDK_CALL DarraUa_EventSubscription_SubscribeWithFilter(
DarraUa_SubscriptionHandle sub,
const char* object_node_id, /* NULL = "i=2253" */
const DarraUa_EventFilter* filter, /* NULL = Mit den 4 Standardfeldern */
DarraUa_OnEvent cb,
void* user_context,
DarraUa_MonitoredItemHandle* out_mi);
Die Signatur des Ereignis-Callbacks finden Sie unter Ereignisabonnement DarraUa_OnEvent.
Code-Beispiel
#include <opcua/opcua.h>
#include "../include/opcua_filter.h"
DarraUa_SessionConfig cfg;
DarraUa_SessionConfig_Init(&cfg);
cfg.endpoint_url = "opc.tcp://localhost:4840";
cfg.security_mode = UA_MSG_SECURITY_MODE_NONE;
cfg.security_policy_uri = "http://opcfoundation.org/UA/SecurityPolicy#None";
cfg.user_token_type = UA_USER_TOKEN_ANONYMOUS;
DarraUa_SessionHandle h = UA_INVALID_SESSION_HANDLE;
DarraUa_Session_Create(&cfg, &h);
DarraUa_Session_Connect(h);
DarraUa_SubscriptionConfig sc;
DarraUa_SubscriptionConfig_Init(&sc);
sc.publishing_interval_ms = 500.0;
sc.publishing_enabled = 1;
DarraUa_SubscriptionHandle sub = UA_INVALID_SUBSCRIPTION_HANDLE;
DarraUa_Subscription_Create(h, &sc, &sub);
// Filter erstellen
const char* event_id_path[] = { "EventId" };
const char* source_path[] = { "SourceName" };
const char* time_path[] = { "Time" };
const char* msg_path[] = { "Message" };
const char* sev_path[] = { "Severity" };
const char* cond_id_path[] = { "ConditionId" };
const char* active_state_path[] = { "ActiveState", "Id" };
DarraUa_SimpleAttributeOperand selects[7] = {
{ "i=2041", event_id_path, 1, UA_ATTR_VALUE, NULL },
{ "i=2041", source_path, 1, UA_ATTR_VALUE, NULL },
{ "i=2041", time_path, 1, UA_ATTR_VALUE, NULL },
{ "i=2041", msg_path, 1, UA_ATTR_VALUE, NULL },
{ "i=2041", sev_path, 1, UA_ATTR_VALUE, NULL },
{ "i=2782", cond_id_path, 1, UA_ATTR_VALUE, NULL },
{ "i=2915", active_state_path, 2, UA_ATTR_VALUE, NULL },
};
DarraUa_EventFilter filter = {
.select_clauses = selects,
.select_clauses_count = 7,
.where_clause = NULL,
};
DarraUa_MonitoredItemHandle ev_mi = UA_INVALID_MONITORED_ITEM_HANDLE;
DarraUa_Status st = DarraUa_EventSubscription_SubscribeWithFilter(
sub, "i=2253", &filter, on_event, NULL, &ev_mi);
on_event
Die DarraUa_Event
Lastfelder werden SDK
fest berechnet
severity
/ message
/ source_name
/ time
/ event_type
und ändern sich nicht bei der Einzelauswertung select_clauses
; dies wird durch benutzerdefinierte select_clauses bestimmtWelche Felder werden vom Server übermittelt?。
Schnellsuche nach Feldern
| EventType | BrowsePath | Bedeutung |
|---|---|---|
| BaseEventType (i=2041) | ["EventId"] | Eindeutige ID des Vorfalls |
| BaseEventType | ["Severity"] | Schweregrad 1–1000 |
| ConditionType (i=2782) | ["ConditionId"] | Bedingungen NodeId |
| AcknowledgeableConditionType (i=2881) | ["AckedState", "Id"] | Ack oder nicht |
| AlarmConditionType (i=2915) | ["ActiveState", "Id"] | Ist es aktiviert? |
Erläuterungen zur Umsetzung
- Alle Felder werden ausgeliehen und RPC vor SDK dem Aufruf tief kopiert; nach der
SubscribeWithFilterRückkehr kann die Struktur freigegeben werden bzw. verlässt den Gültigkeitsbereich. - Stack unterstützt keine benutzerdefinierte „Graceful Downgrade“-Funktion SelectClauses: FallbackStandardmäßig 4 Felder (Schweregrad / Meldung / SourceName / Zeit) und ein Info-Log erstellen
Bewährte Verfahren
- Felder explizit auflisten
- Alarmzentrale – unbedingt sichern ConditionId
Sprachübergreifender Vergleich
| C# | Python | Java | C++ | Rust | C |
|---|---|---|---|---|---|
| EventFilter | EventFilter | EventFilter | EventFilter | EventFilter | DarraUa_EventFilter |
| SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | SimpleAttributeOperand | DarraUa_SimpleAttributeOperand |