Event handling
Posted: 10 Jul 2014, 17:28
Hello.
My model has analog and digital signals and my purpose is to generate an event with each digital signal. For a test, I have created an Event (TransitionEventType) and declared the server as event notifier and one of the digital signals as event source. This is my firing event routine:
This piece of code is executed when a digital change of state is received. As a result, I got that the event was generated in UaExpert with the change of state of all the signals, not only with the signal defined as event source. Why? Is it necessary to define all the signals as event source if I only have a single event notifier?
What's the function of the created event object? Do I need to create an object for each digital signals which will generate events? Which will be the best way to implement my issue?
Thanks in advance.
My model has analog and digital signals and my purpose is to generate an event with each digital signal. For a test, I have created an Event (TransitionEventType) and declared the server as event notifier and one of the digital signals as event source. This is my firing event routine:
Code: Select all
OpcUa_StatusCode XXXProvider_FireChangeEvent(OpcUa_UInt32 identifier)
{
UaServer_Event *pEvent = OpcUa_Null;
OpcUa_NodeId eventTypeId;
OpcUa_ByteString bsEventId;
OpcUa_Variant value;
OpcUa_NodeId nodeId, sourceNodeId;
OpcUa_Variable* pVariable;
OpcUa_InitializeStatus(OpcUa_Module_Server, "XXXProvider_FireChangeEvent");
OpcUa_NodeId_Initialize(&eventTypeId);
OpcUa_ByteString_Initialize(&bsEventId);
OpcUa_Variant_Initialize(&value);
eventTypeId.NamespaceIndex = 0;
eventTypeId.Identifier.Numeric = OpcUaId_ProgramTransitionEventType;
pEvent = UaServer_Events_CreateEvent(&eventTypeId);
UaServer_Events_CreateEventId(0, &bsEventId);
/* Set event fields of BaseEventType */
UaServer_Events_SetEventId(pEvent, &bsEventId);
UaServer_Events_SetEventType(pEvent, &eventTypeId);
nodeId.IdentifierType = OpcUa_IdentifierType_Numeric;
nodeId.NamespaceIndex = g_UaProviderXXX_uNamespaceIndex1;
nodeId.Identifier.Numeric = XXX_Objects_XXX;
sourceNodeId.IdentifierType = OpcUa_IdentifierType_Numeric;
sourceNodeId.NamespaceIndex = g_UaProviderXXX_uNamespaceIndex1;
sourceNodeId.Identifier.Numeric = identifier;
UaServer_Events_SetSourceNode(pEvent, &nodeId);
UaServer_Events_SetSourceName(pEvent, "XXX");
UaServer_Events_SetTime(pEvent, OpcUa_DateTime_UtcNow());
UaServer_Events_SetReceiveTime(pEvent, OpcUa_DateTime_UtcNow());
UaServer_Events_SetLocalTime(pEvent, OpcUa_DateTime_UtcNow());
UaServer_GetNode(&g_pXXXProvider->AddressSpace, &sourceNodeId, (OpcUa_BaseNode**)&pVariable);
if (pVariable != OpcUa_Null)
{
if (OpcUa_Variable_GetValue(pVariable)->Value.Boolean == OpcUa_False)
{
UaServer_Events_SetMessage(pEvent, "en", "var was set to OFF");
}
else
{
UaServer_Events_SetMessage(pEvent, "en", "var was set to ON");
}
}
UaServer_Events_SetSeverity(pEvent, 500);
uStatus = UaServer_Events_FireEvent(pEvent);
UaServer_Events_DeleteEvent(&pEvent);
OpcUa_ByteString_Clear(&bsEventId);
OpcUa_ReturnStatusCode;
OpcUa_BeginErrorHandling;
OpcUa_FinishErrorHandling;
}
What's the function of the created event object? Do I need to create an object for each digital signals which will generate events? Which will be the best way to implement my issue?
Thanks in advance.