如何控制不同ST代码块的执行顺序?
How do you control the order of executing different blocks of ST code?
我有一个包含 8 个步骤的工艺配方,我在 ST 中定义了每个步骤。但是,用户应该能够 select 这 8 个步骤的执行顺序。我正在尝试提出可用于此目的的标志或变量,但到目前为止还是一片空白。有人对如何实施有任何想法吗?
我的建议是让用户按照应该如何执行的顺序用步骤编号填充一个数组。然后将不同的 ST 代码块放入 CASE 语句中。对于 CASE 变量,使用数组。这样执行顺序就完全灵活了。
这里以三明治装饰器为例。重要部分从 E_SandwichDecoratorStep.RecipeExecution
开始
枚举:
TYPE E_SandwichDecoratorStep :
(
UserSelecting := 1,
RecipeExecution,
Finished
);
END_TYPE
TYPE E_SandwichDecoratorUserRecipe :
(
Pepperoni := 1,
Ham,
Cheese,
Tomato,
Salad,
Sauce,
Salt,
Pepper
);
END_TYPE
程序:
PROGRAM SANDWICHDECORATOR
VAR
arrnStepOrder : ARRAY[1..8] OF E_SandwichDecoratorStep; (*User Recipe Configuration*)
bRestart : BOOL;
bUserRecipeStart : BOOL; (*Start the execution of the Recipe*)
eCurStep : E_SandwichDecoratorStep;
nCurUserRecipeIndex : INT := 1;
END_VAR
CASE eCurStep OF
E_SandwichDecoratorStep.UserSelecting:
(*Example Order*)
arrnStepOrder[1] := E_SandwichDecoratorUserRecipe.Ham;
arrnStepOrder[2] := E_SandwichDecoratorUserRecipe.Tomato;
arrnStepOrder[3] := E_SandwichDecoratorUserRecipe.Pepperoni;
arrnStepOrder[4] := E_SandwichDecoratorUserRecipe.Cheese;
arrnStepOrder[5] := E_SandwichDecoratorUserRecipe.Salt;
arrnStepOrder[6] := E_SandwichDecoratorUserRecipe.Sauce;
arrnStepOrder[7] := E_SandwichDecoratorUserRecipe.Pepper;
arrnStepOrder[8] := E_SandwichDecoratorUserRecipe.Salad;
IF bUserRecipeStart THEN
bUserRecipeStart := FALSE;
eCurStep := E_SandwichDecoratorStep.RecipeExecution;
END_IF
E_SandwichDecoratorStep.RecipeExecution:
IF nCurUserRecipeIndex <= E_SandwichDecoratorUserRecipe.Pepper THEN
CASE arrnStepOrder[nCurUserRecipeIndex] OF
E_SandwichDecoratorUserRecipe.Pepperoni:
nCurUserRecipeIndex := nCurUserRecipeIndex + 1;
E_SandwichDecoratorUserRecipe.Ham:
nCurUserRecipeIndex := nCurUserRecipeIndex + 1;
E_SandwichDecoratorUserRecipe.Cheese:
nCurUserRecipeIndex := nCurUserRecipeIndex + 1;
E_SandwichDecoratorUserRecipe.Tomato:
nCurUserRecipeIndex := nCurUserRecipeIndex + 1;
E_SandwichDecoratorUserRecipe.Salad:
nCurUserRecipeIndex := nCurUserRecipeIndex + 1;
E_SandwichDecoratorUserRecipe.Sauce:
nCurUserRecipeIndex := nCurUserRecipeIndex + 1;
E_SandwichDecoratorUserRecipe.Salt:
nCurUserRecipeIndex := nCurUserRecipeIndex + 1;
E_SandwichDecoratorUserRecipe.Pepper:
nCurUserRecipeIndex := nCurUserRecipeIndex + 1;
END_CASE
ELSE
nCurUserRecipeIndex := 1;
eCurStep := E_SandwichDecoratorStep.Finished;
END_IF
E_SandwichDecoratorStep.Finished:
IF bRestart THEN
bRestart := FALSE;
eCurStep := E_SandwichDecoratorStep.UserSelecting;
END_IF
END_CASE
我有一个包含 8 个步骤的工艺配方,我在 ST 中定义了每个步骤。但是,用户应该能够 select 这 8 个步骤的执行顺序。我正在尝试提出可用于此目的的标志或变量,但到目前为止还是一片空白。有人对如何实施有任何想法吗?
我的建议是让用户按照应该如何执行的顺序用步骤编号填充一个数组。然后将不同的 ST 代码块放入 CASE 语句中。对于 CASE 变量,使用数组。这样执行顺序就完全灵活了。
这里以三明治装饰器为例。重要部分从 E_SandwichDecoratorStep.RecipeExecution
开始枚举:
TYPE E_SandwichDecoratorStep :
(
UserSelecting := 1,
RecipeExecution,
Finished
);
END_TYPE
TYPE E_SandwichDecoratorUserRecipe :
(
Pepperoni := 1,
Ham,
Cheese,
Tomato,
Salad,
Sauce,
Salt,
Pepper
);
END_TYPE
程序:
PROGRAM SANDWICHDECORATOR
VAR
arrnStepOrder : ARRAY[1..8] OF E_SandwichDecoratorStep; (*User Recipe Configuration*)
bRestart : BOOL;
bUserRecipeStart : BOOL; (*Start the execution of the Recipe*)
eCurStep : E_SandwichDecoratorStep;
nCurUserRecipeIndex : INT := 1;
END_VAR
CASE eCurStep OF
E_SandwichDecoratorStep.UserSelecting:
(*Example Order*)
arrnStepOrder[1] := E_SandwichDecoratorUserRecipe.Ham;
arrnStepOrder[2] := E_SandwichDecoratorUserRecipe.Tomato;
arrnStepOrder[3] := E_SandwichDecoratorUserRecipe.Pepperoni;
arrnStepOrder[4] := E_SandwichDecoratorUserRecipe.Cheese;
arrnStepOrder[5] := E_SandwichDecoratorUserRecipe.Salt;
arrnStepOrder[6] := E_SandwichDecoratorUserRecipe.Sauce;
arrnStepOrder[7] := E_SandwichDecoratorUserRecipe.Pepper;
arrnStepOrder[8] := E_SandwichDecoratorUserRecipe.Salad;
IF bUserRecipeStart THEN
bUserRecipeStart := FALSE;
eCurStep := E_SandwichDecoratorStep.RecipeExecution;
END_IF
E_SandwichDecoratorStep.RecipeExecution:
IF nCurUserRecipeIndex <= E_SandwichDecoratorUserRecipe.Pepper THEN
CASE arrnStepOrder[nCurUserRecipeIndex] OF
E_SandwichDecoratorUserRecipe.Pepperoni:
nCurUserRecipeIndex := nCurUserRecipeIndex + 1;
E_SandwichDecoratorUserRecipe.Ham:
nCurUserRecipeIndex := nCurUserRecipeIndex + 1;
E_SandwichDecoratorUserRecipe.Cheese:
nCurUserRecipeIndex := nCurUserRecipeIndex + 1;
E_SandwichDecoratorUserRecipe.Tomato:
nCurUserRecipeIndex := nCurUserRecipeIndex + 1;
E_SandwichDecoratorUserRecipe.Salad:
nCurUserRecipeIndex := nCurUserRecipeIndex + 1;
E_SandwichDecoratorUserRecipe.Sauce:
nCurUserRecipeIndex := nCurUserRecipeIndex + 1;
E_SandwichDecoratorUserRecipe.Salt:
nCurUserRecipeIndex := nCurUserRecipeIndex + 1;
E_SandwichDecoratorUserRecipe.Pepper:
nCurUserRecipeIndex := nCurUserRecipeIndex + 1;
END_CASE
ELSE
nCurUserRecipeIndex := 1;
eCurStep := E_SandwichDecoratorStep.Finished;
END_IF
E_SandwichDecoratorStep.Finished:
IF bRestart THEN
bRestart := FALSE;
eCurStep := E_SandwichDecoratorStep.UserSelecting;
END_IF
END_CASE