A Brief Introduction to TwinCAT PLC Control 2.1 Project Components A project contains all of the objects in a PLC program. A project is saved in a file named after the project. The following objects are included in a project: POUs (Program Organization Units), 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 POU, which yields exactly one data element (which can consist of several elements, such as fields or structures) when it is processed, and whose call in textual languages can occur as an operator in expressions. When declaring a function do not forget that the function must receive a type. This means, after the function name, you must enter a colon followed by a type. A correct function declaration can look like this example: FUNCTION Fct: INT In addition, a result must be assigned to the function.
That means that function name is used as an output variable. Example in IL of a function that takes three input variables and returns the product of the first two divided by the third: The call of a function in ST can appear as an operand in expressions. Functions do not have any internal conditions. That means that calling up a function with the same argument (input parameters) always produces the same value (output). NOTE Declaration If you declare a local variable in a function as retain, this has no consequence. The variable is not stored in the retain area. Examples for calling up the function described above: in IL: LD 7 TwinCAT 2 PLC Control 10 Version: 1.0