A Brief Introduction to TwinCAT PLC Control 2.1 Project Components A project contains all objects of a control program. A project is saved in a file with the name of the project. A project includes the following objects: function blocks, data types, resources and libraries. POU (Program Organization Unit) Functions, function blocks, and programs are POUs, which can be supplemented by actions. Each POU consists of a declaration part and a body. The body is written in one of the IEC programming languages which include IL, ST, SFC, FBD, LD or CFC. TwinCAT PLC Control supports all IEC standard POUs.
If you want to use these POUs in your project, you must include the library standard.lib in your project. POUs can call up other POUs. However, recursions are not allowed. Function A function is a function block that returns exactly one data element (which can also be multi-element, such as fields or structures) when executed, and whose call in textual languages can occur as an operator in expressions. When declaring a function, it is important to note that the function must be given a type. I.e. after the function name a colon followed by a type must be entered. A correct function declaration looks like this, for example: FUNCTION Fct:
INT In addition, a result must be assigned to the function. The function name is used like an output variable. Sample in IL for a function that takes three input variables and returns as result the product of the first two divided by the last one: The call to a function can occur in ST as an operand in expressions. Functions do not have internal states. I.e. calls of a function with the same arguments (input parameters) always return the same value (output). If a local variable is declared as RETAIN in a function, this has no effect. The variable is not stored in the retain area. Samples of calling the function described above: in IL: LD 7 Fct 2,4 ST Ergebnis TX1200 10 Version: 1.3