Only program parts with the constant Boolean expression set to TRUE are checked and compiled.
#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;
Purpose:
different versions of code, e.g. for various recipes, initialization routines, etc.
used to generate different program code for different PLC types from one program
useful for code optimization
Constant expressions for conditional compilation can consist of any combination of the following types:
external constant variables
constant local variables
literals
PLC type constants
PLC information instructions
Global variables
POU header
ST body
#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 type constants (capitalized names) allow programs to be compiled depending on the PLC connected. You can choose between:
Current PLC type
Groups of PLC types supported by Control FPWIN Pro7
Explicit PLC types supported by Control FPWIN Pro7
#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 information instructions returning a constant Boolean value:
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;