I've read CoDeSys can work with pointers to functions. Unfortunately i can't figure it out well. I'll try to illustrate what i need.
I have functions - fun1 and fun2
and i want to call fun2 through the fun1 by the pointer to fun2. somehow like below:
fun1( ADR(fun2) );
The question is how to declare the parameter of fun1?
("pointer to function" doesn't work - i've tried )
a pointer to a function is not possible and makes also no sense. A function is not instantiated, so it is not available in the memory. If a functions is called it is on the stack and will be removed after the call. If you would like to do such operations (and I would propose not to do that) use function blocks.
The call is what you already posted:
fun1(i_pfbMyFunctionBlock := ADR(fbMyInstance));
The usage inside the function is:
i_pfbMyFunctionBlock^(i_input1 := xxx, i_input2:= xxx);
Hope this was helpful!
Thanks for respond.
I create some object. This object has its own logic but it needs to give capability to react on some events (inside object) from outside. i know, CoDeSys has similar system to handle services in IEC.
hEvent := EventOpen(EVT_StopDone, CMPID_CmpApp, Result);
Result := EventRegisterCallbackFunction(hEvent, ADR(myFunction));
Where myFunction is the FUNCTION which is called if EVT_StopDone happens.
and i need something the same.
I'll think about different ways... inheritance and addition maybe...
Has your problem been resolved?
See the help of CODESYS regarding Pointers:
"This pointers can be passed to external libraries, but there is no possibility to call a function pointer within an application in the programming system!"
A suggestion could be to use Function Blocks and call the methods (possibly through the interface of the function block), but I'm not sure if this fits with your application.
Can you give me an example for this:
so how can i declare a pointer to function in my library.
and how can i pass a pointer to function to my external library?
Log in to post a comment.