Skip to main content

ControlForge Recipes Guide

ControlForge v1.0.1684 | Contract: docs/features/recipes.md


1. What a recipe is​

A recipe is a named set of parameter values for one machine: the speed, temperature and time of one product, saved so the operator can bring it back with one action.

In ControlForge a GVL is the recipe definition and a recipe is a file holding that GVL's member values. There is no database and no version table. You write the GVL like any other:

(* GVL_Recipe_Mixer -- the recipe definition: members are the parameters *)
VAR_GLOBAL (GVL_Recipe_Mixer)
speed_sp : REAL := 1200.0;
temp_sp : REAL := 65.0;
mix_time : TIME := T#90s;
add_water : BOOL := TRUE;
stages : INT := 3;
batch_id : STRING := 'none';
END_VAR

The declared types are the types, so a value that does not fit its member is refused, and the initial values are what the machine starts with. Only a GVL or a program scope is a group: a struct-instance path (GVL_Mixer.recipe) or a function-block-instance path (PF.f1) is refused (HTTP 400, ST FALSE), and a member that is itself a struct, function-block instance or array is skipped (reported as skipped, never written, never blocking the group).

Files live in <paths.data>/recipes/<group>/<name>.json. The group folder is the GVL name in lower case. A recipe looks like this:

{
"group": "gvl_recipe_mixer",
"saved_at": "2026-09-29T12:25:19Z",
"saved_by": "goplc",
"values": {
"add_water": false,
"batch_id": "FAST",
"mix_time": "T#2m",
"speed_sp": 1800,
"stages": 5,
"temp_sp": 80
}
}

It is plain JSON. You can copy it, diff it and edit it by hand; every select and every load checks whatever it finds.

Carried types: BOOL, the integer types, REAL, LREAL, STRING and TIME. Arrays, structs, function-block instances, enums and the DATE types are left out (the API lists them as skipped).

2. The handshake: the operator selects, the program applies​

Changing what a machine runs is the program's decision, not the HMI's. So loading a recipe is a handshake, the way a PLC has always done it:

  1. The operator selects a recipe (HMI button Select for loading, POST /api/recipes/{group}/{name}/select, or the MCP tool controlforge_recipe_select). The whole recipe is checked. If any value does not fit, nothing is selected and every problem is listed. Otherwise it becomes the group's pending selection (who, when). No tag is written. Selecting again replaces the selection; Clear removes it.
  2. The program applies it at a point it chooses: batch start, idle, a safe state. RECIPE_PENDING tells it what the operator selected; RECIPE_LOAD puts the recipe in.

RECIPE_LOAD(group, name) checks the whole recipe first; if any value is bad, nothing is written and it answers FALSE. Then it assigns every member inline, in the calling scan, storing each value the way GVL_Recipe_Mixer.speed_sp := 1250.0; does (same store, and a constant is refused before anything is written, as an assignment refuses it; it is not the whole statement evaluator, because members are plain scalars), so the whole recipe lands between two statements of your program:

  • when it returns TRUE every value is in, and the very next statement can use them;
  • RECIPE_ACTIVE already answers the new name on the next statement;
  • the pending selection is cleared if it named this recipe;
  • it behaves the same with scan_boundary_writes on or off (it does not use the external-write path that queues for the next scan).

Members the recipe file does not mention (added to the GVL after it was saved) keep their values.

