Many common programming languages have constructors, and some also have destructors. TwinCAT 3 and CODESYS 3 have the methods that map something like constructors and destructors. These are not real constructors/destructors, but this detail is not important for now. This blog post covers the basics and pitfalls.
There are always 3 methods for each function block:
FB_init
: This is the constructor. As you can see from the name, this is not a real constructor. It is just a method to initialize an instance of a function blockFB_exit
: This is the destructor. As you can see from the name, this is not a real destructor.FB_reinit
: This method is a PLC peculiarity, that is only used for online change.
Furthermore, this blog article discusses a few pragmas that can and must be used to influence the behavior when creating, destroying and reinitializing.