CODESYS - the IEC 61131-3 automation software

POINTER TO function
Page 1 of 1

Author:  Mouse [ Mon Dec 26, 2011 11:46 am ]
Post subject:  POINTER TO function


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 :) )

Author:  singleton [ Tue Dec 27, 2011 4:36 pm ]
Post subject:  Re: POINTER TO function

Hello Mouse,
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!

Author:  Mouse [ Thu Dec 29, 2011 7:24 am ]
Post subject:  Re: POINTER TO function

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.
for instance:
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.


Inst1.WhatDoYouWantFromMe(IfSomethingHappensCallPlease, adr(myFunction));

no possible? :(

I'll think about different ways... inheritance and addition maybe...

Author:  yue_qi_qi [ Mon Feb 18, 2013 8:59 am ]
Post subject:  Re: POINTER TO function

Hi Mouse:
Has your problem been resolved?

Author:  TimvH [ Fri Feb 22, 2013 12:34 pm ]
Post subject:  Re: POINTER TO function

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.

Author:  bacha.damin [ Fri Mar 31, 2017 11:33 am ]
Post subject:  Re: POINTER TO function


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?

thank you :)

Page 1 of 1 All times are UTC+01:00
Powered by phpBB® Forum Software © phpBB Limited