twincatstiec61131-3

How can warm start a method in TwinCAT?


One of the features of the method based on the definition of Beckoff site is that:

All data of a method are temporary and are only valid while the method is executed (stack variables). This means that TwinCAT re-initializes all variables and function blocks, which you have declared in a method, with each call of the method.

Is there any way to use a method in the plc loop as warm start!

it means that we use the method without re_initializing and method declare variations run just once at the first time we call it and the rest of the time that is called the variables retain their own values?


Solution

  • Yes, this is possible through VAR_INST or VAR_STAT. Just declare your variables as VAR_INST/VAR_STAT instead, then they will retain their values between the calls.

    VAR_INST means it will be unique for every instantiation of the function block of where the method resides, while VAR_STAT will act as a static/global (all instances will point to the same memory location).

    https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/2528798091.html&id=

    https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/2528787339.html&id=