FUNCTION_BLOCK IJ_LCB0610
VAR_EXTERNAL

END_VAR

VAR_INPUT

LOCK		 			:int:=0;
LightGroup_Input 	 	:array[0..6,0..10] of bool;
CM						:bool;
Delay					:time:=t#50ms;
END_VAR

VAR_OUTPUT

LightGroup_Output	 	:array[0..6,0..10] of bool;

END_VAR

VAR

LightGroup_OutputP  	:array[0..10] of bool;
LightGroup_InputP  		:array[0..10] of bool;
Delay_ton1	    		:ton;
Delay_ton2	    		:ton;
Delay_ton3	    		:ton;
Delay_ton4	    		:ton;
Delay_ton5	    		:ton;
Delay_ton6	    		:ton;
i						:int;
j1						:int;
j2						:int;
j3						:int;
j4						:int;
j5						:int;
j6						:int;
k						:int;

END_VAR
(* 

时  间:20200731
版  本:1.1
作  者:姚立
名  称:照明电控箱控制程序
说  明:
		CM 	为群组控制启用和失效 
		LOCK 为锁定模式 0不锁定 1锁定
		Delay 为回路延时设定,默认为50ms
		LightGroup_Input	照明分组变量输入 array[0..6,0..10]	前部分为分组,后部分为回路		
		LightGroup_Output	照明分组变量输出 array[0..6,0..10] 前部分为分组,后部分为回路	

		1.新云控制同步功能			
				
			CM=0     不接收群组控制
			CM=1	 接收群组控制
	
		2.延时赋值功能	
			用于变量延时批量赋值
			回路非锁输出,输出延时间隔可设定,默认50ms	
		
		3.控制锁定功能
			LOCK 0不锁定;非0锁定;
		
		
备  注:支持6种灯具分组,每种10组灯具;
依赖块:无

*)

(*DEMO
if CM =1 then

	if LightGroup_Input[x,0]<>LightGroup_InputP[x] then 
		LightGroup_Output[x,0]:=LightGroup_Input[x,0]; 
	end_if;
	
end_if;

if LightGroup_Output[x,0]<>LightGroup_OutputP[x] then
	
	Delay_tonx(PT :=Delay );
	Delay_tonx.in:= not Delay_tonx.q;
	if Delay_tonx.q=1 then
		j:=j+1;
		LightGroup_Output[x,j] :=LightGroup_Output[x,0]; 
		if j=30 then
		   j:=0;
		LightGroup_OutputP[x]:=LightGroup_Output[x,0];
		end_if;	
	end_if;	
	
else 
	if Lock=0 then
		LightGroup_Output[x,1] :=LightGroup_Input[x,1] ;
		LightGroup_Output[x,2] :=LightGroup_Input[x,2] ;	 
		LightGroup_Output[x,3] :=LightGroup_Input[x,3] ;	 
		LightGroup_Output[x,4] :=LightGroup_Input[x,4] ;	 
		LightGroup_Output[x,5] :=LightGroup_Input[x,5] ;	 
		LightGroup_Output[x,6] :=LightGroup_Input[x,6] ;	 
		LightGroup_Output[x,7] :=LightGroup_Input[x,7] ;	 
		LightGroup_Output[x,8] :=LightGroup_Input[x,8] ;	 
		LightGroup_Output[x,9] :=LightGroup_Input[x,9] ;	 
		LightGroup_Output[x,10]:=LightGroup_Input[x,10];
		LightGroup_Output[x,11]:=LightGroup_Input[x,11];
		LightGroup_Output[x,12]:=LightGroup_Input[x,12];
		LightGroup_Output[x,13]:=LightGroup_Input[x,13];
		LightGroup_Output[x,14]:=LightGroup_Input[x,14];
		LightGroup_Output[x,15]:=LightGroup_Input[x,15];
		LightGroup_Output[x,16]:=LightGroup_Input[x,16];
		LightGroup_Output[x,17]:=LightGroup_Input[x,17];
		LightGroup_Output[x,18]:=LightGroup_Input[x,18];
		LightGroup_Output[x,19]:=LightGroup_Input[x,19];
		LightGroup_Output[x,20]:=LightGroup_Input[x,20];
		LightGroup_Output[x,21]:=LightGroup_Input[x,21];
		LightGroup_Output[x,22]:=LightGroup_Input[x,22];
		LightGroup_Output[x,23]:=LightGroup_Input[x,23];
		LightGroup_Output[x,24]:=LightGroup_Input[x,24];
		LightGroup_Output[x,25]:=LightGroup_Input[x,25];
		LightGroup_Output[x,26]:=LightGroup_Input[x,26];
		LightGroup_Output[x,27]:=LightGroup_Input[x,27];
		LightGroup_Output[x,28]:=LightGroup_Input[x,28];
		LightGroup_Output[x,29]:=LightGroup_Input[x,29];
		LightGroup_Output[x,30]:=LightGroup_Input[x,30];
	end_if;
end_if;

LightGroup_InputP[x]:=LightGroup_Input[x,0];
*)

