CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Fri Dec 06, 2019 9:22 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
 Post subject: POINTER TO function
PostPosted: Mon Dec 26, 2011 11:46 am 
Offline
User avatar

Joined: Wed Sep 07, 2011 12:52 pm
Posts: 13
Hello!

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:

PLC_PRG:
fun1( ADR(fun2) );

The question is how to declare the parameter of fun1?

("pointer to function" doesn't work - i've tried :) )


Top
   
 Post subject: Re: POINTER TO function
PostPosted: Tue Dec 27, 2011 4:36 pm 
Offline

Joined: Thu Aug 04, 2011 11:16 am
Posts: 87
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:

Code:
fun1(i_pfbMyFunctionBlock := ADR(fbMyInstance));


The usage inside the function is:
Code:
i_pfbMyFunctionBlock^(i_input1 := xxx, i_input2:= xxx);


Hope this was helpful!


Top
   
 Post subject: Re: POINTER TO function
PostPosted: Thu Dec 29, 2011 7:24 am 
Offline
User avatar

Joined: Wed Sep 07, 2011 12:52 pm
Posts: 13
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:myObject;

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

no possible? :(

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


Top
   
 Post subject: Re: POINTER TO function
PostPosted: Mon Feb 18, 2013 8:59 am 
Offline

Joined: Mon Jul 16, 2012 9:11 am
Posts: 75
Hi Mouse:
Has your problem been resolved?


Top
   
 Post subject: Re: POINTER TO function
PostPosted: Fri Feb 22, 2013 12:34 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Tue Jun 06, 2006 9:03 am
Posts: 410
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.


Top
   
 Post subject: Re: POINTER TO function
PostPosted: Fri Mar 31, 2017 11:33 am 
Offline

Joined: Tue Feb 14, 2017 9:59 am
Posts: 25
Hello,

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


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 6 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited