仅检查和编译带有设置为TRUE的常量布尔表达式的程序部分。
#IF ConstantBooleanExpression1 #THEN
(* Program part 1 executed if ConstantBooleanExpression1 = TRUE *)
#ELSIF ConstantBooleanExpression2 #THEN
(* Program part 2 executed if ConstantBooleanExpression2 = TRUE *)
#ELSE
(* Program part 3 executed if ConstantBooleanExpression1 and
ConstantBooleanExpression2 = FALSE *)
#END_IF;
目的:
不同代码版本,例如用于各种配方、初始化例行程序等
用于对一个程序中的不同PLC类型生成不同程序代码
用于代码优化
条件编译的常量表达式可包含以下类型的任意组合:
外部常量变量
常量局部变量
文字
PLC类型常量
PLC信息指令
全局变量
POU头
ST本体
#if(SUN_POS_ALGORITHM=1) #then
(* PSA Algorithm: 0.06° accuracy, 1950 steps, 3.6 ms cycle time on a FP-X *)
SunPosition_PSA(dtDateAndTime := dtDateAndTime,
rTimezone := rTimezone,
rLatitude := rLatitude,
rLongitude := rLongitude,
bError => bError,
rZenith => rZenith,
rAzimuth => rAzimuth);
#elsif (SUN_POS_ALGORITHM=2) #then
(* SolPos Algorithm: 0.00257° accuracy, 3700 steps, 6.3 ms cycle time on a FP-X *)
SunPosition_SolPos(dtDateAndTime := dtDateAndTime,
rTimezone := rTimezone,
rLatitude := rLatitude,
rLongitude := rLongitude,
rPressure := 1013.0,
rTemperature := 20.0,
bError => bError,
rZenith => rZenith,
rAzimuth => rAzimuth);
#else
(* SolPos Algorithm All: 0.00257° accuracy, 7300 steps, 10.3 ms cycle time on a FP-X *)
SunPosition_SolPos_All(dtDateAndTime := dtDateAndTime,
rTimezone := rTimezone,
rLatitude := rLatitude,
rLongitude := rLongitude,
rPressure := 1013.0,
rTemperature := 20.0,
dutAdditionalInputs := dutAdditionalInputs,
bError => bError,
rZenith => rZenith,
rAzimuth => rAzimuth,
dutAdditionalOutputs => dutAdditionaOutputs);
#end_if;
PLC类型常量(大写名称)允许根据连接的PLC编译程序。可以在以下之间选择:
当前PLC类型
Control FPWIN Pro7支持的PLC类型的组
Control FPWIN Pro7支持的显式PLC类型
#if((SYS_CURRENT_PLC AND (SYS_FP0 OR SYS_FP_e))<>0) #then (* FP0, FPe *)
SunPosition_PSA(dtDateAndTime := dtDateAndTime,
rTimezone := rTimezone,
rLatitude := rLatitude,
rLongitude := rLongitude,
bError => bError,
rZenith => rZenith,
rAzimuth => rAzimuth);
#elsif ((SYS_CURRENT_PLC AND (SYS_FP2 OR SYS_FP2SH OR SYS_FP10SH))<>0) #then
(* FP2,FP2SH,FP10SH *)
SunPosition_SolPos_All(dtDateAndTime := dtDateAndTime,
rTimezone := rTimezone,
rLatitude := rLatitude,
rLongitude := rLongitude,
rPressure := 1013.0,
rTemperature := 20.0,
dutAdditionalInputs := dutAdditionalInputs,
bError => bError,
rZenith => rZenith,
rAzimuth => rAzimuth,
dutAdditionalOutputs => dutAdditionaOutputs);
#else (* FP-Sigma, FP-X, FP0R... *)
SunPosition_SolPos(dtDateAndTime := dtDateAndTime,
rTimezone := rTimezone,
rLatitude := rLatitude,
rLongitude := rLongitude,
rPressure := 1013.0,
rTemperature := 20.0,
bError => bError,
rZenith => rZenith,
rAzimuth => rAzimuth);
#end_if;
返回常量布尔值的PLC信息指令:
dutDTBCD := GET_RTC_DTBCD();
#if(IsInstructionSupported('F230_DTBCD_TO_SEC'))#then
(* FP0R, FP-Sigma, FP-X, FP2, FP2SH *)
F230_DTBCD_TO_SEC(dut_DTBCD, diSeconds);
#else
(* FP0, FPe *)
iSecond := WORD_BCD_TO_INT(dutDTBCD.MinSec and16#00FF);
iMinute := WORD_BCD_TO_INT(SHR(dutDTBCD.MinSec, 8));
iHour := WORD_BCD_TO_INT(dutDTBCD.DayHour and16#00FF);
iDay := WORD_BCD_TO_INT(SHR(dutDTBCD.DayHour, 8));
iMonth := WORD_BCD_TO_INT(dutDTBCD.YearMonth and16#00FF);
iYear := WORD_BCD_TO_INT(SHR(dutDTBCD.YearMonth, 8));
GET_RTC_DT := CONCAT_DT_INT(iYear+2000, iMonth, iDay, iHour, iMinute, iSecond, 0, ERROR);
#end_if;