Solamente se revisan y se compilan las partes del programa con una expresión Booleana constante puesta a 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;
Propósito:
permite diferentes versiones de código, por ejemplo, para varias recetas, inicialización de rutinas, etc.
se utiliza para generar código de programa diferente para los diferentes tipos de PLC
útil para la optimización del código
Las expresiones constantes para la compilación condicional también pueden consistir en una combinación de los siguientes tipos:
constantes externas
constante local
literales
constantes del tipo de PLC
instrucciones de información del PLC
Variables Globales
Cabecera de la POU
Cuerpo en 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;
Estas constantes del sistema (en mayúsculas) permiten la compilación de programas dependiendo del PLC conectado. Se puede seleccionar entre:
Tipo de PLC actual
Grupos de tipos de PLC soportado por Control FPWIN Pro7
Tipos de PLC explícitos soportados por 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;
Instrucciones de información del PLC que devuelven un valor booleano constante:
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;