Using Recipes
Adding a Recipe Manager
In the device tree, select the Application object.
Only one Recipe Manager can be added to an Application.
Click the Project → Add Object → Recipe Manager command.
The Recipe Manager is added to the device tree.
Adding a recipe definition
Requirement: A Recipe Manager is available in the Application.
In the device tree, click the Recipe Manager object.
Click the Project → Add Object → Recipe Definition command.
The recipe definition is added below the Recipe Manager.
Any number of Recipe Definitions can be added to a Recipe Manager.
Defining the storage location
Specifies the storage location for reading and writing recipe files.
Note
The path configuration can vary depending on the PLC used.
In the case of CODESYS Control Win SL, relative paths which refer to a directory in the PLC file system (PlcLogic) must always begin with "./". Otherwise, unexpected behavior may result because recipe file names are usually simply appended to the configured storage location.
Requirement: A Recipe Manager is available in the Application.
In the device tree, open the Recipe Manager object.
In the Recipe Manager object, open the Storage tab.
In the File path field, specify the desired path, or click the
button to use the Input Assistant.
Use the RecipeManCommands.SetStoragePath (METH) method.
You can use this method to update the storage path at runtime, for example to assign recipe files to different directories.
Adding variables to a recipe definition
Requirement: A Recipe Manager with a Recipe Definition is available in the Application.
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 to define a recipe for. You can use the Input Assistant for this by clicking the
button).Requirement: The variables must be declared in the declaration editor of the program, or the
GVLmust be declared.Insert additional fields as needed.
The values of a variable can be defined separately for each recipe.
Adding a new, empty recipe
Requirement: A Recipe Manager with a Recipe Definition is available in the Application.
Open the editor of the Recipe Definition by double-clicking the object.
Right-click in any cell of the table.
Select the Add a New Recipe command.
Specify a unique name and click OK to confirm.
Use the RecipeManCommands.CreateRecipeNoSave (METH) method to create an empty recipe without performing any other actions.
The
NoSavesuffix prevents a recipe file from being created in the currently defined storage location.Note
After a recipe is created, it is only automatically saved to a recipe file only if the Save recipe changes to recipe files automatically option is selected on the General tab of the Recipe Manager object.
Saving a recipe file
Requirement: A Recipe Manager with a Recipe Definition is available in the Application.
Open the editor of a Recipe Definition which contains the recipe that should be exported to a recipe file.
Below the recipe, specify the value of the variable for this recipe.
Right-click in any cell of the recipe column of the recipe to save.
Select the Save Recipe command.
Use the Explorer window to specify the desired storage location and file name.
Use the RecipeManCommands.SaveRecipe (METH) method.
Add a new recipe which contains current PLC values.
Requirement: A Recipe Manager with a Recipe Definition is available in the Application.
Open the editor of the Recipe Definition by double-clicking the object.
Right-click in any cell of the table.
Select the Add a New Recipe command and click OK to confirm.
Right-click in any cell of the recipe column of the newly created recipe.
The programming system must be connected online to the PLC. In the context menu, select the Read Recipe command in order to read the current PLC variable and apply it to the recipe.
Use the RecipeManCommands.CreateRecipe (METH) method.
This function creates a new recipe in the buffer and then automatically reads in the current PLC variables.
Note
If the Save recipe changes to recipe files automatically option is selected on the General tab of the Recipe Manager object, then the recipe will also be automatically saved to a recipe file.
Load a recipe from the file system into the buffer
Requirement: A Recipe Manager with a Recipe Definition is available in the Application.
Open the editor of the Recipe Definition where the recipe should be loaded.
Right-click in any cell of the table.
Select the Add a New Recipe command and click OK to confirm.
A new recipe with the specified name is listed in the table on the right side.
Right-click in any cell of the added recipe.
Select the Load Recipe command and click OK to confirm.
Use the Explorer window to browse and select the desired recipe file.
The data is displayed.
Use the RecipeManCommands.LoadRecipe (METH) method.
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:
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
myReccolumn with the current values for this recipe.Edit the
myRec.txtfile 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.In the recipe definition, click the myRec column and in the context menu click 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.txtfile from the file explorer for loading.The recipe values in the recipe definition are updated according to the values read in the file.
Tip
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, you change the decimal value and delete the hexadecimal value.
Reading PLC values into a buffered recipe
Requirement: A Recipe Manager with a Recipe Definition is available in the Application.
Current PLC variable values are read into a buffered recipe.
Open the editor of a Recipe Definition which contains the recipe where the PLC variables should be read.
Right-click in any cell of the recipe column of the recipe.
Select the Read Recipe command. This command is available only when the application is online.
Use the RecipeManCommands.ReadRecipe(METH) method.
Writing recipe values from a recipe file to PLC variables
Requirement: A Recipe Manager with a Recipe Definition is available in the Application.
This function loads values from a recipe file to an existing buffered recipe and then writes them to the assigned PLC variables.
Open the editor of a Recipe Definition which contains the recipe where the PLC variables should be written to PLC variables.
Right-click in any cell of the recipe column of the recipe which should be written to the PLC.
Select the Load and Write Recipe command. This command is available only when the application is online.
Use the RecipeManCommands.LoadAndWriteRecipe(METH) method.
Writing recipe values from a buffered recipe to PLC variables
Requirement: A Recipe Manager with a Recipe Definition is available in the Application.
Open the editor of a Recipe Definition which contains the recipe where the PLC variables should be written to PLC variables.
Right-click in any cell of the recipe column of the recipe which should be written to the PLC.
Select the Write Recipe command. This command is available only when the application is online.
Use the RecipeManCommands.WriteRecipe(METH) method.
Reading PLC values into a buffered recipe and exporting them to a recipe file.
Requirement: A Recipe Manager with a Recipe Definition is available in the Application.
Open the editor of the Recipe Definition which contains the recipe that should be used for reading the PLC variables and is then writing to a recipe file.
Right-click in any cell of the recipe column of the desired recipe.
Select the Read and Save Recipe command and click OK to confirm your desired online change option in the following dialog.
Select a location and a file name and click Save.
Use the RecipeManCommands.ReadAndSaveRecipe(METH) method.
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.
Create a recipe definition
RecDef1in the project, containing the variablesPLC_PRG.ivarandPLC_PRG.bvar. Insert a recipe R1: value forPLC_PRG.ivar:33; value forPLC_PRG.bvar:TRUE.Log in to the controller and download the application.
The recipe file
R1.RecDef1.txtrecipeis saved to the default directory of the controller ($PlcLogic$).Logout and add another variable
PLC_PRG.dwvarto the recipe definition in the project.Edit the recipe definition file
R1.RecDef1.txtrecipeon the device by changing the value forPLC_PRG.ivarfrom33to34.Moreover, add another recipe R2 on the device. To do this, copy the
R1.RecDef1.txtrecipeand 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.
Log in to the controller by means of an online change.
Click the Load Recipes from Device command in 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 want to continue.
A dialog prompt notifies you that the recipe for
PLC_PRG.dwvarloaded on the device cannot yield a value from the controller.Confirm that you want to continue.
The value of
PLC_PRG.ivarin recipe R1 of the recipe definition in the project changes to34. The recipe R2 with the values1andFALSEis also listed in the recipe definition now.PLC_PRG.dwvarremains in the recipe definition.
Deleting a recipe
Requirement: A Recipe Manager with a Recipe Definition is available in the Application.
Open the Recipe Definition where a recipe should be deleted.
Right-click in any cell of the recipe column of the recipe to be deleted.
Select the Remove Recipe command.
Use the RecipeManCommands.DeleteRecipe (METH) method.