Conceptual question on event-triggered data for objects

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

Moderator: uasdkcpp

Post Reply
Felix Meßmer
Sr. Member
Sr. Member
Posts: 12
Joined: 05 Jul 2011, 15:37

Conceptual question on event-triggered data for objects

Post by Felix Meßmer »

Hello Support-Team,

I have a conceptual question or rather I am not absolutely clear about the concept behind server_gettingstarted/lesson03:

I am writing my own nodemanager with application specific object types.
Therefore I use server_gettingstarted/lesson03 as a template/inspiration.

My objects (analog to the controllerobjects) are of type UaObjectTypeSimple and consist of some variables of type BaseDataVariableType. I don't have sub-classes.

So far, I implemented the nodemanager and the communication interface similar to the tutorial.
The difference between the tutorial and my application is that the data is not polled but is event triggered.
In the tutorial we have the controller objects (furnaces and airconditioners) where the new data is polled from within the bacommunicationinterface's run() function by calling the simulate() function of each controller in the m_arrayDevices array.
In my case I also implemented a class that provides the data that I want to write to the variables of the objects. But in this class I have a callback function that is called by an external event. Whenever this callback is called (not necessarily in a cyclic way), I want to write the new data to my objects.


I understand that I can set values of a variable using the setValue() function. I also know that I can get the desired node (i.e. object/variable) through it's description/nodeId by querying the nodemanager's getNode().

1. How can I best hand over my data to the variables of the objects?
2. Does it mean that I need a pointer to the nodemanager in every instance of my data providing class to set the values?
3. As it is said in the tutorial, readValue() and writeValue() are only overwritten since the data comes from polling. Thus I don't need to overwrite these functions, right?
4. What purpose does the BaUserData class have in my case? Do I need it?


I hope these questions are not to confusing and the idea behind my scenario is clear.



Thank you very much,
Felix Meßmer

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

Re:Conceptual question on event-triggered data for objects

Post by Support Team »

If you have an exception based data source you'll have to implement your own IOManager.
In IOManager::beginStartMonitoring() you get an IOVariableCallback for the item. This is where you will put together all information you need to start sampling for the item i.e. tell your data source you want to receive update events.
You need some logical connection between the IOVariableCallback and the updates you receive from your data source. That means whenever you get an event from the data source you need access to the IOVariableCallback that was passed to beginStartMonitoring.
Whenever you get new data you just call IOVariableCallback::dataChange and that's it.

You'll still need some user data that identifies the item when adding the item to the sampling if there is such a mechanism. If you just receive every value change you need that information to filter out which changes you ignore and to find the connection to the IOVariableCallback as mentioned above

Best regards,
Unified Automation Support Team
Best regards
Unified Automation Support Team

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

Re:Conceptual question on event-triggered data for objects

Post by Support Team »

Hello Felix,

We may be able to provide you some more details and hints or sample code snipets regarding your question. But ween need more input from you.

(1) Event based data reporting
Are all value changes for all variables reported always or do you need to activate this reporting?

(2) Read
Is it easy to access the variable values on request if not all changes are reported always?

(3) Write
How is write handled for your variables?
Can you do single variable writes or does your internal API allow/require to write a list of variables if the OPC UA client writes a list?


Best regards,
Unified Automation Support Team
Best regards
Unified Automation Support Team

Felix Meßmer
Sr. Member
Sr. Member
Posts: 12
Joined: 05 Jul 2011, 15:37

Re:Conceptual question on event-triggered data for objects

Post by Felix Meßmer »

Hello SupportTeam,

I solved my problem by providing a pointer to the node manager in the class that implements the callback function for the event.
Whenever this callback is called by the event, it also receives paramters that contain the new data for the variables of the object.
These parameters contain the new values for all variables of the object.
Thus, I just extract the various data that I am interested in from the paramters and map it to the respective variable.
This mapping is fixed, i.e. the same data always goes into the same variable.
Therefore, I use the pointer to the node manager to get the NodeId of the respective variables, cast the NodeId to UaVariable and use setValue() to write the data to the variable.

This works fine and is absolutely satisfying at the moment.

In the future, we might want to use a different approach that keeps the class implementing the callback independend from any OPC-UA code.

As to your questions:
(1) Whenever the event triggers the callback function, all variables of an object get new values. The values of the variables are only changed through this callback. In any other case the values of the variable do not change.

(2) New data for the variables can not be accessed via request but only through the callback function.

(3) I do not need to implement write access to the variables from the client. Only the server writes new data, clients "listen".


Functionality that I want to add next will be to start/stop taking over new data from the callback to the variables using a flag that can be set by the client. Also, I will implement monitoring, i.e. clients subscribe to objects in whose data changes they are interested in.



I hope this clearifies it a little more.

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

Re:Conceptual question on event-triggered data for objects

Post by Support Team »

Hello Felix,

In your situation where the data updates are always delivered through event based mechanisms and write is not needed, you can benefit most from the existing functionality provided by the SDK. There is nothing wrong with your described implementation.

The only thing you can optimize is the access to the variables. It sounds like your objects are well defined. In this case you can implement a class representing the object with all the variable nodes as members. You can provide setter functions to update the data of the object. Inside the setter functions you can access the variables directly. This eliminates the requirement to search for every variable node in every callback with the NodeId. You must only get the object node from the NodeManager in the callback function. Maybe you can even use the UaModeler to create such a class.

Lesson 3 in the server tutorial is for systems that do not provide event based data updates but require data polling. Lesson 3 is the step to connect the variable nodes with real data. The way to access the data depends on the type of interface to the underlying system. The polling example in Lesson 3 is the one extreme. The pure event based capability you have implemented is the other extreme. There are different variations possible in between.

Best regards,
Unified Automation Support Team
Best regards
Unified Automation Support Team

Post Reply