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.
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:
ADRINST
Adress function, not prescribed by the standard IEC61131-3.
ADRINST within a function block instance returns the address of the instance in a DWORD. This
address then can be sent to functions and be treated there as a pointer or it can be assigned to a
pointer within the project.
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?
Greeting,
RikeR
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Please find the sepcification of the CAA_Callback.lib attached (unfortunately German only).
It is important that this function can only call another function that fulfils the following requests:
A possible prototype thus looks like this:
FUNCTIONCallbackFBI1:DWORDVAR_INPUTÂ Â Param1:DWORD;Â Â Param2:DWORD;Â Â Param3:DWORD;END_VAR
Please find a CoDeSys project with the name FB-Pointer-Liste.pro attached. There the following approach is considered:
If the CAA_Callback.lib is not available you could probably write your own c library. It should have something like this:
unsignedlongCB_CallFunctionByIndex(
               shortsPOUIndex,
               unsignedlongulParam1,
               unsignedlongulParam2,
               unsignedlongulParam3)
{
  void*pPlcFunctions;
  unsignedlongulValue=0;
  if(sPOUIndex!=-1)
  {
    pPlcFunctions=RtsGetIecFctPointer(sPOUIndex);
    if(RtsProgramLoaded()&&pPlcFunctions!=0)
    {
      ulValue=SysCallWith3Param(
              (PFCALLBACK)pPlcFunctions,
              ulParam1,
              ulParam2,
              ulParam3
            );
    }
  }
  return(ulValue);
}
I have the similar question. I try to use System event EXCPT_WATCHDOG in Task configuration as follows:
1) watchdog in main program PLC_PRG is enabled and set to 30 sec;
2) main program represents endless loop
WHILETRUEDO;END_WHILE
3) System event EXCPT_WATCHDOG is set, called POU have only one operator ```
SysResetPlcProgram(0);
``` from PLC control system library SysLibPlcCtrl.lib (I want to reset my program when watchdog triggered)
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.
Please explain me how I should reset program or completely PLC?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hey guys,
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.
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:
ADRINST
Adress function, not prescribed by the standard IEC61131-3.
ADRINST within a function block instance returns the address of the instance in a DWORD. This
address then can be sent to functions and be treated there as a pointer or it can be assigned to a
pointer within the project.
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?
Greeting,
RikeR
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.
What you need in order to do so is the CAA_Callback.lib. This is an external library that provides the function CB_CallFunctionByIndex .
The call could e.g. look like this:
Please find the sepcification of the CAA_Callback.lib attached (unfortunately German only).
It is important that this function can only call another function that fulfils the following requests:
A possible prototype thus looks like this:
Please find a CoDeSys project with the name FB-Pointer-Liste.pro attached. There the following approach is considered:
If the CAA_Callback.lib is not available you could probably write your own c library. It should have something like this:
CAA_Callback.pdf [45.66 KiB]
CAA_Callback.zip [3.92 KiB]
FB Pointer Liste.zip [5.4 KiB]
hi!
I have the similar question. I try to use System event EXCPT_WATCHDOG in Task configuration as follows:
1) watchdog in main program PLC_PRG is enabled and set to 30 sec;
2) main program represents endless loop
3) System event EXCPT_WATCHDOG is set, called POU have only one operator ```
SysResetPlcProgram(0);
``` from PLC control system library SysLibPlcCtrl.lib (I want to reset my program when watchdog triggered)
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.
Please explain me how I should reset program or completely PLC?
Your callback must return 0. Just have a look to the attached program which is working for me with PlcWinNt
testwd.pro [25.96 KiB]