Default Recipe Examples
The "Default" type Recipe is an engine to allow users to load and save a list of tags in a data file quickly as soon as needed.
For example, in a paint factory, every 8 hours the production changes the product being manufactured. So the inputs to the machines must change too, such as temperature, amounts of the substances, etc. The best way to change those parameter values is to first create different recipes for the paints and load each of them when needed. See the example below:
In this example, there are 3 recipes pre-created. First, the factory produced Blue Paint (Water-based) and then it changed to produce Red Paint (Resin-based). All those values will be loaded to the application tags and used to configure the machines automatically.
Example 1: Saving and Loading recipes using triggers only.
. Insert a new Recipe document.
. Configure the Recipe Settings as shown in the image below.
. Recipe Path: testeRecipe1RelativePath
. Relative Path: True
. Recipe Save Mode: File
. Trigger Save: @saveRecipe1 (type numeric, can be integer, float, boolean)
. Trigger Load: @loadRecipe1 (type numeric, can be integer, float, boolean)
. Type: Default
.
Configure a tag to store and load its value. In this
example, we created tag "Temperature" which is a float type.
. Now let's run a test.
. Run the Application (F5) and see the results.
. Open the Data Watcher.
. Add the 3 tags to the Data Watcher as in the image below. Write a value to the temperature and then change the saveRecipe1 tag value to something different than last value.
. After triggering the saveRecipe1, the file testeRecipe1RelativePath.rpf will be created under the application's root folder. This new file will contain the tag Temperature and its value when the recipe was saved, which was value 111.
. Now let's give a different value to the Temperature tag using the Data Watcher
. Notice the Temperature is now zero and saveRecipe1 is still 1.
. The next step is to reload tag Temperature to check if it will load value 111.
. In order to do that, let's now trigger the loadRecipe1 tag.
. You will see how the Temperature will now load its saved value 111.
Example 2: Saving and Loading recipes using the SmartView Function Library.
. Insert a new Recipe document.
. Configure the Recipe Settings as shown in the image below.
. Recipe Path: testeRecipe1RelativePath
. Relative Path: True
. Recipe Save Mode: File
. Trigger Save: Leave this field empty. We won't be using it in this example.
. Trigger Load: Leave this field empty. We won't be using it in this example.
. Type: Default
. Configure a tag to store and load its value. In this example, we have created the tag "Temperature" which is a float type.
. Now let's create a screen to interact. Create a new Graphics.
. Insert a GroupBox, a label, a TextBox and 4 buttons as in the image below.
. The GroupBox was configured with Text "Recipe" and the background color with gradient type.
. The Label got the Text "Temperature:"
. The TextBox received the tag we are going to test. Remember to use "@" to indicate it is a tag and not a static text.
. The Button1 was configured with Text "Save" and on the Mouse event the following.
. The Button2 was configured with Text "Load" and on the Mouse event the following.
. The Button3 was configured with Text "Save and Wait" and on the Mouse event the following.
. The Button4 was configured with Text "Load and Wait" and on the Mouse event the following.
. Now let's run a test.
. Run the Application (F5) and see the results.
. Insert a value to the Temperature and click Save.
. In the meantime, you can check the saved file. In this example, it is being saved in the root folder of the application, where the .prj is located.
. Now let's change the Temperature value in the interface to make sure that the value is changing when we load it from the recipe.
. With the value different than the last saved, we can click Load.
. You can test the SaveAndWait and LoadAndWait functions in parallel.
Tips:
Save
. void Save(string RecipeFile)
- The only parameter is the name of the Recipe saved (i.e. Recipe1).
- Asynchronous function.
- Function has no return.
. void Save(string RecipeFile, string Path)
- First parameter refers to the name of the Recipe and Second parameter refers to the full path of the file being generated.
- Asynchronous function.
- Function has no return.
Load
. void Load(string RecipeFile)
- The only parameter is the name of the Recipe saved (i.e. Recipe1)
- Asynchronous function.
- Function has no return.
. void Load(string RecipeFile, string Path)
- First parameter refers to the name of the Recipe and Second parameter refers to the full path of the file being generated.
- Asynchronous function.
- Function has no return.
Save and Wait
. bool SaveAndWait(string RecipeFile)
- The only parameter is the name of the Recipe saved (i.e. Recipe1)
- Synchronous function. Waits for the recipe to finish before executing next command.
- Boolean return indicating if the saving process is finished or not.
. bool SaveAndWait(string RecipeFile, string Path)
- First parameter refers to the name of the Recipe and Second parameter refers to the full path of the file being generated.
- Synchronous function. Waits for the recipe to finish before executing next command.
- Boolean return indicating if the saving process is finished or not.
Load and Wait
. bool LoadAndWait(string RecipeFile)
- The only parameter is the name of the Recipe saved (i.e. Recipe1).
- Synchronous function. Waits for the recipe to finish before executing next command.
- Boolean return indicating if the loading process is finished or not.
. bool LoadAndWait(string RecipeFile, string Path)
- First parameter refers to the name of the Recipe and Second parameter refers to the full path of the file being generated.
- Synchronous function. Waits for the recipe to finish before executing next command.
- Boolean return indicating if the loading process is finished or not.
Related Recipe sections: