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
:strong: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.
See also
- Library ‘Recipe Management’ - ‘RecipeManCommands’
- Input configuration: input_configuration
Creating recipes
Select the Application object in the device tree.
Click
.- ⇒
CODESYS adds the recipe manager to the device tree.
Select the Recipe Manager object in the device tree.
Click
.- ⇒
CODESYS adds the recipe definition below the recipe manager.
Open the editor of the recipe definition by double-clicking the object.
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.
Click
and enter a name for the new recipe.- ⇒
A column with the new recipe name appears in the editor.
Enter the variable value for this recipe in this field.
Insert additional fields as needed.
Select a variable value for the recipe and click
. 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'
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.
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.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.
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.
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.
Create a recipe definition
RecDef1
in the project, containing the variablesPLC_PRG.ivar
andPLC_PRG.bvar
. Insert a recipe R1: value forPLC_PRG.ivar
:33
; value forPLC_PRG.bvar
:TRUE
.Login to the controller and download the application.
- ⇒
The recipe file
R1.RecDef1.txtrecipe
is saved to the default directory of the controller ($PlcLogic$).
Logout and add another variable
PLC_PRG.dwvar
to the recipe definition in the project.Edit the recipe definition file
R1.RecDef1.txtrecipe
on the device by changing the value forPLC_PRG.ivar
from33
to34
.Moreover, add another recipe R2 on the device. To do this, copy the
R1.RecDef1.txtrecipe
and rename it toR2.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.
Login again to the controller with online change.
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.
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.
Confirm that you wish to continue.
- ⇒
The value of
PLC_PRG.ivar
in recipe R1 of the recipe definition in the project changes to34
. The recipe R2 with the values1
andFALSE
is also listed in the recipe definition now.PLC_PRG.dwvar
remains in the recipe definition.