Using recipes

Handling recipes in the TwinCAT user interface

The TwinCAT programming interface provides you with commands for the creation of recipes as well as reading/writing in online mode.

See also:

Use of recipes in the application

You can use recipes at runtime in the user program or via visualization elements.

In the user program you use methods of the function block RecipeManCommands from the library RecipeManagement. In the visualization the use of recipes takes place via the input configuration (internal command) of visualization elements.

Using recipes 1:

During the initialization procedure the recipe management reads the values of variables that are defined in the recipe definition. This procedure takes place at the end of the initialization phase of the application. All initial values of the application variables are set at this point in time. This is carried out so that missing values from recipe files can be correctly initialized.

See also:

Creating a recipe

1. Select the PLC project in the Solution Explorer.
2. Select the command Add > Recipe Manager... in the context menu.
TwinCAT adds the recipe manager to the PLC project.
3. Select the object Recipe Manager in the PLC project tree.
4. Select the command Add > Recipe Definition... in the context menu.
TwinCAT adds the recipe definition below the recipe manager.
5. Open the recipe definition editor by double-clicking on the object.
6. Double-click on the empty field in the column Variable in the editor. Enter the name of a variable for which you wish to define a recipe. The input assistant is available for this (button Using recipes 2:).
7. Select the command Add Recipe in the menu Recipe or in the context menu of the editor and enter a name for the new recipe (e.g. "MyRec").
A column with the recipe name appears in the editor.
8. Enter the value of the variable for this recipe.
9. Add further variables if necessary.
10. Select a variable value of the recipe and execute the command Save Recipe in the menu Recipe or the context menu. Select a memory location and a file name.
TwinCAT saves the recipe in the format defined in the recipe manager.
Using recipes 3:

Overwriting the implicit recipe file

The implicitly used recipe files, which are needed as a clipboard for reading and writing recipes, must not be overwritten. This means that the file name must be different to <Recipe name>.<Recipe definition name>.txtrecipe

See also:

Loading a recipe from a file

There is a recipe management in a PLC project. There is a recipe "MyRec" with variable values in a recipe definition. A recipe file MyRec.txt containing the entries for this recipe exists in the file system.
1. Open the table editor for the definition of the individual recipes by double-clicking on the object Recipe Definition in the PLC project tree.
You will see a column MyRec containing the current values for this recipe.
2. Edit the file MyRec.txt in an external text editor and replace the variable values by others that you wish to load into the recipe definition in TwinCAT. Save the file.
3. Click in the column MyRec in the recipe definition and select the command Load Recipe in the menu Recipe or in the context menu.
The dialog Load Recipe opens.
4. Select the file MyRec.txt 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 change the current values of the recipe variables by loading the recipe, a query appears the next time you log in asking whether you wish to log in with online change, download or without changes.

Example of a recipe file:

MAIN.nVar1:=0
MAIN.nVar2:=2
MAIN.nVar3:=35232
MAIN.sVar4:='first'
MAIN.wsVar5:='123443245'
Using recipes 4:

If you want to overwrite only individual recipe variables with new values, remove the values for the other variables before loading the recipe into the recipe file. Entries without value specification are not read, which means that these variables are unaffected by the update on the controller and in the project.

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

See also:

Reading a recipe

TwinCAT is in online mode.
1. Click in the recipe column in the recipe definition and select the command Read Recipe in the menu Recipe or in the context menu.
TwinCAT overwrites the values of the selected recipe with the values read from the controller. In the process, the values are implicitly stored (in a file on the controller) and simultaneously displayed in the table of the recipe definition.

See also:

Writing a recipe

TwinCAT is in online mode.
1. Click in the recipe column in the recipe definition and select the command Write Recipe in the menu Recipe or in the context menu.
TwinCAT overwrites the values in the controller with the values from the selected recipe.

See also: