You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

795 lines
24 KiB

FUNCTION_BLOCK BS_Schedule
VAR_EXTERNAL
END_VAR
VAR_INPUT
W1SCH_str :STRING;
W2SCH_str :STRING;
W3SCH_str :STRING;
W4SCH_str :STRING;
W5SCH_str :STRING;
W6SCH_str :STRING;
W7SCH_str :STRING;
W1SCH :ARRAY[1..4] OF TimeConfig;
W2SCH :ARRAY[1..4] OF TimeConfig;
W3SCH :ARRAY[1..4] OF TimeConfig;
W4SCH :ARRAY[1..4] OF TimeConfig;
W5SCH :ARRAY[1..4] OF TimeConfig;
W6SCH :ARRAY[1..4] OF TimeConfig;
W7SCH :ARRAY[1..4] OF TimeConfig;
EnableNum :INT;
Enable :BOOL;
Delay :INT;
Mode :INT;
InputMode :INT;
END_VAR
VAR_OUTPUT
TimeSw1 :BOOL;
TimeSw2 :BOOL;
TimeSw3 :BOOL;
TimeSw4 :BOOL;
OUT_Z :BOOL;
END_VAR
VAR
BS_Schedule_Str_W :STRING;
BS_Schedule_Str_R :ARRAY[0..60] OF BYTE;
WXSCH :ARRAY[1..4] OF TimeConfig;
Enable1th :BOOL;
Enable2th :BOOL;
Enable3th :BOOL;
Enable4th :BOOL;
OnH1th :INT:=0;
OnM1th :INT:=0;
OffH1th :INT:=0;
OffM1th :INT:=0;
OnH2th :INT:=0;
OnM2th :INT:=0;
OffH2th :INT:=0;
OffM2th :INT:=0;
OnH3th :INT:=0;
OnM3th :INT:=0;
OffH3th :INT:=0;
OffM3th :INT:=0;
OnH4th :INT:=0;
OnM4th :INT:=0;
OffH4th :INT:=0;
OffM4th :INT:=0;
HOUR :byte;
YEAR :word;
MON :byte;
DAY :byte;
MI :byte;
SEC :byte;
WEEK :byte;
WD_HOUR :INT;
WD_MI :INT;
SetCompare1th :BOOL; (*1反之为0*)
TrueSetCloseCompare1th :BOOL; (*1反之为0*)
TrueSetOpenCompare1th :BOOL; (*1反之为0*)
SetCompare2th :BOOL; (*1反之为0*)
TrueSetCloseCompare2th :BOOL; (*1反之为0*)
TrueSetOpenCompare2th :BOOL; (*1反之为0*)
SetCompare3th :BOOL; (*1反之为0*)
TrueSetCloseCompare3th :BOOL; (*1反之为0*)
TrueSetOpenCompare3th :BOOL; (*1反之为0*)
SetCompare4th :BOOL; (*1反之为0*)
TrueSetCloseCompare4th :BOOL; (*1反之为0*)
TrueSetOpenCompare4th :BOOL; (*1反之为0*)
ini : BOOL;
str_ini :STRING;
(* C2版本
v2m1 :AdvVarToMem;
m2v1 :AdvMemToVar;
Clock : AdvGetDateTime;
*)
(* C4版本 *)
Clock : NW_DateTimeGet;
p1,p2 : pointer;
v2v : NW_MemCopy;
END_VAR
(*
20201028
1.5
1.1 支持最多7天4段式时间开关控制使
1.2 优化程序方式C4版本CPU
1.3 合并周
1.4 增加时间输入参数为变量的方式
1.5 时间输入参数为变量的方式bug修复
4
1 营业准备
2 营业
3 营业
4 闭店准备
BS_ASCII2INT
*)
(*
Input_Type: 输入 WXSCH_str X=1~7,4组时间00000000 00000000 00000000 00000000
WXSCH X=1~7,4组时间分别为
WXSCH[1].OnH,WXSCH[1].OnM,WXSCH[1].OffH,WXSCH[1].OffM
WXSCH[2].OnH,WXSCH[2].OnM,WXSCH[2].OffH,WXSCH[2].OffM
WXSCH[3].OnH,WXSCH[3].OnM,WXSCH[3].OffH,WXSCH[3].OffM
WXSCH[4].OnH,WXSCH[4].OnM,WXSCH[4].OffH,WXSCH[4].OffM
EnableNum 排程启用数量
Enable 排程启用
Delay 延时补偿
Mode 模式0 W1SCH_str~W7SCH_str 对应周一~
1 节假日模式 W1SCH_str 对应工作日 W2SCH_str 对应节假日时间设置
2 日模式 W1SCH_str 对应每日时间设置
InputMode 模式0
1 变量输入
Output_Type: 输出 TimeSw1 排程1输出
TimeSw2 排程2输出
TimeSw3 排程3输出
TimeSw4 排程4输出
OUT_Z 整体输出
*)
(* *)
Clock( EN:=1 , B_TWELVE_HOUR:=0 | YEAR:= W_YEAR, MON:= BY_MONTH, DAY:= BY_DAY, HOUR:= BY_HOUR,MI := BY_MIN, SEC:= BY_SEC,WEEK := BY_WDAY );
WD_HOUR:=BYTE_TO_int(HOUR);
WD_MI:=BYTE_TO_int(MI);
(**)
(************************************** *********************************************)
if InputMode=0 then
if Mode=0 then
(* *)
if WEEK=1 then
if W1SCH_str<>'' then
BS_Schedule_Str_W :=W1SCH_str;
end_if;
end_if;
if WEEK=2 then
if W2SCH_str<>'' then
BS_Schedule_Str_W :=W2SCH_str;
end_if;
end_if;
if WEEK=3 then
if W3SCH_str<>'' then
BS_Schedule_Str_W :=W3SCH_str;
end_if;
end_if;
if WEEK=4 then
if W4SCH_str<>'' then
BS_Schedule_Str_W :=W4SCH_str;
end_if;
end_if;
if WEEK=5 then
if W5SCH_str<>'' then
BS_Schedule_Str_W :=W5SCH_str;
end_if;
end_if;
if WEEK=6 then
if W6SCH_str<>'' then
BS_Schedule_Str_W :=W6SCH_str;
end_if;
end_if;
if WEEK=7 then
if W7SCH_str<>'' then
BS_Schedule_Str_W :=W7SCH_str;
end_if;
end_if;
end_if;
(*,1~47为工作日56为节假日*)
if Mode=1 then
if WEEK=7 or WEEK<=4 then
if W1SCH_str<>'' then
BS_Schedule_Str_W :=W1SCH_str;
end_if;
end_if;
if WEEK>=5 and WEEK<=6 then
if W2SCH_str<>'' then
BS_Schedule_Str_W :=W2SCH_str;
end_if;
end_if;
end_if;
(**)
if Mode=2 then
if W1SCH_str<>'' then
BS_Schedule_Str_W :=W1SCH_str;
end_if;
end_if;
(**)
(* C2版本
v2m1(EN :=1 , DW_MEM_ADDR :=7000 , W_MAXNUM :=32 , STR_FILENAME :='VAR_str' , STR_VARNAME :='BS_Schedule_Str_W' );
m2v1(EN :=1 , DW_MEM_ADDR :=7000 , W_MEM_LEN :=32 , STR_FILENAME :='VAR_str' , STR_VARNAME :='BS_Schedule_Str_R' );
*)
(* C4版本 *)
p1:=&BS_Schedule_Str_W;
p2:=&BS_Schedule_Str_R;
v2v(DEST :=p2 , SRC :=p1 , LENGTH :=32 , IQM :=0 );
(**)
if BS_ASCII2INT(BS_Schedule_Str_R[ 0],BS_Schedule_Str_R[ 1])<0 then OnH1th:=0; elsif BS_ASCII2INT(BS_Schedule_Str_R[ 0],BS_Schedule_Str_R[ 1]) >23 then OnH1th:=23; else OnH1th:=BS_ASCII2INT(BS_Schedule_Str_R[ 0],BS_Schedule_Str_R[ 1]) ; end_if;
if BS_ASCII2INT(BS_Schedule_Str_R[ 2],BS_Schedule_Str_R[ 3])<0 then OnM1th:=0; elsif BS_ASCII2INT(BS_Schedule_Str_R[ 2],BS_Schedule_Str_R[ 3])+Delay>59 then OnM1th:=59; else OnM1th:=BS_ASCII2INT(BS_Schedule_Str_R[ 2],BS_Schedule_Str_R[ 3])+Delay; end_if;
if BS_ASCII2INT(BS_Schedule_Str_R[ 4],BS_Schedule_Str_R[ 5])<0 then OffH1th:=0; elsif BS_ASCII2INT(BS_Schedule_Str_R[ 4],BS_Schedule_Str_R[ 5]) >23 then OffH1th:=23; else OffH1th:=BS_ASCII2INT(BS_Schedule_Str_R[ 4],BS_Schedule_Str_R[ 5]) ; end_if;
if BS_ASCII2INT(BS_Schedule_Str_R[ 6],BS_Schedule_Str_R[ 7])<0 then OffM1th:=0; elsif BS_ASCII2INT(BS_Schedule_Str_R[ 6],BS_Schedule_Str_R[ 7])+Delay>59 then OffM1th:=59; else OffM1th:=BS_ASCII2INT(BS_Schedule_Str_R[ 6],BS_Schedule_Str_R[ 7])+Delay; end_if;
if BS_ASCII2INT(BS_Schedule_Str_R[ 8],BS_Schedule_Str_R[ 9])<0 then OnH2th:=0; elsif BS_ASCII2INT(BS_Schedule_Str_R[ 8],BS_Schedule_Str_R[ 9]) >23 then OnH2th:=23; else OnH2th:=BS_ASCII2INT(BS_Schedule_Str_R[ 8],BS_Schedule_Str_R[ 9]) ; end_if;
if BS_ASCII2INT(BS_Schedule_Str_R[10],BS_Schedule_Str_R[11])<0 then OnM2th:=0; elsif BS_ASCII2INT(BS_Schedule_Str_R[10],BS_Schedule_Str_R[11])+Delay>59 then OnM2th:=59; else OnM2th:=BS_ASCII2INT(BS_Schedule_Str_R[10],BS_Schedule_Str_R[11])+Delay; end_if;
if BS_ASCII2INT(BS_Schedule_Str_R[12],BS_Schedule_Str_R[13])<0 then OffH2th:=0; elsif BS_ASCII2INT(BS_Schedule_Str_R[12],BS_Schedule_Str_R[13]) >23 then OffH2th:=23; else OffH2th:=BS_ASCII2INT(BS_Schedule_Str_R[12],BS_Schedule_Str_R[13]) ; end_if;
if BS_ASCII2INT(BS_Schedule_Str_R[14],BS_Schedule_Str_R[15])<0 then OffM2th:=0; elsif BS_ASCII2INT(BS_Schedule_Str_R[14],BS_Schedule_Str_R[15])+Delay>59 then OffM2th:=59; else OffM2th:=BS_ASCII2INT(BS_Schedule_Str_R[14],BS_Schedule_Str_R[15])+Delay; end_if;
if BS_ASCII2INT(BS_Schedule_Str_R[16],BS_Schedule_Str_R[17])<0 then OnH3th:=0; elsif BS_ASCII2INT(BS_Schedule_Str_R[16],BS_Schedule_Str_R[17]) >23 then OnH3th:=23; else OnH3th:=BS_ASCII2INT(BS_Schedule_Str_R[16],BS_Schedule_Str_R[17]) ; end_if;
if BS_ASCII2INT(BS_Schedule_Str_R[18],BS_Schedule_Str_R[19])<0 then OnM3th:=0; elsif BS_ASCII2INT(BS_Schedule_Str_R[18],BS_Schedule_Str_R[19])+Delay>59 then OnM3th:=59; else OnM3th:=BS_ASCII2INT(BS_Schedule_Str_R[18],BS_Schedule_Str_R[19])+Delay; end_if;
if BS_ASCII2INT(BS_Schedule_Str_R[20],BS_Schedule_Str_R[21])<0 then OffH3th:=0; elsif BS_ASCII2INT(BS_Schedule_Str_R[20],BS_Schedule_Str_R[21]) >23 then OffH3th:=23; else OffH3th:=BS_ASCII2INT(BS_Schedule_Str_R[20],BS_Schedule_Str_R[21]) ; end_if;
if BS_ASCII2INT(BS_Schedule_Str_R[22],BS_Schedule_Str_R[23])<0 then OffM3th:=0; elsif BS_ASCII2INT(BS_Schedule_Str_R[22],BS_Schedule_Str_R[23])+Delay>59 then OffM3th:=59; else OffM3th:=BS_ASCII2INT(BS_Schedule_Str_R[22],BS_Schedule_Str_R[23])+Delay; end_if;
if BS_ASCII2INT(BS_Schedule_Str_R[24],BS_Schedule_Str_R[25])<0 then OnH4th:=0; elsif BS_ASCII2INT(BS_Schedule_Str_R[24],BS_Schedule_Str_R[25]) >23 then OnH4th:=23; else OnH4th:=BS_ASCII2INT(BS_Schedule_Str_R[24],BS_Schedule_Str_R[25]) ; end_if;
if BS_ASCII2INT(BS_Schedule_Str_R[26],BS_Schedule_Str_R[27])<0 then OnM4th:=0; elsif BS_ASCII2INT(BS_Schedule_Str_R[26],BS_Schedule_Str_R[27])+Delay>59 then OnM4th:=59; else OnM4th:=BS_ASCII2INT(BS_Schedule_Str_R[26],BS_Schedule_Str_R[27])+Delay; end_if;
if BS_ASCII2INT(BS_Schedule_Str_R[28],BS_Schedule_Str_R[29])<0 then OffH4th:=0; elsif BS_ASCII2INT(BS_Schedule_Str_R[28],BS_Schedule_Str_R[29]) >23 then OffH4th:=23; else OffH4th:=BS_ASCII2INT(BS_Schedule_Str_R[28],BS_Schedule_Str_R[29]) ; end_if;
if BS_ASCII2INT(BS_Schedule_Str_R[30],BS_Schedule_Str_R[31])<0 then OffM4th:=0; elsif BS_ASCII2INT(BS_Schedule_Str_R[30],BS_Schedule_Str_R[31])+Delay>59 then OffM4th:=59; else OffM4th:=BS_ASCII2INT(BS_Schedule_Str_R[30],BS_Schedule_Str_R[31])+Delay; end_if;
end_if;
(************************************** *********************************************)
if InputMode=1 then
if Mode=0 then
if WEEK=1 then
WXSCH[1].OnH :=W1SCH[1].OnH;
WXSCH[1].OnM :=W1SCH[1].OnM;
WXSCH[1].OffH:=W1SCH[1].OffH;
WXSCH[1].OffM:=W1SCH[1].OffM;
WXSCH[2].OnH :=W1SCH[2].OnH;
WXSCH[2].OnM :=W1SCH[2].OnM;
WXSCH[2].OffH:=W1SCH[2].OffH;
WXSCH[2].OffM:=W1SCH[2].OffM;
WXSCH[3].OnH :=W1SCH[3].OnH;
WXSCH[3].OnM :=W1SCH[3].OnM;
WXSCH[3].OffH:=W1SCH[3].OffH;
WXSCH[3].OffM:=W1SCH[3].OffM;
WXSCH[4].OnH :=W1SCH[4].OnH;
WXSCH[4].OnM :=W1SCH[4].OnM;
WXSCH[4].OffH:=W1SCH[4].OffH;
WXSCH[4].OffM:=W1SCH[4].OffM;
end_if;
if WEEK=2 then
WXSCH[1].OnH :=W2SCH[1].OnH;
WXSCH[1].OnM :=W2SCH[1].OnM;
WXSCH[1].OffH:=W2SCH[1].OffH;
WXSCH[1].OffM:=W2SCH[1].OffM;
WXSCH[2].OnH :=W2SCH[2].OnH;
WXSCH[2].OnM :=W2SCH[2].OnM;
WXSCH[2].OffH:=W2SCH[2].OffH;
WXSCH[2].OffM:=W2SCH[2].OffM;
WXSCH[3].OnH :=W2SCH[3].OnH;
WXSCH[3].OnM :=W2SCH[3].OnM;
WXSCH[3].OffH:=W2SCH[3].OffH;
WXSCH[3].OffM:=W2SCH[3].OffM;
WXSCH[4].OnH :=W2SCH[4].OnH;
WXSCH[4].OnM :=W2SCH[4].OnM;
WXSCH[4].OffH:=W2SCH[4].OffH;
WXSCH[4].OffM:=W2SCH[4].OffM;
end_if;
if WEEK=3 then
WXSCH[1].OnH :=W3SCH[1].OnH;
WXSCH[1].OnM :=W3SCH[1].OnM;
WXSCH[1].OffH:=W3SCH[1].OffH;
WXSCH[1].OffM:=W3SCH[1].OffM;
WXSCH[2].OnH :=W3SCH[2].OnH;
WXSCH[2].OnM :=W3SCH[2].OnM;
WXSCH[2].OffH:=W3SCH[2].OffH;
WXSCH[2].OffM:=W3SCH[2].OffM;
WXSCH[3].OnH :=W3SCH[3].OnH;
WXSCH[3].OnM :=W3SCH[3].OnM;
WXSCH[3].OffH:=W3SCH[3].OffH;
WXSCH[3].OffM:=W3SCH[3].OffM;
WXSCH[4].OnH :=W3SCH[4].OnH;
WXSCH[4].OnM :=W3SCH[4].OnM;
WXSCH[4].OffH:=W3SCH[4].OffH;
WXSCH[4].OffM:=W3SCH[4].OffM;
end_if;
if WEEK=4 then
WXSCH[1].OnH :=W4SCH[1].OnH;
WXSCH[1].OnM :=W4SCH[1].OnM;
WXSCH[1].OffH:=W4SCH[1].OffH;
WXSCH[1].OffM:=W4SCH[1].OffM;
WXSCH[2].OnH :=W4SCH[2].OnH;
WXSCH[2].OnM :=W4SCH[2].OnM;
WXSCH[2].OffH:=W4SCH[2].OffH;
WXSCH[2].OffM:=W4SCH[2].OffM;
WXSCH[3].OnH :=W4SCH[3].OnH;
WXSCH[3].OnM :=W4SCH[3].OnM;
WXSCH[3].OffH:=W4SCH[3].OffH;
WXSCH[3].OffM:=W4SCH[3].OffM;
WXSCH[4].OnH :=W4SCH[4].OnH;
WXSCH[4].OnM :=W4SCH[4].OnM;
WXSCH[4].OffH:=W4SCH[4].OffH;
WXSCH[4].OffM:=W4SCH[4].OffM;
end_if;
if WEEK=5 then
WXSCH[1].OnH :=W5SCH[1].OnH;
WXSCH[1].OnM :=W5SCH[1].OnM;
WXSCH[1].OffH:=W5SCH[1].OffH;
WXSCH[1].OffM:=W5SCH[1].OffM;
WXSCH[2].OnH :=W5SCH[2].OnH;
WXSCH[2].OnM :=W5SCH[2].OnM;
WXSCH[2].OffH:=W5SCH[2].OffH;
WXSCH[2].OffM:=W5SCH[2].OffM;
WXSCH[3].OnH :=W5SCH[3].OnH;
WXSCH[3].OnM :=W5SCH[3].OnM;
WXSCH[3].OffH:=W5SCH[3].OffH;
WXSCH[3].OffM:=W5SCH[3].OffM;
WXSCH[4].OnH :=W5SCH[4].OnH;
WXSCH[4].OnM :=W5SCH[4].OnM;
WXSCH[4].OffH:=W5SCH[4].OffH;
WXSCH[4].OffM:=W5SCH[4].OffM;
end_if;
if WEEK=6 then
WXSCH[1].OnH :=W6SCH[1].OnH;
WXSCH[1].OnM :=W6SCH[1].OnM;
WXSCH[1].OffH:=W6SCH[1].OffH;
WXSCH[1].OffM:=W6SCH[1].OffM;
WXSCH[2].OnH :=W6SCH[2].OnH;
WXSCH[2].OnM :=W6SCH[2].OnM;
WXSCH[2].OffH:=W6SCH[2].OffH;
WXSCH[2].OffM:=W6SCH[2].OffM;
WXSCH[3].OnH :=W6SCH[3].OnH;
WXSCH[3].OnM :=W6SCH[3].OnM;
WXSCH[3].OffH:=W6SCH[3].OffH;
WXSCH[3].OffM:=W6SCH[3].OffM;
WXSCH[4].OnH :=W6SCH[4].OnH;
WXSCH[4].OnM :=W6SCH[4].OnM;
WXSCH[4].OffH:=W6SCH[4].OffH;
WXSCH[4].OffM:=W6SCH[4].OffM;
end_if;
if WEEK=7 then
WXSCH[1].OnH :=W7SCH[1].OnH;
WXSCH[1].OnM :=W7SCH[1].OnM;
WXSCH[1].OffH:=W7SCH[1].OffH;
WXSCH[1].OffM:=W7SCH[1].OffM;
WXSCH[2].OnH :=W7SCH[2].OnH;
WXSCH[2].OnM :=W7SCH[2].OnM;
WXSCH[2].OffH:=W7SCH[2].OffH;
WXSCH[2].OffM:=W7SCH[2].OffM;
WXSCH[3].OnH :=W7SCH[3].OnH;
WXSCH[3].OnM :=W7SCH[3].OnM;
WXSCH[3].OffH:=W7SCH[3].OffH;
WXSCH[3].OffM:=W7SCH[3].OffM;
WXSCH[4].OnH :=W7SCH[4].OnH;
WXSCH[4].OnM :=W7SCH[4].OnM;
WXSCH[4].OffH:=W7SCH[4].OffH;
WXSCH[4].OffM:=W7SCH[4].OffM;
end_if;
end_if;
if Mode=1 then
if WEEK=7 or WEEK<=4 then
WXSCH[1].OnH :=W1SCH[1].OnH;
WXSCH[1].OnM :=W1SCH[1].OnM;
WXSCH[1].OffH:=W1SCH[1].OffH;
WXSCH[1].OffM:=W1SCH[1].OffM;
WXSCH[2].OnH :=W1SCH[2].OnH;
WXSCH[2].OnM :=W1SCH[2].OnM;
WXSCH[2].OffH:=W1SCH[2].OffH;
WXSCH[2].OffM:=W1SCH[2].OffM;
WXSCH[3].OnH :=W1SCH[3].OnH;
WXSCH[3].OnM :=W1SCH[3].OnM;
WXSCH[3].OffH:=W1SCH[3].OffH;
WXSCH[3].OffM:=W1SCH[3].OffM;
WXSCH[4].OnH :=W1SCH[4].OnH;
WXSCH[4].OnM :=W1SCH[4].OnM;
WXSCH[4].OffH:=W1SCH[4].OffH;
WXSCH[4].OffM:=W1SCH[4].OffM;
end_if;
if WEEK>=5 and WEEK<=6 then
WXSCH[1].OnH :=W2SCH[1].OnH;
WXSCH[1].OnM :=W2SCH[1].OnM;
WXSCH[1].OffH:=W2SCH[1].OffH;
WXSCH[1].OffM:=W2SCH[1].OffM;
WXSCH[2].OnH :=W2SCH[2].OnH;
WXSCH[2].OnM :=W2SCH[2].OnM;
WXSCH[2].OffH:=W2SCH[2].OffH;
WXSCH[2].OffM:=W2SCH[2].OffM;
WXSCH[3].OnH :=W2SCH[3].OnH;
WXSCH[3].OnM :=W2SCH[3].OnM;
WXSCH[3].OffH:=W2SCH[3].OffH;
WXSCH[3].OffM:=W2SCH[3].OffM;
WXSCH[4].OnH :=W2SCH[4].OnH;
WXSCH[4].OnM :=W2SCH[4].OnM;
WXSCH[4].OffH:=W2SCH[4].OffH;
WXSCH[4].OffM:=W2SCH[4].OffM;
end_if;
end_if;
if Mode=2 then
WXSCH[1].OnH :=W1SCH[1].OnH;
WXSCH[1].OnM :=W1SCH[1].OnM;
WXSCH[1].OffH:=W1SCH[1].OffH;
WXSCH[1].OffM:=W1SCH[1].OffM;
WXSCH[2].OnH :=W1SCH[2].OnH;
WXSCH[2].OnM :=W1SCH[2].OnM;
WXSCH[2].OffH:=W1SCH[2].OffH;
WXSCH[2].OffM:=W1SCH[2].OffM;
WXSCH[3].OnH :=W1SCH[3].OnH;
WXSCH[3].OnM :=W1SCH[3].OnM;
WXSCH[3].OffH:=W1SCH[3].OffH;
WXSCH[3].OffM:=W1SCH[3].OffM;
WXSCH[4].OnH :=W1SCH[4].OnH;
WXSCH[4].OnM :=W1SCH[4].OnM;
WXSCH[4].OffH:=W1SCH[4].OffH;
WXSCH[4].OffM:=W1SCH[4].OffM;
end_if;
if WXSCH[1].OnH <0 then OnH1th:=0; elsif WXSCH[1].OnH >23 then OnH1th:=23; else OnH1th:=WXSCH[1].OnH ; end_if;
if WXSCH[1].OnM <0 then OnM1th:=0; elsif WXSCH[1].OnM +Delay>59 then OnM1th:=59; else OnM1th:=WXSCH[1].OnM +Delay; end_if;
if WXSCH[1].OffH<0 then OffH1th:=0; elsif WXSCH[1].OffH >23 then OffH1th:=23; else OffH1th:=WXSCH[1].OffH ; end_if;
if WXSCH[1].OffM<0 then OffM1th:=0; elsif WXSCH[1].OffM+Delay>59 then OffM1th:=59; else OffM1th:=WXSCH[1].OffM+Delay; end_if;
if WXSCH[2].OnH <0 then OnH2th:=0; elsif WXSCH[2].OnH >23 then OnH2th:=23; else OnH2th:=WXSCH[2].OnH ; end_if;
if WXSCH[2].OnM <0 then OnM2th:=0; elsif WXSCH[2].OnM +Delay>59 then OnM2th:=59; else OnM2th:=WXSCH[2].OnM +Delay; end_if;
if WXSCH[2].OffH<0 then OffH2th:=0; elsif WXSCH[2].OffH >23 then OffH2th:=23; else OffH2th:=WXSCH[2].OffH ; end_if;
if WXSCH[2].OffM<0 then OffM2th:=0; elsif WXSCH[2].OffM+Delay>59 then OffM2th:=59; else OffM2th:=WXSCH[2].OffM+Delay; end_if;
if WXSCH[3].OnH <0 then OnH3th:=0; elsif WXSCH[3].OnH >23 then OnH3th:=23; else OnH3th:=WXSCH[3].OnH ; end_if;
if WXSCH[3].OnM <0 then OnM3th:=0; elsif WXSCH[3].OnM +Delay>59 then OnM3th:=59; else OnM3th:=WXSCH[3].OnM +Delay; end_if;
if WXSCH[3].OffH<0 then OffH3th:=0; elsif WXSCH[3].OffH >23 then OffH3th:=23; else OffH3th:=WXSCH[3].OffH ; end_if;
if WXSCH[3].OffM<0 then OffM3th:=0; elsif WXSCH[3].OffM+Delay>59 then OffM3th:=59; else OffM3th:=WXSCH[3].OffM+Delay; end_if;
if WXSCH[4].OnH <0 then OnH4th:=0; elsif WXSCH[4].OnH >23 then OnH4th:=23; else OnH4th:=WXSCH[4].OnH ; end_if;
if WXSCH[4].OnM <0 then OnM4th:=0; elsif WXSCH[4].OnM +Delay>59 then OnM4th:=59; else OnM4th:=WXSCH[4].OnM +Delay; end_if;
if WXSCH[4].OffH<0 then OffH4th:=0; elsif WXSCH[4].OffH >23 then OffH4th:=23; else OffH4th:=WXSCH[4].OffH ; end_if;
if WXSCH[4].OffM<0 then OffM4th:=0; elsif WXSCH[4].OffM+Delay>59 then OffM4th:=59; else OffM4th:=WXSCH[4].OffM+Delay; end_if;
end_if;
if EnableNum =1 then Enable1th :=1; Enable2th :=0; Enable3th :=0; Enable4th :=0; end_if;
if EnableNum =2 then Enable1th :=1; Enable2th :=1; Enable3th :=0; Enable4th :=0; end_if;
if EnableNum =3 then Enable1th :=1; Enable2th :=1; Enable3th :=1; Enable4th :=0; end_if;
if EnableNum =4 then Enable1th :=1; Enable2th :=1; Enable3th :=1; Enable4th :=1; end_if;
(*4段定时处理*)
if Enable=1 then
(* 4段排程*)
if Enable1th=TRUE and (not(OnH1th=OffH1th and OnM1th=OffM1th)) then(**)
(*1判断开关设定时间之间的大小*)
if OnH1th>OffH1th then
SetCompare1th := 1;
end_if;
if OnH1th<OffH1th then
SetCompare1th := 0;
end_if;
if OnH1th=OffH1th then
if OnM1th>OffM1th then
SetCompare1th := 1;
else
SetCompare1th := 0;
end_if;
end_if;
(*1判断开设定时间与实际时间之间的大小*)
if OnH1th>WD_HOUR then
TrueSetOpenCompare1th := 1;
end_if;
if OnH1th<WD_HOUR then
TrueSetOpenCompare1th := 0;
end_if;
if OnH1th=WD_HOUR then
if OnM1th>=WD_MI then
TrueSetOpenCompare1th := 1;
else
TrueSetOpenCompare1th := 0;
end_if;
end_if;
(*1判断关设定时间与实际时间之间的大小*)
if OffH1th>WD_HOUR then
TrueSetCloseCompare1th := 1;
end_if;
if OffH1th<WD_HOUR then
TrueSetCloseCompare1th := 0;
end_if;
if OffH1th=WD_HOUR then
if OffM1th>=WD_MI then
TrueSetCloseCompare1th := 1;
else
TrueSetCloseCompare1th := 0;
end_if;
end_if;
(*1控制输出*)
if SetCompare1th then(*1*)
if TrueSetOpenCompare1th and not (TrueSetCloseCompare1th) then
TimeSw1:=0;
else
TimeSw1:=1;
end_if;
else
if TrueSetCloseCompare1th and not (TrueSetOpenCompare1th) then
TimeSw1:=1;
else
TimeSw1:=0;
end_if;
end_if;
else
TimeSw1:=0;
end_if;
if Enable2th=TRUE and (not(OnH2th=OffH2th and OnM2th=OffM2th)) then(**)
(*2判断开关设定时间之间的大小*)
if OnH2th>OffH2th then
SetCompare2th := 1;
end_if;
if OnH2th<OffH2th then
SetCompare2th := 0;
end_if;
if OnH2th=OffH2th then
if OnM2th>OffM2th then
SetCompare2th := 1;
else
SetCompare2th := 0;
end_if;
end_if;
(*2判断开设定时间与实际时间之间的大小*)
if OnH2th>WD_HOUR then
TrueSetOpenCompare2th := 1;
end_if;
if OnH2th<WD_HOUR then
TrueSetOpenCompare2th := 0;
end_if;
if OnH2th=WD_HOUR then
if OnM2th>=WD_MI then
TrueSetOpenCompare2th := 1;
else
TrueSetOpenCompare2th := 0;
end_if;
end_if;
(*2判断关设定时间与实际时间之间的大小*)
if OffH2th>WD_HOUR then
TrueSetCloseCompare2th := 1;
end_if;
if OffH2th<WD_HOUR then
TrueSetCloseCompare2th := 0;
end_if;
if OffH2th=WD_HOUR then
if OffM2th>=WD_MI then
TrueSetCloseCompare2th := 1;
else
TrueSetCloseCompare2th := 0;
end_if;
end_if;
(*2控制输出*)
if SetCompare2th then(*1*)
if TrueSetOpenCompare2th and not (TrueSetCloseCompare2th) then
TimeSw2:=0;
else
TimeSw2:=1;
end_if;
else
if TrueSetCloseCompare2th and not (TrueSetOpenCompare2th) then
TimeSw2:=1;
else
TimeSw2:=0;
end_if;
end_if;
else
TimeSw2:=0;
end_if;
if Enable3th=TRUE and (not(OnH3th=OffH3th and OnM3th=OffM3th)) then(**)
(*3判断开关设定时间之间的大小*)
if OnH3th>OffH3th then
SetCompare3th := 1;
end_if;
if OnH3th<OffH3th then
SetCompare3th := 0;
end_if;
if OnH3th=OffH3th then
if OnM3th>OffM3th then
SetCompare3th := 1;
else
SetCompare3th := 0;
end_if;
end_if;
(*3判断开设定时间与实际时间之间的大小*)
if OnH3th>WD_HOUR then
TrueSetOpenCompare3th := 1;
end_if;
if OnH3th<WD_HOUR then
TrueSetOpenCompare3th := 0;
end_if;
if OnH3th=WD_HOUR then
if OnM3th>=WD_MI then
TrueSetOpenCompare3th := 1;
else
TrueSetOpenCompare3th := 0;
end_if;
end_if;
(*3判断关设定时间与实际时间之间的大小*)
if OffH3th>WD_HOUR then
TrueSetCloseCompare3th := 1;
end_if;
if OffH3th<WD_HOUR then
TrueSetCloseCompare3th := 0;
end_if;
if OffH3th=WD_HOUR then
if OffM3th>=WD_MI then
TrueSetCloseCompare3th := 1;
else
TrueSetCloseCompare3th := 0;
end_if;
end_if;
(*3控制输出*)
if SetCompare3th then(*1*)
if TrueSetOpenCompare3th and not (TrueSetCloseCompare3th) then
TimeSw3:=0;
else
TimeSw3:=1;
end_if;
else
if TrueSetCloseCompare3th and not (TrueSetOpenCompare3th) then
TimeSw3:=1;
else
TimeSw3:=0;
end_if;
end_if;
else
TimeSw3:=0;
end_if;
if Enable4th=TRUE and (not(OnH4th=OffH4th and OnM4th=OffM4th)) then(**)
(*4判断开关设定时间之间的大小*)
if OnH4th>OffH4th then
SetCompare4th := 1;
end_if;
if OnH4th<OffH4th then
SetCompare4th := 0;
end_if;
if OnH4th=OffH4th then
if OnM4th>OffM4th then
SetCompare4th := 1;
else
SetCompare4th := 0;
end_if;
end_if;
(*4判断开设定时间与实际时间之间的大小*)
if OnH4th>WD_HOUR then
TrueSetOpenCompare4th := 1;
end_if;
if OnH4th<WD_HOUR then
TrueSetOpenCompare4th := 0;
end_if;
if OnH4th=WD_HOUR then
if OnM4th>=WD_MI then
TrueSetOpenCompare4th := 1;
else
TrueSetOpenCompare4th := 0;
end_if;
end_if;
(*4判断关设定时间与实际时间之间的大小*)
if OffH4th>WD_HOUR then
TrueSetCloseCompare4th := 1;
end_if;
if OffH4th<WD_HOUR then
TrueSetCloseCompare4th := 0;
end_if;
if OffH4th=WD_HOUR then
if OffM4th>=WD_MI then
TrueSetCloseCompare4th := 1;
else
TrueSetCloseCompare4th := 0;
end_if;
end_if;
(*4控制输出*)
if SetCompare4th then(*1*)
if TrueSetOpenCompare4th and not (TrueSetCloseCompare4th) then
TimeSw4:=0;
else
TimeSw4:=1;
end_if;
else
if TrueSetCloseCompare4th and not (TrueSetOpenCompare4th) then
TimeSw4:=1;
else
TimeSw4:=0;
end_if;
end_if;
else
TimeSw4:=0;
end_if;
if TimeSw1 or TimeSw2 or TimeSw3 or TimeSw4 then
OUT_Z:=1;
else
OUT_Z:=0;
end_if;
end_if;
END_FUNCTION_BLOCK