A&C / DA: read items after an Event

Questions regarding the use of the C++ SDK for Server or Client development or integration into customer products ...

Moderator: uasdkcpp

Post Reply
kk1986
Full Member
Full Member
Posts: 5
Joined: 04 Sep 2015, 10:33

A&C / DA: read items after an Event

Post by kk1986 »

Hi,

i use the c++ SDK an work with the Client lesson06 Code.
My Client can connect to the Server and recognize Events and show items from the Alarms&Conditions Namespace (Timestamp, message, sourceName, severity, ... )
After an Event (for example the temperature is over the max.Limit of 40 centigrade) i will use the read() function to get the other items/values from the DA Namespace.
But that doesnt work -> see my code :

Code: Select all

void SampleSubscription::newEvents(
    OpcUa_UInt32                clientSubscriptionHandle, //!< [in] Client defined handle of the affected subscription
    UaEventFieldLists&          eventFieldList)           //!< [in] List of event notifications sent by the server
{
    OpcUa_UInt32 i = 0;
    printf("-- Event newEvents -----------------------------------------\n");
    printf("clientSubscriptionHandle %d \n", clientSubscriptionHandle);
    for ( i=0; i<eventFieldList.length(); i++ )
    {
        UaVariant message    = eventFieldList[i].EventFields[0];
        UaVariant sourceName = eventFieldList[i].EventFields[1];
        UaVariant severity   = eventFieldList[i].EventFields[2];
        UaVariant time		 = eventFieldList[i].EventFields[3];
		UaVariant ConditionName	= eventFieldList[i].EventFields[4];
		printf("Event = [%d] \n Message = %s \n SourceName = %s \n Severity = %s \n Time = %s \n ConditionName = %s \n",
            i,
            message.toString().toUtf8(),
            sourceName.toString().toUtf8(),
            severity.toString().toUtf8(),
			time.toString().toUtf8(),
			ConditionName.toString().toUtf8());
			
	//read values from the DA Namespace

		UaStatus status;
		SampleClient* pMyClient = new SampleClient();
		status = pMyClient->read();
Thanks for you help,
Kadir (Germany)

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re: A&C / DA: read items after an Event

Post by Support Team »

Hi Kadir,

The simple answer seems to be that you create a new SampleClient instance in the event callback for the read but you do not call connect on the new SampleClient object before you call Read. Therefore Read fails since your new SampleClient instance is not connected.

But this behaviour has several other issues too:
(1) Why do you want to create a second connection to the server to execute a read if you have already a connection?
(2) It is bad behaviour to execute calls to the server in a callback from the SDK

Best Regards,
Unified Automation Support Team

kk1986
Full Member
Full Member
Posts: 5
Joined: 04 Sep 2015, 10:33

Re: A&C / DA: read items after an Event

Post by kk1986 »

Hi Support-Team,

thanks for the answer,

After the Event how can i jump to the read() funkction (in sampleclient.cpp) with the existing connection ?

Thanks for your help.
Kadir

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re: A&C / DA: read items after an Event

Post by Support Team »

Hi,

You should start a worker thread to execute the read.

Best Regards,
Unified Automation Support Team

Post Reply