Skip to main content

Changing Values with Recipes

Use recipes to change or read recipes values for a specific set of variables (recipe definition) on the controller at the same time.

You define the basic settings for recipes, such as location and format, in the Recipe Manager object. Insert one or more recipe definitions below this object. A recipe definition is composed of one or more recipes for the contained variable. The recipe consists of specific variable values.

You can save a recipe to a file or write directly from files to the PLC.

Recipes can be loaded via the CODESYS development interface, the visualization element, or the application program.

Using recipes on remote devices

The variable values from recipes are transferred automatically to and from another controller when they are data source variables and a data source exchange is configured. Reading and writing occurs synchronously. Therefore, CODESYS updates all variables in a recipe at the same time. After reading or writing, you can use the call g_RecipeManager.LastError to check whether or not the transfer was successful (g_RecipeManager.LastError = 0).

Handling of recipes in the CODESYS user interface

The development interface of CODESYS provides commands for generating recipes as well as reading/writing in online mode.

Using recipes in applications

At runtime, you can use recipes in the user program and visualization elements.

In the user program, you use the methods for the function block RecipeManCommands from the library RecipeManagement. In the visualization, you use recipes via the input configuration (execute command of visualization elements.


During the initialization process, the recipe management reads the values of the variables that are defined in the recipe definition. This operation takes place at the end of the initialization phase of the application. At this point, all initial values of the application variables are set. This is performed to initialize missing values from recipe files correctly.

Creating a recipe

  1. In the device tree, select the Application object.

  2. Click Project → Add Object → Recipe Manager.

    CODESYS adds the Recipe Manager to the device tree.

  3. In the device tree, click the Recipe Manager object.

  4. Click Project → Add Object → Recipe Manager.

    CODESYS adds the recipe definition below the Recipe Manager.

  5. Open the editor of the recipe definition by double-clicking the object.

  6. Double-click the blank field below Variable. Specify the name of a variable to define a recipe for. You can use the Input Assistant (_cds_icon_button_threedots.png button) for this.

  7. Click Recipes → Add a New Recipe and specify a name for the new recipe.

    A column with the new recipe name appears in the editor.

  8. Enter the variable value for this recipe in this field.

  9. Insert additional fields as needed.

  10. Select a variable value for the recipe and click Recipes→ Save Recipe. Select a location and file name.

    CODESYS saves the recipe in the format as defined in the Recipe Manager.

Loading a recipe from a file

Requirement: A Recipe Manager is available in the application. In a recipe definition, there is a myRec recipe with variable values. A myRec.txt recipe file is located on the file system and contains the entries for this recipe.

Example of the recipe file:

  1. Double-click the Recipe Definition object in the device tree to open the tabular editor for the definition of the individual recipes.

    You see the myRec column with the current values for this recipe.

  2. Edit the myRec.txt file in an external text editor and replace the variable values with other values that you want to load into the recipe definition in CODESYS. Save the file.

  3. In the recipe definition, click the myRec column and in the context menu click Load Recipe.

    A dialog prompt notifies you about the possibly needing to perform an online change when logging in again. An online change is necessary when you change the current values of the recipe variables by loading the recipe.

  4. Click Yes to close the dialog and continue. Select the myRec.txt file from the file explorer for loading.

    The recipe values in the recipe definition are updated according to the values read in the file.


If you want to overwrite only individual recipe variables with new values, then remove the values for the other variables before loading to the recipe file. Entries without value definitions are not read, and therefore updating leaves these variables unchanged on the controller and in the project.

For values of the data type REAL/LREAL, the hexadecimal value is also written to the recipe file in some cases. This is necessary so that the exactly identical value is restored when converting back. In this case, change the decimal value and delete the hexadecimal value.

Recipe management on the controller; memory usage

When you clear the Recipe management in the PLC option, the Recipe Manager and recipe definitions will not use any memory on the PLC.

If you select this option, then code is generated for the Recipe Manager and all recipe definitions, and this code is stored on the PLC. The size of the used memory primarily depends on the number pf recipes and their variables, as well as the data type of the variables. Whether or not the fields of the recipe definition are filled also has an effect. The memory usage of recipes cannot be calculated. It has to be determined by experimentation at the time it is needed. The following table merely provides some guiding principles.

Table 4. Memory usage for CODESYS V3 SP6 with a CODESYS Control Win V3 controller

Code Size (bytes)

Data Size (bytes)

Total (bytes)

Recipe definition with 100 INT variables




Recipe definition with 200 INT variables




Recipe definition with 300 INT variables




Recipe definition with 100 BOOL variables




Recipe definition with 200 BOOL variables




Recipe definition with 300 BOOL variables




Recipe definition with 100 string variables




Recipe definition with 200 string variables




Recipe definition with 300 string variables




Loading recipe values from the controller

You can apply recipe values on the controller to recipe definitions in the project, even if these definitions have been modified in the project.

Requirement: The Recipe management in the PLC is option is selected in the Recipe Manager.

  1. Create a recipe definition RecDef1 in the project, containing the variables PLC_PRG.ivar and PLC_PRG.bvar. Insert a recipe R1: value for PLC_PRG.ivar: 33; value for PLC_PRG.bvar: TRUE.

  2. Log in to the controller and download the application.

    The recipe file R1.RecDef1.txtrecipe is saved to the default directory of the controller ($PlcLogic$).

  3. Logout and add another variable PLC_PRG.dwvar to the recipe definition in the project.

  4. Edit the recipe definition file R1.RecDef1.txtrecipe on the device by changing the value for PLC_PRG.ivar from 33 to 34.

    Moreover, add another recipe R2 on the device. To do this, copy the R1.RecDef1.txtrecipe and rename it to R2.RecDef1.txtrecipe. Then edit this file and change the recipe values: PLC_PRG.ivar: 1, PLC_PRG.bvar: FALSE.

    Now two recipes R1 and R2 are available on the device. In the project, there is only R1, and it also contains other values than R1 on the device.

  5. Log in to the controller by means of an online change.

  6. Click Load Recipes from Device from the context menu.

    A dialog prompt notifies you that executing the command at the next login may trigger an online change, and that the recipes on the runtime system will overwrite the recipes of the current recipe definition.

  7. Confirm that you want to continue.

    A dialog prompt notifies you that the recipe for PLC_PRG.dwvar loaded on the device cannot yield a value from the controller.

  8. Confirm that you want to continue.

    The value of PLC_PRG.ivar in recipe R1 of the recipe definition in the project changes to 34. The recipe R2 with the values 1 and FALSE is also listed in the recipe definition now. PLC_PRG.dwvar remains in the recipe definition.