(**************************************************分组1****************************************************)
if CM =1 then

	if LightGroup_Input[1,0]<>LightGroup_InputP[1] then (*主控CPU群组控制--》新云/本地控制*)
		LightGroup_Output[1,0]:=LightGroup_Input[1,0]; 
	end_if;
	
end_if;

if LightGroup_Output[1,0]<>LightGroup_OutputP[1] then
	
	Delay_ton1(PT :=Delay );
	Delay_ton1.in:= not Delay_ton1.q;
	if Delay_ton1.q=1 then
		j1:=j1+1;
		LightGroup_Output[1,j1] :=LightGroup_Output[1,0]; 
		if j1=10 then
		   j1:=0;
		LightGroup_OutputP[1]:=LightGroup_Output[1,0];
		end_if;	
	end_if;	
	
else (*保持非锁定*)
	if Lock=0 then
		LightGroup_Output[1,1] :=LightGroup_Input[1,1] ;
		LightGroup_Output[1,2] :=LightGroup_Input[1,2] ;	 
		LightGroup_Output[1,3] :=LightGroup_Input[1,3] ;	 
		LightGroup_Output[1,4] :=LightGroup_Input[1,4] ;	 
		LightGroup_Output[1,5] :=LightGroup_Input[1,5] ;	 
		LightGroup_Output[1,6] :=LightGroup_Input[1,6] ;	 
		LightGroup_Output[1,7] :=LightGroup_Input[1,7] ;	 
		LightGroup_Output[1,8] :=LightGroup_Input[1,8] ;	 
		LightGroup_Output[1,9] :=LightGroup_Input[1,9] ;	 
		LightGroup_Output[1,10]:=LightGroup_Input[1,10];
	end_if;
end_if;

LightGroup_InputP[1]:=LightGroup_Input[1,0];

(**************************************************分组2****************************************************)
if CM =1 then

	if LightGroup_Input[2,0]<>LightGroup_InputP[2] then (*主控CPU群组控制--》新云/本地控制*)
		LightGroup_Output[2,0]:=LightGroup_Input[2,0]; 
	end_if;
	
end_if;

if LightGroup_Output[2,0]<>LightGroup_OutputP[2] then
	
	Delay_ton2(PT :=Delay );
	Delay_ton2.in:= not Delay_ton2.q;
	if Delay_ton2.q=1 then
		j2:=j2+1;
		LightGroup_Output[2,j2] :=LightGroup_Output[2,0]; 
		if j2=10 then
		   j2:=0;
		LightGroup_OutputP[2]:=LightGroup_Output[2,0];
		end_if;	
	end_if;	
	
