How to know which data point trigger the call back function in dpConnect logic

Find and share HowTos to various installations / configurations!
16 posts • Page 1 of 2
maoyi8212
Posts:9
Joined: Tue Feb 21, 2017 3:47 am

How to know which data point trigger the call back function in dpConnect logic

Post by maoyi8212 »

Now I am testing some panel script using dpConnect interface and the code structure is like following

Code: Select all

main()
{

  dpConnect("workCB", "System1:ExampleDP_SumAlert.:_original.._value",
                                   "System1:ExampleDP_SumAlert1.:_original.._value";
}

void workCB(string dpe1, ulong valueFromSimulator,
                    string dpe2, ulong valueFromSimulator2)
{
XXXXXX
}
For my understanding, no matter the value of ExampleDP_SumAlert or ExampleDP_SumAlert1 changes, it will trigger the callback function of workCB(). My question is in the logic of function workCB, is it possible to know which value change(ExampleDP_SumAlert or ExampleDP_SumAlert1) trigger the call back function. If yes, how to get this information?

Gertjan van Schijndel
Posts:634
Joined: Mon Aug 02, 2010 10:37 am

Re: How to know which data point trigger the call back function in dpConnect logic

Post by Gertjan van Schijndel »

When the value has changed you could get this information by connecting also to the '_value_changed' attribute.
But when the same value is written to the data point element you still do not know which has triggered the call back function, in this it would only be possible with dpConnects on a single data point element or a dpQueryConnectSingle.

leoknipp
Posts:2928
Joined: Tue Aug 24, 2010 7:28 pm

Re: How to know which data point trigger the call back function in dpConnect logic

Post by leoknipp »

With the attribute _value_changed and the attribute _value_up you can detect if a _original.._value/_online.._value for a dp element is different to the previous one.

Current value = 2 and new value = 3 the attributes will be
_value_changed = 1
_value_up = 1

Current value = 2 and new value = 2 the attributes will be
_value_changed = 0
_value_up = 0

Current value = 2 and new value = 1 the attributes will be
_value_changed = 1
_value_up = 0

Those attribute cannot be used to detect which dp element has triggered the callback function for a dpConnect() with several dp elements.

Best Regards
Leopold Knipp
Senior Support Specialist

fmulder
Posts:330
Joined: Wed Feb 03, 2010 9:46 am

Re: How to know which data point trigger the call back function in dpConnect logic

Post by fmulder »

You could also connect to the _stime of the value. The one(s) with the newest timestamp(s) have triggered the callback.

Share the fun
Frenk Mulder

maoyi8212
Posts:9
Joined: Tue Feb 21, 2017 3:47 am

Re: How to know which data point trigger the call back function in dpConnect logic

Post by maoyi8212 »

So if I connect hundreds of data point, I should write my script like following way:

main()
{

dpConnect("workCB", "System1:ExampleDP_SumAlert1.:_original.._value",
....
"System1:ExampleDP_SumAlert100.:_original.._value",
"System1:ExampleDP_SumAlert1.:_original.._value_changed",
...
"System1:ExampleDP_SumAlert100.:_original.._value_changed");
}

void workCB(string dpe1, ulong valueFromSimulator1,
string dpe2, ulong valueFromSimulator2
...
string dep100, ulong valueFromSimulator100,
bool dep101, bool value_changed1,
...
bool dep200, bool value_changed200)
{
if(value_changed1) {
XXX
}
if(value_changed2) {
XXX
}
...
if(value_changed100) {
XXX
}
}

But actually the logic of value_changed1, value_changed2...value_changed100 is the same. I really do not want to write the same logic 100 times in a script. Is there easier way to do that? Many thanks!

maoyi8212
Posts:9
Joined: Tue Feb 21, 2017 3:47 am

Re: How to know which data point trigger the call back function in dpConnect logic

Post by maoyi8212 »

Frenk, Thank you for your suggestion and reply. So if I connect 100 of similar data point, I need to connect the _stime as well, then I need to compare 100 values of _stime to find the biggest one, After I know which timestamp is the biggest one, I should parse the name information of the data point, then do the logic I planned?

My question is that if the numbers of the data point increases, is it possible that the comparison logic spends too much time so the data point has been refreshed already?

nmnogueira
Posts:125
Joined: Thu May 05, 2011 12:59 pm

Re: How to know which data point trigger the call back function in dpConnect logic

Post by nmnogueira »

I think you should really take a look at dpQueryConnectSingle. This should be the right way to go!

fmulder
Posts:330
Joined: Wed Feb 03, 2010 9:46 am

Re: How to know which data point trigger the call back function in dpConnect logic

Post by fmulder »

Yes, Nuno is right. The scenario that you describe seems to fit a dpQueryConnectSingle()

First of all some important details:

1) a dpConnect() is always synchronized. This means that a callback function is not called before the previous one has finished executing. This also implies that your callback functions should be fast. if your callback function takes too much time then you might get the mesage '200 pending runs'. This basically means that your UI or script manager is receiving data for a callback, but your callback is not fast enough to process them.
( This rule applies to each specific callback function. If you have multiple panels, or you have multiple threads with callbacks, then they will run in parallel)
2) The scripting is better than you think. You wont easily run into a performance problem
3) The dpQueryConnectSingle() does what you need. It will only give you the modified values

If you only want to respond to new values then the dpQueryConnectSingle() is perfect. It will only send you the new values. If you need to have all values,then you should save them in the callback. Saving them could be done in some dyn_.. or could be done in a mapping (the mapping is faster in looking up date)

Hope this helps

p.s.
The Lab section will hold a document XFile 1. This document explains how the queries work

Good luck

Frenk Mulder
Share the fun !

leoknipp
Posts:2928
Joined: Tue Aug 24, 2010 7:28 pm

Re: How to know which data point trigger the call back function in dpConnect logic

Post by leoknipp »

Using a connect to the attribute _stime does not give you the information which dp element has triggered the callback function by searching for those with the newest time stamp.
In WinCC OA you can set an original value with a defined time stamp, e.g. by using dpSetTimed(). Also some of the WinCC OA drivers can use the time stamp given by the PLC.

E.g. a dpConnect for 2 dp elements

DPE1 - value 1 - time stamp 2017.04.18 08:55:00.000
DPE2 - value 2 - time stamp 2017.04.18 06:00:00.000

If now a dpSetTimed is made for DPE2 with the following information the callback function will be triggered
DPE2 - value 3 - time stamp 2017.04.18 07:00:00.000

By comparing the _stime you will find DPE1 as the newer one but this one has not triggered the callback function.

Best Regards
Leopold Knipp
Senior Support Specialist

fmulder
Posts:330
Joined: Wed Feb 03, 2010 9:46 am

Re: How to know which data point trigger the call back function in dpConnect logic

Post by fmulder »

Leo is right, but the dpSetTimed() is quite rare. I've hardly ever used or needed it.
In general, looking at the _stime will work, but using the dpQueryConnectSingle() in this case, sounds like a better idea !

Share the fun
Frenk Mulder

16 posts • Page 1 of 2