Page 1 of 1

Alarms & CallAsync

Posted: 04 Aug 2014, 13:49
by perezjo
Hello,

When trying to ACK or confirm an alarm from UaExpert panel, CallAsync function is called. The code obtained from UaModeler is this:

Code: Select all

for (i = 0; i < pRequest->NoOfMethodsToCall; i++)
    {

        if (pRequest->MethodsToCall[i].MethodId.NamespaceIndex == g_UaProviderTest_uNamespaceIndex1)
        {
            pMethodId = &(pRequest->MethodsToCall[i].MethodId);
            if (pMethodId->IdentifierType == OpcUa_IdentifierType_Numeric)
            {
                switch (pMethodId->Identifier.Numeric)
                {
                case Test_Objects_Alarms_1_AddComment:
                    UaProvider_Test_ConditionType_CallAddComment(a_pCallContext, &pRequest->MethodsToCall[i], &pResponse->Results[i]);
                    break;
                case Test_Objects_Alarms_1_Disable:
                    UaProvider_Test_ConditionType_CallDisable(a_pCallContext, &pRequest->MethodsToCall[i], &pResponse->Results[i]);
                    break;
                case Test_Objects_Alarms_1_Enable:
                    UaProvider_Test_ConditionType_CallEnable(a_pCallContext, &pRequest->MethodsToCall[i], &pResponse->Results[i]);
                    break;
                case Test_Objects_Alarms_1_Acknowledge:
                    UaProvider_Test_AcknowledgeableConditionType_CallAcknowledge(a_pCallContext, &pRequest->MethodsToCall[i], &pResponse->Results[i]);
                    break;
                default:
                    break;
                }
            }
            else if (pMethodId->IdentifierType == OpcUa_IdentifierType_String)
            {
            }
        }


#if UASERVER_SUPPORT_EVENTS
        else if (pRequest->MethodsToCall[i].ObjectId.NamespaceIndex == g_UaProviderTest_uNamespaceIndex1
                 && pRequest->MethodsToCall[i].MethodId.NamespaceIndex == 0
                 && pRequest->MethodsToCall[i].MethodId.IdentifierType == OpcUa_IdentifierType_Numeric)
        {
            switch (pRequest->MethodsToCall[i].MethodId.Identifier.Numeric)
            {
            case OpcUaId_AcknowledgeableConditionType_Acknowledge:
            {
                UaServer_Event *pEvent = UaServer_Events_GetConditionByNodeId(g_UaProviderTest_uNamespaceIndex1,
                                         &pRequest->MethodsToCall[i].ObjectId);
                if (pEvent != OpcUa_Null)
                {
                    UaProvider_Test_CallAcknowledge(pEvent, &pRequest->MethodsToCall[i], &pResponse->Results[i]);
                }
                break;
            }
            case OpcUaId_AcknowledgeableConditionType_Confirm:
            {
                UaServer_Event *pEvent = UaServer_Events_GetConditionByNodeId(g_UaProviderTest_uNamespaceIndex1,
                                         &pRequest->MethodsToCall[i].ObjectId);
                if (pEvent != OpcUa_Null)
                {
                    UaProvider_Test_CallConfirm(pEvent, &pRequest->MethodsToCall[i], &pResponse->Results[i]);
                }
                break;
            }
            case OpcUaId_ConditionType_AddComment:
            {
                UaServer_Event *pEvent = UaServer_Events_GetConditionByNodeId(g_UaProviderTest_uNamespaceIndex1,
                                         &pRequest->MethodsToCall[i].ObjectId);
                if (pEvent != OpcUa_Null)
                {
                    UaProvider_Test_CallAddComment(pEvent, &pRequest->MethodsToCall[i], &pResponse->Results[i]);
                }
                break;
            }
            default:
                break;
            }
        }
    }
What is the difference between both switches? I mean, the defference between UaProvider_Test_AcknowledgeableConditionType_CallAcknowledge and UaProvider_Test_CallAcknowledge and so.
Where is suposed to be stored the message introduced when ack/confirm of alarms in UaExpert? I am not able to view it.

Thanks in advance.
Best regards.

Re: Alarms & CallAsync

Posted: 06 Aug 2014, 15:37
by Support Team
Hello,

When calling an UA method it is allowed to use the NodeId of the Method node that is defined at the instance or the NodeId of the Method node that is defined at the ObjectType. Especially the Methods that are defined for Alarms are called using the NodeId of the Method node that is defined at the type.

For that reason the switch

Code: Select all

for (i = 0; i < pRequest->NoOfMethodsToCall; i++)
{
    if (pRequest->MethodsToCall[i].MethodId.NamespaceIndex == g_UaProviderTest_uNamespaceIndex1)
    {
        //..
    }
    else if (pRequest->MethodsToCall[i].ObjectId.NamespaceIndex == g_UaProviderTest_uNamespaceIndex1
             && pRequest->MethodsToCall[i].MethodId.NamespaceIndex == 0
             && pRequest->MethodsToCall[i].MethodId.IdentifierType == OpcUa_IdentifierType_Numeric)
    {
        //..
    }
}
is auto-generated.

The function

Code: Select all

UaProvider_Test_CallAcknowledge(pEvent, &pRequest->MethodsToCall[i], &pResponse->Results[i]);
of the second switch is a default implementation for the Acknowledge UA Method.

The functions of the first switch like

Code: Select all

UaProvider_Test_AcknowledgeableConditionType_CallAcknowledge(a_pCallContext, &pRequest->MethodsToCall[i], &pResponse->Results[i]);
are extracting the method arguments from the request and the response and call funtions that the user has to implement. E.g. for the Acknowledge Method the implementation should be similar to the implementation of the UaProvider_Test_CallAcknowledge function of the second switch.

Best regards
Support Team

Re: Alarms & CallAsync

Posted: 07 Aug 2014, 13:12
by perezjo
Thanks for the explanation.
One last question regarding to this issue. This piece of code automatically generated in UaProvider_Test_CallAcknowledge

Code: Select all

value.Datatype = OpcUaType_LocalizedText;
            value.Value.LocalizedText = (OpcUa_LocalizedText*)OpcUa_Alloc(sizeof(OpcUa_LocalizedText));
            OpcUa_LocalizedText_Initialize(value.Value.LocalizedText);
            OpcUa_LocalizedText_Clone(a_pRequest->InputArguments[1].Value.LocalizedText, value.Value.LocalizedText);
            UaServer_Events_SetEventField(a_pEvent, ConditionTypeField_Comment, &value);
            OpcUa_Variant_Clear(&value);
should save the comment inserted when acked/confirmed an alarm with UaExpert, shouldn't it? I'm trying to see this message in Alarm or DA tab and I can't. Where is this comment stored?
Many thanks for your help.
Regards