昔日使用1200竟无Graph,故欲写此程序,现疑惑不解之处,望友人指点迷津!
1.顺控步序号为0..63,但出现并行分支时(例如3,4同时执行),步序号应如何显示,采用怎样编程思路?
2.使用for循环监控时,为何变量显示始终为1,见下图

3.当程序内步序号出现并行分支时,按我的想法从步序0..63开始检索当前步序,为何监控出现下图情况,疑惑不解。

程序原代码如下,可另存为Scl文件格式后到人TIA。
FUNCTION_BLOCK "SK10N"
TITLE = Standard Sequncen Function
{ S7_Optimized_Access := 'FALSE' }
AUTHOR : MICROT
FAMILY : 'S7-1200'
VERSION : 0.1
VAR_INPUT
Clock_10Hz : Bool; // Clock 10Hz input
DBNo_Mode : DB_ANY := 10; // Memory Flag DB number for Mode
END_VAR
VAR_OUTPUT
CurrentNum : Int; // The current running step number
END_VAR
VAR
S10 : Struct // S10 Status
HP : Bool; // Home Position
ACT : Bool; // Step Actived
HE : Bool; // Memory assistance Flag write "homing error"
StartCond : Bool; // Start condition
END_STRUCT;
S10N : Array[0..63] of Bool; // S10 Step Number
S10HP : Array[0..63] of Bool := 64(true); // S10 Homeposition status
Delay : DInt; // delay setting
clock10_M : Bool; // Clock Memory bit
clock10_FP : Bool; // Clock FP
END_VAR
VAR_TEMP
T_W : Bool; // Step mode switch condition
i : Int; // Step number temporary variable
END_VAR
BEGIN
(*
使用此功能块注意事项:
1.请设置Home位置状态,如不设置默认状态OK.
2.如需要Homing动作程序请在Homing program区编写.
3.Sequncen有效步序区为Step1-Step62,如需扩展请使用生成程序.
4.定时计数以100ms为单位,其延时设定与输入Clock_Hz有关.
*)
//set homeposition status*
#S10HP[0] := TRUE;
#S10HP[1] := TRUE;
#S10HP[2] := TRUE;
//......
For #i := 0 To 63 By 1 Do //Check homeposition status
If #S10HP[#i] Then
#S10.HP := TRUE;
Else
#S10.HP := FALSE;
Exit;
End_If;
End_For;
//sequence Mode judgment & Start condition & Initialization step setting
#T_W := #DBNo_Mode.%DBX2.0;
If Not #S10.ACT And #S10.HP And
(#DBNo_Mode.%DBX0.4 Or (#DBNo_Mode.%DBX0.2 And #T_W)) And Not #DBNo_Mode.%DBX0.1
Then
#S10.StartCond := TRUE;
Else
#S10.StartCond := FALSE;
End_If;
If (Not #S10N[0] And Not #S10.ACT) Or #S10N[63] Then
#S10N[0] := TRUE;
#S10N[63] := FALSE;
End_If;
#clock10_FP := #Clock_10Hz And Not #clock10_M;
#clock10_M := #Clock_10Hz;
If #clock10_FP And #S10.ACT And #T_W Then
#Delay := #Delay + 1;
End_If;
//Homing Program*
//
//Sequncen Program
//Step0:Initialization step
If #S10N[0] And #T_W And #S10.StartCond Then
#S10N[1] := TRUE;
#S10N[0] := FALSE;
#Delay := 0;
End_If;
//Step1:Sequnce Start*..
If #S10N[1] And #T_W Then
//
//
If #Delay >= 300 Then
#S10N[2] := TRUE;
#S10N[1] := FALSE;
#Delay := 0;
End_If;
End_If;
//Step2:
If #S10N[2] And #T_W Then
//
//
If #Delay >= 300 Then
#S10N[3] := TRUE;
#S10N[4] := TRUE;
#S10N[2] := FALSE;
#Delay := 0;
End_If;
End_If;
//Step3:
If #S10N[3] And #T_W Then
//
//
If #Delay >= 300 Then
//#S10N[4] := TRUE;
#S10N[3] := FALSE;
#Delay := 0;
End_If;
End_If;
//Step4:
If #S10N[4] And #T_W Then
//
//
If #Delay >= 300 Then
#S10N[5] := TRUE;
#S10N[4] := FALSE;
#Delay := 0;
End_If;
End_If;
//Step5:
If #S10N[5] And #T_W Then
//
//
If #Delay >= 300 Then
#S10N[62] := TRUE;
#S10N[5] := FALSE;
#Delay := 0;
End_If;
End_If;
//Step62:Sequence End..*
If #S10N[62] And #T_W Then
//
//
If #Delay >= 300 Then
#S10N[63] := TRUE;
#S10N[62] := FALSE;
#Delay := 0;
End_If;
End_If;
// Step63:Homeposition reached
If #S10N[63] And #T_W Then
#S10N[0] := TRUE;
#S10N[63] := FALSE;
#Delay := 0;
End_If;
For #i := 1 To 63 By 1 //Traverse the activated state
Do
If #S10N[#i] Then
#S10.ACT := TRUE;
Exit;
Else
#S10.ACT := FALSE;
End_If;
End_For;
If #DBNo_Mode.%DBX0.1 Then //Initialization step number when home press-button
For #i := 1 To 63 By 1
Do
#S10N[#i] := FALSE;
End_For;
End_If;
For #i := 1 To 63 By 1 //currentNumber display
Do
If #S10.ACT And (#Delay >5)And #S10N[#i] Then
#CurrentNum := #i;
ElsIf Not #S10.ACT Then
#CurrentNum := 0;
End_If;
End_For;
END_FUNCTION_BLOCK