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 save location and format, in the object Recipe Manager. Insert one or more recipe definitions below this object. A recipe definition comprises 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.

Note

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).

See also

Using recipes in the CODESYS user interface

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

See also

Using recipes in applications

When the application is in runtime mode, 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 (internal command of visualization elements.

Note

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.

See also

Creating recipes

  1. Select the Application object in the device tree.

  2. Click Project ‣ Add Object ‣ Recipe Manager .

    ⇒ CODESYS adds the recipe manager to the device tree.

  3. Select the Recipe Manager object in the device tree.

  4. Click Project ‣ Add Object ‣ Recipe Definition .

    ⇒ 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 that you will define a recipe. The input assistant can be used for this: button.

  7. Click Recipes ‣ Add a new recipe and enter 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 save location and file name.

    ⇒ CODESYS saves the recipe in the format as defined in the recipe manager.

See also

Loading recipes 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:

PLC_PRG.bVar:=0
PLC_PRG.iVar:=2
PLC_PRG.dwVar:=35232
PLC_PRG.stVar:='first'
PLC_PRG.wstVar:='123443245'
  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. Click the myRec column in the recipe definition and right-click for the Load recipe command.

    ⇒ 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.

Note

Please note that it is possible to modify the recipe file externally so that only individual values of a recipe are reloaded and the remaining values remain unchanged in CODESYS and on the PLC. Entries in the recipe file that you removed the value assignment are not read.

See also

Recipe management on the controller; memory usage

When you clear the Recipe management in the PLC check box, the recipe manager and recipe definitions will not use any memory on the PLC.

If you select this check box, 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.

Memory Usage for CODESYS V3 SP6 with CODESYS Control Win V3 Controller
  Code Size (bytes) Data Size (bytes) Total (bytes)
Recipe definition with 100 INT variables 194406 79400 267352
Recipe definition with 200 INT variables 238318 121284 459344
Recipe definition with 300 INT variables 282230 163084 543856
Recipe definition with 100 BOOL variables 192742 69884 343168
Recipe definition with 200 BOOL variables 235446 101568 436872
Recipe definition with 300 BOOL variables 278146 133284 510072
Recipe definition with 100 string variables 203278 870084 1154000
Recipe definition with 200 string variables 255570 1709784 2973296
Recipe definition with 300 string variables 307886 2549484 2964112

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 option Recipe management in the PLC is activated 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. Login 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. Login again to the controller with 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 wish 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 wish 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.