<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Dynamic function call</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/f5514026d8/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/f5514026d8/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/f5514026d8/</id><updated>2020-02-27T21:24:26.687000Z</updated><subtitle>Recent posts to Dynamic function call</subtitle><entry><title>Dynamic function call</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/f5514026d8/?limit=25#117f" rel="alternate"/><published>2020-02-27T21:24:26.687000Z</published><updated>2020-02-27T21:24:26.687000Z</updated><author><name>ljean</name><uri>https://forge.codesys.com/u/ljean/</uri></author><id>https://forge.codesys.com859b39368101fe7d4f41a699436ff521ee38a39c</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Your callback must return 0. Just have a look to the attached program which is working for me with PlcWinNt&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="https://forum.codesys.com//download/file.php?id=93" rel="nofollow"&gt;testwd.pro &lt;span&gt;&lt;span&gt;[25.96 KiB]&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Dynamic function call</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/f5514026d8/?limit=25#79b2" rel="alternate"/><published>2020-02-27T21:24:25.216000Z</published><updated>2020-02-27T21:24:25.216000Z</updated><author><name>Avgur</name><uri>https://forge.codesys.com/u/avgur/</uri></author><id>https://forge.codesys.com9f750ac9ab77ee8881fc95b06dc867551646e7f5</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;hi! &lt;/p&gt;
&lt;p&gt;I have the similar question. I try to use System event EXCPT_WATCHDOG in Task configuration as follows:&lt;/p&gt;
&lt;p&gt;1) watchdog in main program PLC_PRG is enabled and set to 30 sec;&lt;/p&gt;
&lt;p&gt;2) main program represents endless loop&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;WHILE&lt;/span&gt; &lt;span class="nv"&gt;TRUE&lt;/span&gt; &lt;span class="k"&gt;DO&lt;/span&gt;
&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_WHILE&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;3) System event EXCPT_WATCHDOG is set, called POU have only one operator ```&lt;/p&gt;
&lt;p&gt;SysResetPlcProgram(0);&lt;/p&gt;
&lt;p&gt;``` from PLC control system library SysLibPlcCtrl.lib (I want to reset my program when watchdog triggered)&lt;/p&gt;
&lt;p&gt;It seems to be right but doesn't work! Software watchdog of IEC-task never  triggers and I can't reset my program  at the same time hardware watchdog of ThinkIO always triggers and indicating PLC hang-up.&lt;/p&gt;
&lt;p&gt;Please explain me how I should reset program or completely PLC?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Dynamic function call</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/f5514026d8/?limit=25#10f3" rel="alternate"/><published>2020-02-27T21:24:23.700000Z</published><updated>2020-02-27T21:24:23.700000Z</updated><author><name>RolandWagner</name><uri>https://forge.codesys.com/u/rowa/</uri></author><id>https://forge.codesys.comfeeccb2940c976f6dc3dbb4928f1882f2e49a29b</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;The direct call of function blocks e.g. via a string variable with the name of the FB can be realised by the means of some detours.&lt;/p&gt;
&lt;p&gt;What you need in order to do so is the &lt;strong&gt;CAA_Callback.lib&lt;/strong&gt;. This is an external library that provides the function &lt;strong&gt;CB_CallFunctionByIndex&lt;/strong&gt; .&lt;/p&gt;
&lt;p&gt;The call could e.g. look like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;dwValue&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;CB_CallFunctionByIndex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;INDEXOF&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CallbackFBI1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;dwParam1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dwParam2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dwParam3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Please find the sepcification of the CAA_Callback.lib attached (unfortunately German only).&lt;br/&gt;
It is important that this function can &lt;span style="color: underline;"&gt;only&lt;/span&gt; call another function that fulfils the following requests:&lt;/p&gt;
&lt;p&gt;A possible prototype thus looks like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;FUNCTION&lt;/span&gt; &lt;span class="nt"&gt;CallbackFBI1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;DWORD&lt;/span&gt;
&lt;span class="nt"&gt;VAR_INPUT&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;Param1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;DWORD&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;Param2&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;DWORD&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="nt"&gt;Param3&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;DWORD&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Please find a CoDeSys project with the name &lt;strong&gt;FB-Pointer-Liste.pro&lt;/strong&gt; attached. There the following approach is considered:&lt;br/&gt;
If the CAA_Callback.lib is not available you could probably write your own c library. It should have something like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;unsigned&lt;/span&gt; &lt;span class="nv"&gt;long&lt;/span&gt; &lt;span class="nv"&gt;CB_CallFunctionByIndex&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;
                              &lt;span class="nv"&gt;short&lt;/span&gt; &lt;span class="nv"&gt;sPOUIndex&lt;/span&gt;,
                              &lt;span class="nv"&gt;unsigned&lt;/span&gt; &lt;span class="nv"&gt;long&lt;/span&gt; &lt;span class="nv"&gt;ulParam1&lt;/span&gt;,
                              &lt;span class="nv"&gt;unsigned&lt;/span&gt; &lt;span class="nv"&gt;long&lt;/span&gt; &lt;span class="nv"&gt;ulParam2&lt;/span&gt;,
                              &lt;span class="nv"&gt;unsigned&lt;/span&gt; &lt;span class="nv"&gt;long&lt;/span&gt; &lt;span class="nv"&gt;ulParam3&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
{
   &lt;span class="nv"&gt;void&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nv"&gt;pPlcFunctions&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
   &lt;span class="nv"&gt;unsigned&lt;/span&gt; &lt;span class="nv"&gt;long&lt;/span&gt; &lt;span class="nv"&gt;ulValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
   &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;sPOUIndex&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
   {
      &lt;span class="nv"&gt;pPlcFunctions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;RtsGetIecFctPointer&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;sPOUIndex&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;RtsProgramLoaded&lt;/span&gt;&lt;span class="ss"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nv"&gt;pPlcFunctions&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;
      {
         &lt;span class="nv"&gt;ulValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;SysCallWith3Param&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;
                     &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;PFCALLBACK&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;pPlcFunctions&lt;/span&gt;,
                     &lt;span class="nv"&gt;ulParam1&lt;/span&gt;,
                     &lt;span class="nv"&gt;ulParam2&lt;/span&gt;,
                     &lt;span class="nv"&gt;ulParam3&lt;/span&gt;
                  &lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
      }
   }
   &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;ulValue&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
}
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;a class="" href="https://forum.codesys.com//download/file.php?id=62" rel="nofollow"&gt;CAA_Callback.pdf &lt;span&gt;&lt;span&gt;[45.66 KiB]&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="https://forum.codesys.com//download/file.php?id=61" rel="nofollow"&gt;CAA_Callback.zip &lt;span&gt;&lt;span&gt;[3.92 KiB]&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="https://forum.codesys.com//download/file.php?id=60" rel="nofollow"&gt;FB Pointer Liste.zip &lt;span&gt;&lt;span&gt;[5.4 KiB]&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Dynamic function call</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/f5514026d8/?limit=25#497c" rel="alternate"/><published>2020-02-27T21:24:19.498000Z</published><updated>2020-02-27T21:24:19.498000Z</updated><author><name>RikeR</name><uri>https://forge.codesys.com/u/riker/</uri></author><id>https://forge.codesys.com47d0f9d9dba835e850f3d2ee337897b72dd7a668</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hey guys,&lt;/p&gt;
&lt;p&gt;Let's say I have some logic which will return a value. Based on the outcome I would like to run a certain program/function block. The values of this logic can vary from say 0 to 100. For example value = 50, run Program 50.&lt;/p&gt;
&lt;p&gt;I've searched the manual and found the ADRINST function, which in my case can come in pretty handy. But the documentation on this function is limited:&lt;/p&gt;
&lt;p&gt;ADRINST&lt;/p&gt;
&lt;p&gt;Adress function, not prescribed by the standard IEC61131-3.&lt;/p&gt;
&lt;p&gt;ADRINST within a function block instance returns the address of the instance in a DWORD. This&lt;/p&gt;
&lt;p&gt;address then can be sent to functions and be treated there as a pointer or it can be assigned to a&lt;/p&gt;
&lt;p&gt;pointer within the project.&lt;/p&gt;
&lt;p&gt;Is there a beter way to handle the problem discribed above, or is there a way to use the pointer returned by the ADRINST function and call a function?&lt;/p&gt;
&lt;p&gt;Greeting,&lt;/p&gt;
&lt;p&gt;RikeR&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>