This sample is the RecipeManagement sample, extended by a filter: a text box limits the recipe selection to the recipes whose name or folder contains the entered text.
- Open TcHmiRecipeManagementFilterSample.sln in Visual Studio or the TwinCAT XAE Shell with TwinCAT HMI Engineering installed.
- Activate the configuration of
TwinCAT Project1and start the PLC. - Restore the NuGet packages, build the solution and start the Live-View of the
TcHmiRecipeManagementFilterSampleproject. - Enter a part of a recipe name in the filter at the bottom, for example
2, and open the recipe selection.
The solution contains two projects:
| Project | Content |
|---|---|
| TcHmiRecipeManagementFilterSample | The HMI project with the recipe management server extension and the user interface. |
| TwinCAT Project1 | A PLC with the variables MAIN.Value1 and MAIN.Value2. |
The user interface, the recipes and the functions are the same as in RecipeManagement, which describes them in detail. This README only describes the filter. On the page Functions, the box of ListRecipesAsReferenceArray highlights the filter.
The container at the bottom of Desktop.view contains the text box RecipeFilter in front of the recipe selection RecipeSelect. The combobox gets its recipes from the function ListRecipesAsReferenceArray, which has a second parameter for the filter text:
%f%TcHmi.Functions.RecipeManagementFilterSample.ListRecipesAsReferenceArray(
%s%TcHmiRecipeManagement.Config::recipeList%/s%, %ctrl%RecipeFilter::Text%/ctrl%)%/f%
The binding calls the function again whenever the recipe list or the text of the filter changes. The function only returns the recipe references which contain the filter text, regardless of upper and lower case. An empty filter returns all recipes. The reference includes the folder, so sub finds SubFolder1::Recipe4.
export function ListRecipesAsReferenceArray(
recipeList: Server.RecipeManagement.FolderRecipe | null,
filterText: string | null
): string[] {
// ...
const filter = (filterText ?? '').toLowerCase();
// ...
if (reference.toLowerCase().includes(filter)) {
result.push(reference);
}
// ...
}See ListRecipesAsReferenceArray.ts and its description ListRecipesAsReferenceArray.function.json with the parameter filterText.
The functions of this sample are registered in the namespace TcHmi.Functions.RecipeManagementFilterSample, so they do not collide with the functions of RecipeManagement when both are used in one project.
Note: The button Delete selected recipe only deletes a recipe if the combobox lists more than one recipe. With an active filter this counts the listed recipes, not all recipes: if the filter leaves only one recipe, clear the filter to delete it.
- RecipeManagement: the sample without filter, with the description of the user interface and the functions
- Logic in the background (documentation in Infosys)
