1
我有8個步驟的過程配方,每個步驟都在ST中定義。然而,用戶應該能夠選擇執行這8個步驟的順序。我試圖想出可用於此的標誌或變量,但迄今爲止繪製了一個空白。有沒有人有任何想法如何實現這一點?你如何控制執行不同的ST代碼塊的順序?
我有8個步驟的過程配方,每個步驟都在ST中定義。然而,用戶應該能夠選擇執行這8個步驟的順序。我試圖想出可用於此的標誌或變量,但迄今爲止繪製了一個空白。有沒有人有任何想法如何實現這一點?你如何控制執行不同的ST代碼塊的順序?
我的建議是讓用戶按照應該如何執行的順序填充步驟編號。然後將您的不同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
我可以回答你的問題,但是你沒有告訴我我最後的答案出了什麼問題,或者接受了我之前給出的問題的最後一個答案。問候 –
我剛剛做到了。謝謝,你以前的回答對我的另一個問題很有幫助 – user2840240