Conditions in DP Function config
Search
-
ilyas_ahmed
- Posts: 19
- Joined: Wed Sep 06, 2017 7:39 am
Conditions in DP Function config
Hi,
In one case I need some conditions as DP Functions config,
e.g
IF (p1 = 1 AND p2 =2)
return 3;
ELSE
return 4;
I can use dpSet() in my CTRL library to set the required data point element , but I want to define the _dp_fct in the master data point so that its applicable for the instances.
The Help file says that:
If you call a function of a CTRL library ( /libs) in the "Function" text field you can use the return value of the function for the calculation.
Do I need program these conditions in the CTRL function can call this function in the _dp_fct config?
How to call a CTRL function in _dp_fct function.?
Or there is a better way of implementing it?.
I hope I am able to explain my problem. Appreciate help and support.
thanks.
In one case I need some conditions as DP Functions config,
e.g
IF (p1 = 1 AND p2 =2)
return 3;
ELSE
return 4;
I can use dpSet() in my CTRL library to set the required data point element , but I want to define the _dp_fct in the master data point so that its applicable for the instances.
The Help file says that:
If you call a function of a CTRL library ( /libs) in the "Function" text field you can use the return value of the function for the calculation.
Do I need program these conditions in the CTRL function can call this function in the _dp_fct config?
How to call a CTRL function in _dp_fct function.?
Or there is a better way of implementing it?.
I hope I am able to explain my problem. Appreciate help and support.
thanks.
Re: Conditions in DP Function config
This one should be easy and there are two solutions. First of all, the dp function is ..... standard control code ! So anything possible in a script can be entered here.
Solution a:
Type the formula: ( (p1==1) && (p2==2) ? 3 : 4
Solution b:
1) Implement a control library called 'myfunctions.ctl'
2) Add to confg file or config.level
[event]
LoadCtrlLibs="myfunctions.ctl'
3) Library holds:
4) In your dp function enter 'MyFunction(p1,p2)'
5) Make sure to restart the Event manager when you add a library in config or config.level
This should do it. Good luck
Frenk Mulder
Share the fun
Solution a:
Type the formula: ( (p1==1) && (p2==2) ? 3 : 4
Solution b:
1) Implement a control library called 'myfunctions.ctl'
2) Add to confg file or config.level
[event]
LoadCtrlLibs="myfunctions.ctl'
3) Library holds:
Code: Select all
int MyFunction( int p1, int p2 )
{
if( (p1==1) && (p2==2))
{
return 3;
}
else
return 4;
}5) Make sure to restart the Event manager when you add a library in config or config.level
This should do it. Good luck
Frenk Mulder
Share the fun
-
ilyas_ahmed
- Posts: 19
- Joined: Wed Sep 06, 2017 7:39 am
Re: Conditions in DP Function config
Hi Frenk,
thanks for that, I have tried the second method by ctl library.
I am getting an error
Stacktrace:
1: work(anytype p1 = TRUE, anytype p2 = FALSE) at DpFunction: System1:F3_1.state.fault_int:_dp_fct:1
WCCILevent (0), 2018.03.16 18:31:03.967, CTRL, SEVERE, 72, Function not defined, DpFunction: System1:F3_1.state.display:_dp_fct Line: 1, display
'display' is my function name , and the name of my ctrl library as well and i have added it in config and also restarted the event anager,
any thought?
Best Regard,
thanks for that, I have tried the second method by ctl library.
I am getting an error
Stacktrace:
1: work(anytype p1 = TRUE, anytype p2 = FALSE) at DpFunction: System1:F3_1.state.fault_int:_dp_fct:1
WCCILevent (0), 2018.03.16 18:31:03.967, CTRL, SEVERE, 72, Function not defined, DpFunction: System1:F3_1.state.display:_dp_fct Line: 1, display
'display' is my function name , and the name of my ctrl library as well and i have added it in config and also restarted the event anager,
any thought?
Best Regard,
Re: Conditions in DP Function config
I'm pretty sure that your control library is not being loaded. There's either a syntax failure in your script library or your config file is wrong
Please verify that your config file looks something like this:
* Load your control library in UI also and make sure the syntax is ok
* You can also start the Event manager with '-dbg 2' and see what it is loading.
Good luck
share the fun
Frenk Mulder
Please verify that your config file looks something like this:
Code: Select all
[event]
LoadCtrlLibs = "rsn_SwitchDiag.ctl"
* You can also start the Event manager with '-dbg 2' and see what it is loading.
Good luck
share the fun
Frenk Mulder
-
ilyas_ahmed
- Posts: 19
- Joined: Wed Sep 06, 2017 7:39 am
Re: Conditions in DP Function config
Hi Frenk,
All Good , thanks for your support, Actually I was loading my new library "display.ctl" in 'config.level' under [ui] and [ctrl] and event maanger couldnt load it, when i loaded under [event] and restarted the event manager it was laoded and i got my dp_fct working.
big thanks for ur support
cheers
ilyas.
All Good , thanks for your support, Actually I was loading my new library "display.ctl" in 'config.level' under [ui] and [ctrl] and event maanger couldnt load it, when i loaded under [event] and restarted the event manager it was laoded and i got my dp_fct working.
big thanks for ur support
cheers
ilyas.
-
AMRPatricio
- Posts: 61
- Joined: Mon Dec 12, 2016 4:43 pm
Re: Conditions in DP Function config
Hi All,
any way to use delays within the dp function?Assuming I do not want to use a control library...
Best regards,
Antonio Patricio
any way to use delays within the dp function?Assuming I do not want to use a control library...
Best regards,
Antonio Patricio
Re: Conditions in DP Function config
Why do you want to use a delay() in a datapoint function?
Normally a datapoint function is used to immediately react on changes of other dp elements.
Best Regards
Leopold Knipp
Senior Support Specialist
Normally a datapoint function is used to immediately react on changes of other dp elements.
Best Regards
Leopold Knipp
Senior Support Specialist
-
AMRPatricio
- Posts: 61
- Joined: Mon Dec 12, 2016 4:43 pm
Re: Conditions in DP Function config
Hi Leopold,
I think I described the situation wrongly on my last post.
Imagine that I want to check if 2 dp elements are "true" for a certain amount of time. If yes the "third element" is set up to true. If the conditions are not meet during the certain amount of time the "third element" is set up to false.
Thanks in advance,
Antonio
I think I described the situation wrongly on my last post.
Imagine that I want to check if 2 dp elements are "true" for a certain amount of time. If yes the "third element" is set up to true. If the conditions are not meet during the certain amount of time the "third element" is set up to false.
Thanks in advance,
Antonio
Re: Conditions in DP Function config
Careful about delays and timers and such in DPFunctions, they are evaluated by the Event Manager. You don't want to delay, in any way, the event manager from doing work. Complex time things and conditions which are not always "on" should be done in CTRL Manager so you have your own thread and control over these things yourself.
Consider building a little OOP class for this. It would be more work up front, but easy to use later on.
Consider building a little OOP class for this. It would be more work up front, but easy to use later on.
Re: Conditions in DP Function config
I don't fully agree that making a class makes this any easier. This simple 'wait' can just as easily be done using normal scripting
( a big chunk of the scada world has never programmed in C# or C++)
In general the dp function wont allow you any waiting functions like dpGet(), dpQuery() and such. I'd guess that the dp functions were probably never built or meant for that. The were built to do a simple 'standard' ax+b formule.
"if all you have is a hammer, then everything looks like a nail"
Consider the following more important argument.
- When your dp function becomes more complex then you'll want to put your script code in a library
- But changing your library means restarting the Event manager !!! (which is not the best idea)
Still You could achieve your 'timer' in a dp function as follows:
( but only do this when you have a couple of timers)
- make a dp that changes every second
- include this dp in your function so that your dp function now gets triggered every second
- Then implement your function just like you would do in a PLC (using a state machine)
My advise:
dp function -> for very(!) simple formulas
scripts -> for complex functions or functions that require threads or waits
good luck
share the fun
Frenk Mulder
( a big chunk of the scada world has never programmed in C# or C++)
In general the dp function wont allow you any waiting functions like dpGet(), dpQuery() and such. I'd guess that the dp functions were probably never built or meant for that. The were built to do a simple 'standard' ax+b formule.
"if all you have is a hammer, then everything looks like a nail"
Consider the following more important argument.
- When your dp function becomes more complex then you'll want to put your script code in a library
- But changing your library means restarting the Event manager !!! (which is not the best idea)
Still You could achieve your 'timer' in a dp function as follows:
( but only do this when you have a couple of timers)
- make a dp that changes every second
- include this dp in your function so that your dp function now gets triggered every second
- Then implement your function just like you would do in a PLC (using a state machine)
My advise:
dp function -> for very(!) simple formulas
scripts -> for complex functions or functions that require threads or waits
good luck
share the fun
Frenk Mulder