else (*保持非锁定*)
	if Lock=0 then
		LightGroup_Output[2,1] :=LightGroup_Input[2,1] ;
		LightGroup_Output[2,2] :=LightGroup_Input[2,2] ;	 
		LightGroup_Output[2,3] :=LightGroup_Input[2,3] ;	 
		LightGroup_Output[2,4] :=LightGroup_Input[2,4] ;	 
		LightGroup_Output[2,5] :=LightGroup_Input[2,5] ;	 
		LightGroup_Output[2,6] :=LightGroup_Input[2,6] ;	 
		LightGroup_Output[2,7] :=LightGroup_Input[2,7] ;	 
		LightGroup_Output[2,8] :=LightGroup_Input[2,8] ;	 
		LightGroup_Output[2,9] :=LightGroup_Input[2,9] ;	 
		LightGroup_Output[2,10]:=LightGroup_Input[2,10];
	end_if;
end_if;

LightGroup_InputP[2]:=LightGroup_Input[2,0];
(**************************************************分组3****************************************************)
if CM =1 then

	if LightGroup_Input[3,0]<>LightGroup_InputP[3] then (*主控CPU群组控制--》新云/本地控制*)
		LightGroup_Output[3,0]:=LightGroup_Input[3,0]; 
	end_if;
	
end_if;

if LightGroup_Output[3,0]<>LightGroup_OutputP[3] then
	
	Delay_ton3(PT :=Delay );
	Delay_ton3.in:= not Delay_ton3.q;
	if Delay_ton3.q=1 then
		j3:=j3+1;
		LightGroup_Output[3,j3] :=LightGroup_Output[3,0]; 
		if j3=10 then
		   j3:=0;
		LightGroup_OutputP[3]:=LightGroup_Output[3,0];
		end_if;	
	end_if;	
	
else (*保持非锁定*)
	if Lock=0 then
		LightGroup_Output[3,1] :=LightGroup_Input[3,1] ;
		LightGroup_Output[3,2] :=LightGroup_Input[3,2] ;	 
		LightGroup_Output[3,3] :=LightGroup_Input[3,3] ;	 
		LightGroup_Output[3,4] :=LightGroup_Input[3,4] ;	 
		LightGroup_Output[3,5] :=LightGroup_Input[3,5] ;	 
		LightGroup_Output[3,6] :=LightGroup_Input[3,6] ;	 
		LightGroup_Output[3,7] :=LightGroup_Input[3,7] ;	 
		LightGroup_Output[3,8] :=LightGroup_Input[3,8] ;	 
		LightGroup_Output[3,9] :=LightGroup_Input[3,9] ;	 
		LightGroup_Output[3,10]:=LightGroup_Input[3,10];
	end_if;
end_if;

LightGroup_InputP[3]:=LightGroup_Input[3,0];
(**************************************************分组4****************************************************)
if CM =1 then

	if LightGroup_Input[4,0]<>LightGroup_InputP[4] then (*主控CPU群组控制--》新云/本地控制*)
		LightGroup_Output[4,0]:=LightGroup_Input[4,0]; 
	end_if;
	
end_if;

if LightGroup_Output[4,0]<>LightGroup_OutputP[4] then
	
	Delay_ton4(PT :=Delay );
	Delay_ton4.in:= not Delay_ton4.q;
	if Delay_ton4.q=1 then
		j4:=j4+1;
		LightGroup_Output[4,j4] :=LightGroup_Output[4,0]; 
		if j4=10 then
		   j4:=0;
		LightGroup_OutputP[4]:=LightGroup_Output[4,0];
		end_if;	
	end_if;	
	
else (*保持非锁定*)
	if Lock=0 then
		LightGroup_Output[4,1] :=LightGroup_Input[4,1] ;
		LightGroup_Output[4,2] :=LightGroup_Input[4,2] ;	 
		LightGroup_Output[4,3] :=LightGroup_Input[4,3] ;	 
		LightGroup_Output[4,4] :=LightGroup_Input[4,4] ;	 
		LightGroup_Output[4,5] :=LightGroup_Input[4,5] ;	 
		LightGroup_Output[4,6] :=LightGroup_Input[4,6] ;	 
		LightGroup_Output[4,7] :=LightGroup_Input[4,7] ;	 
		LightGroup_Output[4,8] :=LightGroup_Input[4,8] ;	 
		LightGroup_Output[4,9] :=LightGroup_Input[4,9] ;	 
		LightGroup_Output[4,10]:=LightGroup_Input[4,10];
	end_if;
