FUNCTION_BLOCK IJ_DAHUW
VAR_EXTERNAL

END_VAR

VAR_INPUT
DAHUW_STRUCT_IN  :DAHUW_IN;
END_VAR

VAR_OUTPUT
DAHUW_STRUCT_OUT :DAHUW_OUT;
END_VAR

VAR

DAHUW_EVC			 :IJ_EVC;
DAHUW_RunTime		 :BS_Runtime;
RunTon1         	 :TON;
RunTon2         	 :TON;
RunTof1         	 :TOF;
RunTof2         	 :TOF;
DevCheck1_time  	 :TIME :=t#15s;  (*设备运行状态反馈*)
DevCheck2_time  	 :TIME :=t#15s;  (*设备运行状态反馈*)
Status0				 :INT;
Status1				 :INT;
Status2				 :INT;
Status3				 :INT;
FPSSIM_timer		 :TON;

END_VAR
(* 

时  间:20220814
版  本:1.0
作  者:潘平
名  称:吾悦定制吊顶空调机组程序功能块
说  明:
		输入变量
		DAHUW_STRUCT_IN.
		SM              :INT ; 		季节模式 0夏季 1冬季 2过渡 
		Run             :BOOL; 		运行状态
		Fault           :BOOL; 		故障状态
		Auto            :BOOL; 		自动状态
		Control         :BOOL; 		程序控制
		TSET			:REAL; 		温度设定
		EVC				:BOOL;      电磁阀控制
		EVA				:BOOL;      电磁阀自动状态
		EVR				:BOOL;      电磁阀运行状态
		EVMC			:BOOL;      电磁阀手动控制
		EVMV    		:BOOL;      电磁阀手动控制值
		RTS         	:REAL; 		回风温度
		RST      		:BOOL; 		运行时间累计重置
		RSTV			:REAL; 		运行时间累计重置值
		FPS 			:BOOL; 		风机压差
		ISO1   			:BOOL; 		运行故障反馈隔离
		ISO2   			:BOOL; 		风机压差反馈隔离

		DAHUW_STRUCT_OUT.
		EVC     		:BOOL ;
		Control         :BOOL; 		启停控制
		RH        		:REAL; 		运行小时
		SN        		:INT ; 		设备状态代码
		FPSSIM			:BOOL;		压差模拟输出
		
		包含以下几点功能
		1.运行故障回检,输出故障代码,支持故障报警隔离
		2.水阀PID调节/手动调节
		3.运行时间累计
		4.增加了压差模拟输出
				
备  注:
依赖块:
		BS_Runtime;
		IJ_EVC;
*)


(******************************************************运行故障回检******************************************************)
RunTon1( IN:=DAHUW_STRUCT_IN.Control , PT:=DevCheck1_time);
RunTof1( IN:=DAHUW_STRUCT_IN.Control , PT:=DevCheck1_time);
RunTon2( IN:=DAHUW_STRUCT_IN.Control , PT:=DevCheck2_time);
RunTof2( IN:=DAHUW_STRUCT_IN.Control , PT:=DevCheck2_time);

(*设备电气控制箱控制指令与设备运行反馈不一致故障检测,检测故障产生原因电箱没电、断路器断开、中间继电器与接触器故障等为Status0*);
DAHUW_STRUCT_OUT.Control:=DAHUW_STRUCT_IN.Control;
if DAHUW_STRUCT_IN.ISO1=0 then
	if RunTon1.q or not RunTof1.q then		
		if DAHUW_STRUCT_OUT.Control<>DAHUW_STRUCT_IN.Run then
			Status0:=1;
			else
			Status0:=0;
		end_if;
		if DAHUW_STRUCT_IN.Fault=1 then
			Status1:=1;
			else
			Status1:=0;
		end_if;
	end_if;
	else
	Status0:=0;
	Status1:=0;
end_if;

(*设备电气控制箱控制指令与设备运行反馈不一致故障检测,检测故障产生风机压差无回检信号*);
if DAHUW_STRUCT_IN.ISO2=0 then
	if RunTon2.q or not RunTof2.q then		
		if DAHUW_STRUCT_OUT.Control<>DAHUW_STRUCT_IN.FPS then
			Status2:=1;
			else
			Status2:=0;
		end_if;
	end_if;
	else
	Status2:=0;
end_if;


(*输出故障代码*)
if DAHUW_STRUCT_OUT.Control<>0 then
	DAHUW_STRUCT_OUT.SN := Status0*1 + Status1*2 + Status2*4;
	else
	DAHUW_STRUCT_OUT.SN := 0 ;
end_if;

(******************************************************压差信号模拟**************************************************)
(********************************************原则上不使用,谨慎使用**************************************************)

FPSSIM_timer( IN:=DAHUW_STRUCT_IN.Run , PT:=t#5s );
if DAHUW_STRUCT_IN.Run=1 and DAHUW_STRUCT_IN.Fault=0 then 
	DAHUW_STRUCT_OUT.FPSSIM:=FPSSIM_timer.q;
	else
	DAHUW_STRUCT_OUT.FPSSIM:=0;
end_if;

(******************************************************水阀控制******************************************************)
if DAHUW_STRUCT_IN.EVMC=0 then
	if DAHUW_STRUCT_IN.Run=1 then
		(*制冷季*)
		if DAHUW_STRUCT_IN.SM=0 then		
		   DAHUW_EVC(RUN :=DAHUW_STRUCT_IN.RUN , SET :=DAHUW_STRUCT_IN.TSET , FB :=DAHUW_STRUCT_IN.RTS , DEAD_BAND :=0.5 , DELAY :=t#60s , SW :=DAHUW_STRUCT_IN.SM  |  DAHUW_STRUCT_OUT.EVC:= EVC);
		end_if;
		(*制热季*)
		if DAHUW_STRUCT_IN.SM=1 then
		   DAHUW_EVC(RUN :=DAHUW_STRUCT_IN.RUN , SET :=DAHUW_STRUCT_IN.TSET , FB :=DAHUW_STRUCT_IN.RTS , DEAD_BAND :=0.5 , DELAY :=t#60s , SW :=DAHUW_STRUCT_IN.SM  |  DAHUW_STRUCT_OUT.EVC:= EVC);
		end_if;
		(*过渡季*)
		if DAHUW_STRUCT_IN.SM=2 then 	
		   DAHUW_STRUCT_OUT.EVC:=0;
		end_if;
	else
		DAHUW_STRUCT_OUT.EVC:=0 ;		
	end_if;
else
	DAHUW_STRUCT_OUT.EVC:=DAHUW_STRUCT_IN.EVMV;
end_if;

(******************************************************运行时间累计******************************************************)
DAHUW_RunTime(RUN :=DAHUW_STRUCT_IN.Run , RUNTIMESET :=DAHUW_STRUCT_IN.RSTV , RUNTIMERST :=DAHUW_STRUCT_IN.RST ,RunTimeRec_In :=DAHUW_STRUCT_OUT.RH |  DAHUW_STRUCT_OUT.RH:= RUNTIME);


END_FUNCTION_BLOCK