As the documentation of dpConnect([class object,] string|function_ptr work, [bool answer,] string dp1 [, string dp2 ...] | dyn_string dp_list) states, the work function is called when dp1 | dp2... are changed.
How do we know which one of the connected datapoint elements triggered the work function?
As you already noticed, the callback you register with
dpConnectgets called when either of the connected datapoint values changes.There are multiple possible solutions to your scenario where the most common are the two following ones:
If you are just interested in getting the callback when either of the specified datapoint element's value changes and you do not need the values from all connected datapoint elements within your callback, you can simply connect the callback separately for each datapoint element of interest.
Instead of writing...
...you can can write the following:
Connect to the source time (
_online.._stime) of the datapoint elements in addition to their values. In this way you not only retrieve the values but also the timestamp of their last change. The following example should guide you in the right direction:(I have specified
_online.._valueexplicitly in the below example to clarify that both attributes (_valueand_stime) are getting connected. Of course specifying_online.._valueis not required but it increased the readability.)