====== Program ====== A program represents a POU of the highest level in a user program. A controller (PLC) may process more programs, and the IDE contains tools for [[:en:mervis-ide:35-help:015-plc:065-plc_prog_map|definition of activity of programs]] (or, how often a program shall be executed, program priority, etc.). Every POU has two main parts: declarative and executive. In the declarative parts of a POU, variables necessary for the POU activity are defined. The executive part then contains the commands necessary for the execution of the required algorithm. ==== Program declaration ==== PROGRAM name ... END_PROGRAM ==== Variables declaration ==== The declarative part of the program contains definitions of variables necessary for the program's activity. Variables are used to store and process information. Each variable is defined by the variable name and data type. The data type defines the space used by the variable in memory, and determines the way the variable is processed. For definition of variables, standard data types (BOOL, BYTE, INT, …) are available. The usage depends on the type of information which is stored in the memory (e.g. BOOL for yes/no informations, INT for signed whole numbers, etc.). Users are allowed to define their own data types, too. The placement of variables in a PLC memory is managed by the IDE automatically. If necessary, user can define the location of a variable in memory, too. Input variables VAR_INPUT ... END_VAR Output variables VAR_OUTPUT ... END_VAR Input/output variables VAR_IN_OUT ... END_VAR Static variables VAR ... END_VAR External variables VAR_EXTERNAL ... END_VAR Initialisation of variables VAR I : INT := 1; END_VAR; Definition of „retain“ variables (are kept in memory even after a power cycle) VAR RETAIN ... END_VAR ==== Executive part ==== The executive part follows the declarative part and contains commands and instructions. ---- Example of a program (TEST): PROGRAM TEST //name of the program: TEST VAR //static declarations (of a function block, in this example) My_Room : Light_Room; END_VAR VAR_EXTERNAL //external declaration Actual_TOD : TOD; END_VAR (* Program body *) IF (Actual_TOD >= TOD#20:15:00) OR (Actual_TOD <= TOD#6:00:00) THEN MyRoom.NightTime(); ELSE MyRoom.DayTime(); END_IF; END_PROGRAM {{:en:mervis-ide:35-help:prog.png}}