Keep triggers and handshake flags OUT of the recipe group. Every program scope IS a possible group: its group is every scalar variable that program declares. MixerControl is one too; the example simply never uses it as a group. If it did (RECIPE_SAVE('MixerControl', …)), its own start_cmd, running and ok would be recipe members: a save would capture start_cmd as TRUE, and a load would write it back and start the batch again. The example below is built the safe way: the recipe group is the GVL GVL_Recipe_Mixer (only parameters in it), and every flag lives in the program MixerControl. Do the same: parameters in a GVL, triggers in the program. Constants are never part of a group — a program's VAR CONSTANT, a named GVL's VAR_GLOBAL CONSTANT (GVL_X) and an anonymous VAR_GLOBAL CONSTANT alike: they are reported as skipped, and a recipe file naming one is refused (the constant keeps its value). A constant is refused by the variable writes of ST and of SetVariable, not only recipes: an ST assignment (a VAR_EXTERNAL alias of a GVL constant included, and an element or member of a constant array or struct), a FOR over it, passing it to a VAR_IN_OUT (the task faults, as for an assignment), and an external write through SetVariable (the REST variable write answers 409) all leave it untouched, as does a function block's own VAR CONSTANT. What is judged is the storage the write lands on, not the name: your program's own variable named like a library constant (a VAR_OUTPUT LOG_SIZE beside OSCAT's LOG_SIZE) is your program's, writable, and addressed from outside as YourProgram.LOG_SIZE (the bare LOG_SIZE is the library constant). Not covered: a write through a pointer (p^ := v), writes by address, writers that bypass SetVariable (the I/O bus, the failover standby import), a compute-tier task's compiled body (not verified), and a VAR CONSTANT inside a FUNCTION, a METHOD, or a function block called inside an expression. The full list is in docs/features/recipes.md.

One task should own each recipe GVL. The load is atomic for the program that calls it. Another task that reads the same GVL is not paused, so keep the recipe GVL's readers in the task that loads it. A member the calling task cannot see (a program-scope group of another task) makes RECIPE_LOAD refuse: FALSE, nothing written.

Call RECIPE_LOAD on an edge. Every call is one audit row and reads the recipe file. The example below loads once per selection: a successful load clears the pending selection it names, and a program that cannot apply a selection drops it with RECIPE_CLEAR_PENDING instead of retrying every scan.

A complete example​

It passes POST /api/programs/validate on a v1.0.1684 instance, and is the program the guide's test bench ran:

PROGRAM MixerControl
VAR
running : BOOL := FALSE; (* a batch is running: not a safe point *)
start_cmd : BOOL := FALSE; (* raised by the operator / sequence *)
stop_cmd : BOOL := FALSE;
sel : STRING := ''; (* the operator's pending selection *)
ok : BOOL := FALSE;
loaded : STRING := ''; (* what RECIPE_ACTIVE says right after a load *)
load_count : DINT := 0;
refuse_count: DINT := 0;
speed_now : REAL := 0.0; (* working setpoints the process uses *)
temp_now : REAL := 0.0;
time_now : TIME := T#0s;
water_now : BOOL := FALSE;
END_VAR
(* 1. Apply a selection ONLY at a safe point. RECIPE_PENDING is the cue;
RECIPE_LOAD is the act. It checks the whole recipe first (nothing is
written if any value is bad) and then puts every member in, between
two statements of this program. The load clears the pending selection
when it names this recipe, so this branch runs once per selection. *)
sel := RECIPE_PENDING('GVL_Recipe_Mixer');
IF NOT running AND sel <> '' THEN
ok := RECIPE_LOAD('GVL_Recipe_Mixer', sel);
IF ok THEN
load_count := load_count + 1;
loaded := RECIPE_ACTIVE('GVL_Recipe_Mixer'); (* already the new name *)
ELSE
refuse_count := refuse_count + 1;
ok := RECIPE_CLEAR_PENDING('GVL_Recipe_Mixer'); (* refuse it, do not retry every scan *)
END_IF;
END_IF;

(* 2. Batch start copies the loaded recipe into the working setpoints. *)
IF start_cmd AND NOT running THEN
running := TRUE;
speed_now := GVL_Recipe_Mixer.speed_sp;
temp_now := GVL_Recipe_Mixer.temp_sp;
time_now := GVL_Recipe_Mixer.mix_time;
water_now := GVL_Recipe_Mixer.add_water;
start_cmd := FALSE;
END_IF;
IF stop_cmd THEN
running := FALSE;
stop_cmd := FALSE;
END_IF;
END_PROGRAM

While running is TRUE an operator can select Gentle: the pending selection is recorded and shown on the page, nothing on the machine changes, and when the batch ends the program loads it at its next scan. On the bench: before, speed_sp 1200; the operator (operator1) selected Fast; the program loaded it on its next scan (speed_sp 1800, stages 5, batch_id FAST, RECIPE_ACTIVE = Fast in the same scan); the audit log then held recipe.selected by operator1 and recipe.loaded by st:mixercontrol.

3. From ST​

FunctionReturns
RECIPE_PENDING(group)STRING. The operator's pending selection; '' if none.
RECIPE_LOAD(group, name)BOOL. TRUE: every value is in. FALSE: missing file or group, a failed check (including a recipe that names a constant), a member this task cannot see, or the service's queue is full (nothing written in every case; the reasons are in the runtime log and RECIPE_LAST_ERROR). An empty recipe name is refused up front: FALSE, a log line, nothing in RECIPE_LAST_ERROR.
RECIPE_CLEAR_PENDING(group)BOOL. Drop the pending selection without loading it. TRUE if there was one. FALSE when there was none, and also when the service's queue is busy (nothing changed, RECIPE_LAST_ERROR says so): the example's refuse branch would then try again on the next scan, because the selection is still pending.
RECIPE_SAVE(group, name)BOOL. Saves the live values of every member. TRUE = valid and accepted, not yet written: the service writes the file a moment later, so a RECIPE_LOAD in the same scan would not see it, and a failed write (disk full) shows only in RECIPE_LAST_ERROR. FALSE also when the service's queue is full, and for an empty name (refused up front; a log line only).
RECIPE_DELETE(group, name)BOOL. TRUE = it exists and the delete is accepted (a failure shows in RECIPE_LAST_ERROR). FALSE also when the queue is full, and for an empty name (refused up front; a log line only).
RECIPE_EXISTS(group, name)BOOL
RECIPE_COUNT(group)INT
RECIPE_NAME(group, index)STRING. The index-th recipe name, sorted, 0-based; '' out of range.
RECIPE_ACTIVE(group)STRING. The recipe last loaded; '' if none (also '' when the loaded recipe was deleted before its record was written).
RECIPE_LAST_ERROR(group)STRING. Why the group's last recipe call failed, and about which recipe. Only a later success on the same recipe name clears it (a RECIPE_CLEAR_PENDING that answered FALSE because the queue was busy names no recipe: the next RECIPE_CLEAR_PENDING that does not fail clears it). '' means no failure is standing; it is NOT a completion signal: right after an accepted RECIPE_SAVE, '' can mean "written" or "not run yet", and there is no call that says which. To confirm a FIRST save, wait for RECIPE_EXISTS(group, name) to become TRUE; for an overwrite or a delete there is no signal beyond '' staying '' for a few scans.

All arguments are STRING except index, which is INT. RECIPE_PENDING, RECIPE_COUNT, RECIPE_NAME, RECIPE_ACTIVE and RECIPE_EXISTS read an in-memory index (plus a few stat calls for changes from outside) and are cheap enough to call every scan (the example calls RECIPE_PENDING every scan). RECIPE_LOAD, RECIPE_SAVE and RECIPE_DELETE read or write files: call them on an edge. A RECIPE_SAVE from ST is the simplest way to keep "the current settings" as a named recipe when a batch completes.

The calls act as st:<program> in the audit log (here st:mixercontrol).

4. From the operator screen​

/hmi/recipes lists a group's recipes and, for the one you pick, a table of member | type | recipe value | live value | match, so you can see whether the machine is running what the recipe says. The header shows the recipe the program last loaded (who, when) and the pending selection (who selected it, when) with a Clear button. Select for loading asks the program to load the recipe; the page says plainly that nothing has been written to the machine yet. A recipe that fails the check lists every failure in red and selects nothing. Save captures the live values under a name (an existing name is kept as <name>.json.bak first). Copy, Rename and Delete manage the files. A bad folder under recipes/ shows as a warning on its own row and never hides the rest.

5. From HTTP​

RouteRoleWhat
GET /api/recipesviewerGroups that have recipes: count, active, pending, warning.
GET /api/recipes/{group}viewerThe group's recipes, active and pending selection, and its members with declared type and live value.
GET /api/recipes/{group}/{name}viewerOne recipe, compared per member with the live values.
PUT /api/recipes/{group}/{name}operatorSave: {"from":"live"} or {"values":{...}} (checked like a load).
POST /api/recipes/{group}/{name}/selectoperatorSelect for loading (checked; writes no tag).
DELETE /api/recipes/{group}/pendingoperatorClear the pending selection.
POST /api/recipes/{group}/{name}/copy and /renameoperatorBody {"to":"<name>"}.
DELETE /api/recipes/{group}/{name}engineerDelete.

There is deliberately no route that loads a recipe into the machine: only the program does that.

# capture the live values as a recipe
curl -X PUT http://host:8302/api/recipes/GVL_Recipe_Mixer/Standard -d '{"from":"live"}'
# save chosen values; the stored form is canonical ("1800" becomes 1800)
curl -X PUT http://host:8302/api/recipes/GVL_Recipe_Mixer/Fast \
-d '{"values":{"speed_sp":"1800","mix_time":"T#2m","stages":5}}'
# the operator selects it; the program applies it at its next safe point
curl -X POST http://host:8302/api/recipes/GVL_Recipe_Mixer/Fast/select

A select that fails the check answers 422 with the whole list, and nothing is selected:

{"error": "recipe refused, nothing written (3 problem(s)): ...",
"failures": [{"member": "stages", "reason": "INT value 70000 is out of range"},
{"member": "temp_sp", "reason": "REAL expects a number, got the text \"hot\""},
{"member": "no_such_member", "reason": "not a member of GVL_Recipe_Mixer"}]}

Other answers: 400 for an unusable name, 404 for a missing group or recipe, 409 when a copy or rename target exists.

6. Names and safety​

  • A recipe or group name may not be empty, contain / or \, contain .., start with a dot, contain a control character, contain ", ', <, > or a backtick, or exceed 128 bytes. A group may not end in a dot. A recipe may not be called pending.
  • All file access is confined to <paths.data>/recipes; a path that leaves it or crosses a symlink is refused. The recipes page builds its DOM as text, never as HTML.
  • Every select, clear, load, save, delete, copy and rename is written to the audit log (GET /api/audit) with who did it: recipe.selected, recipe.pending_cleared, recipe.loaded, recipe.saved, recipe.deleted, recipe.copied, recipe.renamed. The audit row's resource is recipes:<group>/<name>. Because the program's load is a call in your ST, one recipe.loaded row per call: call it on an edge.
  • The TIME type is written as an IEC literal: "mix_time": "T#1m45s". A number for a TIME is read as milliseconds, the same as ST arithmetic and a numeric variable write do, so a recipe saved from live values always loads even when a TIME holds a plain millisecond count. A fractional number of milliseconds is refused.
  • {"values":{}} (a save with nothing in it) is refused with 422, so a slip cannot replace a recipe with an empty one. A recipe file that is not valid JSON answers 422; a file that names one member in two spellings that differ only in case (Speed and speed) is refused as ambiguous.

7. Fred (MCP)​

controlforge_recipe_list and controlforge_recipe_get read; Fred may use them while read-only. controlforge_recipe_select and controlforge_recipe_save change state and follow the same roles and checks as the API; controlforge_recipe_select writes no tag, it only cues the program. There is no tool that loads a recipe.