<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to POINTER TO function</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/95b3def5a2/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/95b3def5a2/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/95b3def5a2/</id><updated>2020-02-27T13:56:13.615000Z</updated><subtitle>Recent posts to POINTER TO function</subtitle><entry><title>POINTER TO function</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/95b3def5a2/?limit=25#6b19" rel="alternate"/><published>2020-02-27T13:56:13.615000Z</published><updated>2020-02-27T13:56:13.615000Z</updated><author><name>bacha.damin</name><uri>https://forge.codesys.com/u/bacha-damin/</uri></author><id>https://forge.codesys.com8115428ee2dcd4afc3ca5d552fd107b04ee7c3e4</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Can you give me an example for this:&lt;br/&gt;
so how can i declare a pointer to function in my library.&lt;br/&gt;
and how can i pass a pointer to function to my external library?&lt;/p&gt;
&lt;p&gt;thank you &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>POINTER TO function</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/95b3def5a2/?limit=25#e55b" rel="alternate"/><published>2020-02-27T13:56:12.969000Z</published><updated>2020-02-27T13:56:12.969000Z</updated><author><name>timvh</name><uri>https://forge.codesys.com/u/timvh/</uri></author><id>https://forge.codesys.comb8c55fd8913552c6a23c211b3de670584d96bbee</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;See the help of CODESYS regarding Pointers:&lt;br/&gt;
"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!"&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>POINTER TO function</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/95b3def5a2/?limit=25#4e54" rel="alternate"/><published>2020-02-27T13:56:12.754000Z</published><updated>2020-02-27T13:56:12.754000Z</updated><author><name>yue-qi-qi</name><uri>https://forge.codesys.com/u/yue-qi-qi/</uri></author><id>https://forge.codesys.comaef85784dc1c01150834889929bb5d5afcb17f37</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi Mouse:&lt;br/&gt;
      Has your problem been resolved?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>POINTER TO function</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/95b3def5a2/?limit=25#7f9b" rel="alternate"/><published>2020-02-27T13:56:12.523000Z</published><updated>2020-02-27T13:56:12.523000Z</updated><author><name>Mouse</name><uri>https://forge.codesys.com/u/mouse/</uri></author><id>https://forge.codesys.comc5d86fb8eff0d2941ba3c04b680d74cbcbe80ae1</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thanks for respond.&lt;/p&gt;
&lt;p&gt;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. &lt;br/&gt;
for instance:&lt;br/&gt;
hEvent := EventOpen(EVT_StopDone, CMPID_CmpApp, Result);&lt;br/&gt;
Result := EventRegisterCallbackFunction(hEvent, ADR(myFunction));&lt;/p&gt;
&lt;p&gt;Where myFunction is the FUNCTION which is called if EVT_StopDone happens.&lt;/p&gt;
&lt;p&gt;and i need something the same.&lt;/p&gt;
&lt;p&gt;Inst1:myObject;&lt;/p&gt;
&lt;p&gt;Inst1.WhatDoYouWantFromMe(IfSomethingHappensCallPlease, adr(myFunction));&lt;/p&gt;
&lt;p&gt;no possible?  &lt;/p&gt;
&lt;p&gt;I'll think about different ways... inheritance and addition maybe...&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>POINTER TO function</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/95b3def5a2/?limit=25#8c8c" rel="alternate"/><published>2020-02-27T13:56:12.278000Z</published><updated>2020-02-27T13:56:12.278000Z</updated><author><name>singleton</name><uri>https://forge.codesys.com/u/singleton/</uri></author><id>https://forge.codesys.com8071c7848edde5f7efe4939eca7986b040926de0</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello Mouse,&lt;br/&gt;
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.&lt;/p&gt;
&lt;p&gt;The call is what you already posted:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;fun1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i_pfbMyFunctionBlock&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ADR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fbMyInstance&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The usage inside the function is:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;i_pfbMyFunctionBlock&lt;/span&gt;&lt;span class="o"&gt;^(&lt;/span&gt;&lt;span class="nt"&gt;i_input1&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;xxx&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;i_input2&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;xxx&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Hope this was helpful!&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>POINTER TO function</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/95b3def5a2/?limit=25#3d44" rel="alternate"/><published>2020-02-27T13:56:11.568000Z</published><updated>2020-02-27T13:56:11.568000Z</updated><author><name>Mouse</name><uri>https://forge.codesys.com/u/mouse/</uri></author><id>https://forge.codesys.com888a9af276a86e3024a1d7968d4c6958e78657f4</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello!&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;I have functions - fun1 and fun2&lt;br/&gt;
and i want to call fun2 through the fun1 by the pointer to fun2. somehow like below:&lt;/p&gt;
&lt;p&gt;PLC_PRG:&lt;br/&gt;
fun1( ADR(fun2) );&lt;/p&gt;
&lt;p&gt;The question is how to declare the parameter of fun1?&lt;/p&gt;
&lt;p&gt;("pointer to function" doesn't work - i've tried  )&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>