Soltanto le parti del programma con l'espressione booleana costante impostata su TRUE vengono controllate e compilate.
#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;
Scopo:
versioni di codice diverse, p. es. per varie ricette, routine di inizializzazione, ecc.
utilizzati per generare diversi codici programma per diversi tipi di PLC da un programma
utili per l'ottimizzazione del codice
Le espressioni costanti per la compilazione condizionata possono anche constare di una qualsiasi combinazione dei seguenti tipi:
variabili costanti esterne
variabili locali costanti
valore letterale
costanti tipo di PLC
Istruzioni informazioni PLC
Variabili globali
Intestazione del POU
Corpo 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;
Le Costanti tipo PLC (nomi a lettere maiuscole) permettono di compilare i programmi in funzione del PLC collegato. Potete scegliere tra:
Tipo di PLC corrente
Gruppi di tipi di PLC supportati da Control FPWIN Pro7
Tipi di PLC espliciti supportati da 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;
Istruzioni informazioni PLC che restituiscono un valore booleano costante:
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;