I have a process recipe with 8 steps, each of which I have defined in ST. The user should be able to however, select the order in which these 8 steps are executed. I'm trying to come up with flags or variables which could be used for this but drawing a blank so far. Does anyone have any thoughts on how this could be implemented?
1 回答
2
我的建议是让用户按照应该如何执行的顺序用步骤号填充一个数组。然后将不同的 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
于 2015-12-03T20:11:14.113 回答