end_if;

LightGroup_InputP[4]:=LightGroup_Input[4,0];
(**************************************************分组5****************************************************)
if CM =1 then

	if LightGroup_Input[5,0]<>LightGroup_InputP[5] then (*主控CPU群组控制--》新云/本地控制*)
		LightGroup_Output[5,0]:=LightGroup_Input[5,0]; 
	end_if;
	
end_if;

if LightGroup_Output[5,0]<>LightGroup_OutputP[5] then
	
	Delay_ton5(PT :=Delay );
	Delay_ton5.in:= not Delay_ton5.q;
	if Delay_ton5.q=1 then
		j5:=j5+1;
		LightGroup_Output[5,j5] :=LightGroup_Output[5,0]; 
		if j5=10 then
		   j5:=0;
		LightGroup_OutputP[5]:=LightGroup_Output[5,0];
		end_if;	
	end_if;	
	
else (*保持非锁定*)
	if Lock=0 then
		LightGroup_Output[5,1] :=LightGroup_Input[5,1] ;
		LightGroup_Output[5,2] :=LightGroup_Input[5,2] ;	 
		LightGroup_Output[5,3] :=LightGroup_Input[5,3] ;	 
		LightGroup_Output[5,4] :=LightGroup_Input[5,4] ;	 
		LightGroup_Output[5,5] :=LightGroup_Input[5,5] ;	 
		LightGroup_Output[5,6] :=LightGroup_Input[5,6] ;	 
		LightGroup_Output[5,7] :=LightGroup_Input[5,7] ;	 
		LightGroup_Output[5,8] :=LightGroup_Input[5,8] ;	 
		LightGroup_Output[5,9] :=LightGroup_Input[5,9] ;	 
		LightGroup_Output[5,10]:=LightGroup_Input[5,10];
	end_if;
end_if;

LightGroup_InputP[5]:=LightGroup_Input[5,0];
(**************************************************分组6****************************************************)
if CM =1 then

	if LightGroup_Input[6,0]<>LightGroup_InputP[6] then (*主控CPU群组控制--》新云/本地控制*)
		LightGroup_Output[6,0]:=LightGroup_Input[6,0]; 
	end_if;
	
end_if;

if LightGroup_Output[6,0]<>LightGroup_OutputP[6] then
	
	Delay_ton6(PT :=Delay );
	Delay_ton6.in:= not Delay_ton6.q;
	if Delay_ton6.q=1 then
		j6:=j6+1;
		LightGroup_Output[6,j6] :=LightGroup_Output[6,0]; 
		if j6=10 then
		   j6:=0;
		LightGroup_OutputP[6]:=LightGroup_Output[6,0];
		end_if;	
	end_if;	
	
else (*保持非锁定*)
	if Lock=0 then
		LightGroup_Output[6,1] :=LightGroup_Input[6,1] ;
		LightGroup_Output[6,2] :=LightGroup_Input[6,2] ;	 
		LightGroup_Output[6,3] :=LightGroup_Input[6,3] ;	 
		LightGroup_Output[6,4] :=LightGroup_Input[6,4] ;	 
		LightGroup_Output[6,5] :=LightGroup_Input[6,5] ;	 
		LightGroup_Output[6,6] :=LightGroup_Input[6,6] ;	 
		LightGroup_Output[6,7] :=LightGroup_Input[6,7] ;	 
		LightGroup_Output[6,8] :=LightGroup_Input[6,8] ;	 
		LightGroup_Output[6,9] :=LightGroup_Input[6,9] ;	 
		LightGroup_Output[6,10]:=LightGroup_Input[6,10];
	end_if;
end_if;

LightGroup_InputP[6]:=LightGroup_Input[6,0];




END_FUNCTION_BLOCK