{
    S7_Author := "ABH";
    S7_BlockNumber := "15182";
    S7_BlockTitle := "MLC_TA";
    S7_Family := "ZeusControl";
    S7_Optimized := "TRUE";
    S7_PreferredLanguage := "LAD";
    S7_Version := "1.0"
}
FUNCTION_BLOCK "FB15182_ZC_FERM_ESPERA_PH"
    VAR_INPUT
        { S7_MLC := "MLC_d3" }
        NombreSecuencia : String := 'HOMOGENIZAR';
        { S7_MLC := "MLC_3A6" }
        Pulso1Seg : Bool;
        { S7_MLC := "MLC_4MM" }
        Ack : Bool;
        { S7_MLC := "MLC_3EG" }
        OrdenMarcha : Bool;
        { S7_MLC := "MLC_TF" }
        EstadoEnMarcha : Bool;
        { S7_MLC := "MLC_3zG" }
        EnEtapa : Bool;
        { S7_MLC := "MLC_fD" }
        OrdenPausa : Bool;
        { S7_MLC := "MLC_an" }
        ConfirmacionPulsador : Bool;
        Parametros : _.UDT_ZC_RECETA_BATCH_ETAPA := (
            { S7_MLC := "MLC_3Pn" }
            TipoEtapa := (),
            { S7_MLC := "MLC_4bS" }
            P_Real_1 := (),
            { S7_MLC := "MLC_4RZ" }
            P_Real_2 := (),
            { S7_MLC := "MLC_3vG" }
            P_Real_3 := (),
            { S7_MLC := "MLC_jt" }
            P_Real_4 := (),
            { S7_MLC := "MLC_3EH" }
            P_Real_5 := (),
            { S7_MLC := "MLC_3MQ" }
            P_Real_6 := (),
            { S7_MLC := "MLC_3KM" }
            P_Real_7 := (),
            { S7_MLC := "MLC_rx" }
            P_Real_8 := (),
            { S7_MLC := "MLC_3SN" }
            P_Real_9 := (),
            { S7_MLC := "MLC_ge" }
            P_Real_10 := (),
            { S7_MLC := "MLC_36D" }
            P_Real_11 := (),
            { S7_MLC := "MLC_59q" }
            P_Real_12 := (),
            { S7_MLC := "MLC_384" }
            P_Real_13 := (),
            { S7_MLC := "MLC_3AV" }
            P_Real_14 := (),
            { S7_MLC := "MLC_3N4" }
            P_Real_15 := (),
            { S7_MLC := "MLC_4zN" }
            P_Real_16 := (),
            { S7_MLC := "MLC_mW" }
            P_Real_17 := (),
            { S7_MLC := "MLC_3Pe" }
            P_Int_1 := (),
            { S7_MLC := "MLC_4WL" }
            P_Int_2 := (),
            { S7_MLC := "MLC_4KE" }
            P_Int_3 := (),
            { S7_MLC := "MLC_47f" }
            P_Int_4 := (),
            { S7_MLC := "MLC_4JS" }
            P_Int_5 := (),
            { S7_MLC := "MLC_4Xa" }
            P_Int_6 := (),
            { S7_MLC := "MLC_wj" }
            P_Int_7 := (),
            { S7_MLC := "MLC_3sg" }
            P_Int_8 := (),
            { S7_MLC := "MLC_3M5" }
            P_Int_9 := (),
            { S7_MLC := "MLC_4QT" }
            P_Int_10 := (),
            { S7_MLC := "MLC_53j" }
            P_Int_11 := (),
            { S7_MLC := "MLC_47x" }
            P_Int_12 := (),
            { S7_MLC := "MLC_3Ra" }
            P_Int_13 := (),
            { S7_MLC := "MLC_4Q2" }
            P_Int_14 := (),
            { S7_MLC := "MLC_TW" }
            P_Int_15 := (),
            { S7_MLC := "MLC_pu" }
            P_String_1 := (),
            { S7_MLC := "MLC_3g8" }
            P_String_2 := (),
            { S7_MLC := "MLC_34N" }
            P_String_3 := (),
            { S7_MLC := "MLC_3SC" }
            P_String_4 := (),
            { S7_MLC := "MLC_4nh" }
            P_String_5 := (),
            { S7_MLC := "MLC_52B" }
            P_String_6 := (),
            { S7_MLC := "MLC_48Z" }
            P_String_7 := (),
            { S7_MLC := "MLC_xg" }
            P_String_8 := (),
            { S7_MLC := "MLC_4Km" }
            P_String_9 := (),
            { S7_MLC := "MLC_32s" }
            P_String_10 := ()
        );
    END_VAR
    VAR_OUTPUT
        { S7_MLC := "MLC_3Eu" }
        PermisoPulsador : Bool;
        { S7_MLC := "MLC_3Kk" }
        SecuenciaIniciada : Bool;
        { S7_MLC := "MLC_3kC" }
        FinSecuencia : Bool;
        VisMinutosRestantes : Bool;
        MinutosRestantes : Int;
    END_VAR
    VAR RETAIN
        { S7_MLC := "MLC_43X" }
        s_EtapaActual : Int;
        { S7_MLC := "MLC_3Um" }
        s_TextoEtapa : String[100];
        s_Pausa_M : Bool;
        s_Pausa_V : Bool;
        s_Continuar : Bool;
    END_VAR
    VAR
        {
            S7_Access := "ReadOnly := External";
            S7_Visibility := "Hidden := External"
        }
        s_Pulsos : Array[0..15] of Bool := [
            { S7_MLC := "MLC_3UZ" }
        (),
            { S7_MLC := "MLC_4qn" }
        (),
            { S7_MLC := "MLC_vn" }
        (),
            { S7_MLC := "MLC_4HK" }
        (),
            { S7_MLC := "MLC_VN" }
        (),
            { S7_MLC := "MLC_3rJ" }
        (),
            { S7_MLC := "MLC_4WJ" }
        (),
            { S7_MLC := "MLC_xa" }
        (),
            { S7_MLC := "MLC_4ig" }
        (),
            6(()),
            { S7_MLC := "MLC_3wB" }
        ()
        ];
    END_VAR
    VAR RETAIN
        { S7_MLC := "MLC_3XQ" }
        s_TiempoEtapa : STRUCT
            { S7_MLC := "MLC_ZW" }
            Activar : Bool;
            { S7_MLC := "MLC_52z" }
            Reset : Bool;
            { S7_MLC := "MLC_3zF" }
            Actual : Int;
            { S7_MLC := "MLC_SZ" }
            SP : Int;
            { S7_MLC := "MLC_3Yy" }
            Restante : Int;
        END_STRUCT;
    END_VAR
    VAR
        {
            S7_Access := "ReadOnly := External";
            S7_Setpoint := "False";
            S7_Visibility := "Hidden := External"
        }
        s_TON : Array[1..#NUM_MAX_TON] of _.UDT_ZC_DISP_TON := [
            { S7_MLC := "MLC_4mT" }
        (),
            { S7_MLC := "MLC_4Je" }
        ()
        ];
    END_VAR
    VAR RETAIN
        s_ContadorTiempo : _.UDT_ZC_CONTADOR_MINUTOS;
    END_VAR
    VAR_TEMP
        for_i : Int;
        t_MinutosInt : Int;
        t_MinutosRestantes : Int;
    END_VAR
    VAR CONSTANT
        SiempreON : Bool := TRUE;
        SiempreOFF : Bool := FALSE;
        NUM_MAX_TON : Int := 2;
    END_VAR

    {
        S7_Language := "SCL";
        S7_NetworkTitle := "MLC_4qC"
    }
    NETWORK
        (*
        ============================================================================
        ZEUS CONTROL, S.A.
        (c)Copyright (2024) All Rights Reserved
        -----------------------------------------------------------------------------
        
        Software:       TIA Portal 18
        Restricciones:  PLC serie 1200/1500
        
        
        Nombre:         FB15182_ZC_FERM_ESPERA_PH
        Descripcion:    Bloque de gestión de fase homogenizar
        
        Dependencias:   
            FC:         -
            FB:         -
            DB:         -
            UDT:        -
                     
        
        Change log:
        
            Version     Fecha       Tecnico a cargo     Descripción
            
            01.00.00    08.07.2025  (ABH)               Primera versión
            
         ============================================================================
        *)
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3WU"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_37Y"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_SP"
    }
    NETWORK
        RUNG wire#powerrail
            Contact( #SiempreON )
            wire#w1
            Contact( #OrdenPausa )
            wire#w2
            S_Coil( #s_Pausa_M )
        END_RUNG
        RUNG wire#w1
            I_Contact( #EstadoEnMarcha )
        END_RUNG wire#w2
        RUNG wire#w1
            Contact( #s_Pausa_M )
            wire#w3
            Move(
                in := 3,
                out1 => #s_TON[1].SP
            )
            Coil( #s_TON[1].IN )
        END_RUNG
        RUNG wire#w3
            Contact( #s_TON[1].Q )
            I_Contact( #s_Continuar )
            S_Coil( #s_Pausa_V )
        END_RUNG
        RUNG wire#w1
            I_Contact( #OrdenPausa )
            Contact( #EstadoEnMarcha )
            wire#w4
            R_Coil( #s_Pausa_V )
        END_RUNG
        RUNG wire#w4
            S_Coil( #s_Continuar )
        END_RUNG
        RUNG wire#w1
            Contact( #s_Continuar )
            wire#w5
            Move(
                in := 3,
                out1 => #s_TON[2].SP
            )
            Coil( #s_TON[2].IN )
        END_RUNG
        RUNG wire#w5
            Contact( #s_TON[2].Q )
            wire#w6
            R_Coil( #s_Pausa_M )
        END_RUNG
        RUNG wire#w6
            R_Coil( #s_Continuar )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 0
            )
            wire#w7
            R_Coil( #s_Pausa_M )
        END_RUNG
        RUNG wire#w7
            R_Coil( #s_Pausa_V )
        END_RUNG
        RUNG wire#w7
            R_Coil( #s_Continuar )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_53y"
    }
    NETWORK
        RUNG wire#powerrail
            I_Contact( #EnEtapa )
            Move(
                in := 0,
                out1 => #s_EtapaActual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "SCL";
        S7_NetworkTitle := "MLC_UA"
    }
    NETWORK
        //  ================================================================
        //  TEXTO ETAPA
        CASE #s_EtapaActual OF
            0:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - REPOSO');
                
            140:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - ESPERA');
                
            999:
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - FIN DE SECUENCIA');
                
            ELSE
                #s_TextoEtapa := CONCAT_STRING(IN1 := #NombreSecuencia, IN2 := ' - FUERA DE ETAPA');
        END_CASE;
        
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3DX"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3Bb"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 0
            )
            Contact( #EnEtapa )
            Contact( #OrdenMarcha )
            Move(
                in := 140,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4ic"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 140
            )
            wire#w1
            P_Trig( #s_Pulsos[3] )
            Move(
                in := 1,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            R_Coil( #s_TiempoEtapa.Activar )
        END_RUNG
        RUNG wire#w1
            Contact( #ConfirmacionPulsador )
            Move(
                in := 999,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_wt"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 999
            )
            wire#w1
            P_Trig( #s_Pulsos[15] )
            Move(
                in := 3,
                out1 => #s_TiempoEtapa.SP
            )
        END_RUNG
        RUNG wire#w1
            I_Contact( #EnEtapa )
            S_Coil( #s_TiempoEtapa.Activar )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_TiempoEtapa.Actual,
                in2 := #s_TiempoEtapa.SP
            )
            Move(
                in := 0,
                out1 => #s_EtapaActual
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_cr"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_56Y"
    }
    NETWORK
        RUNG wire#powerrail
            Contact( #s_TiempoEtapa.Activar )
            wire#w1
            Contact( #EstadoEnMarcha )
            I_Contact( #s_Pausa_M )
            Contact( #Pulso1Seg )
            { S7_Templates := "SrcType := Int" }
            LT_Contact(
                in1 := #s_TiempoEtapa.Actual,
                in2 := #s_TiempoEtapa.SP
            )
            { S7_Templates := "DestType := Int" }
            Inc( #s_TiempoEtapa.Actual )
        END_RUNG
        RUNG wire#w1
            Contact( #s_TiempoEtapa.Reset )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
        RUNG wire#w1
            R_Coil( #s_TiempoEtapa.Activar )
        END_RUNG
        RUNG wire#powerrail
            Sub(
                in1 := #s_TiempoEtapa.SP,
                in2 := #s_TiempoEtapa.Actual,
                out => #s_TiempoEtapa.Restante
            )
            { S7_Templates := "SrcType := Int" }
            LE_Contact(
                in1 := #s_TiempoEtapa.Restante,
                in2 := 0
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Restante
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "SCL";
        S7_NetworkTitle := "MLC_3JN"
    }
    NETWORK
        
        //  ============================================================================
        //  TON
        FOR #for_i := 1 TO #NUM_MAX_TON DO
            "FC2928_ZC_TON_INDV"(Pulso1seg := #Pulso1Seg,
                                 TON := #s_TON[#for_i]);
        END_FOR;
        
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_45j"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_55m"
    }
    NETWORK
        RUNG wire#powerrail
            "FC15027_ZC_CONTADOR_MINUTOS"(
                Pulso1seg := #Pulso1Seg,
                Iniciar := wire#w1,
                Reset := wire#w2,
                Contador := #s_ContadorTiempo
            )
        END_RUNG
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 140
            )
        END_RUNG wire#w1
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 0
            )
        END_RUNG wire#w2
        RUNG wire#powerrail
            {
                S7_Templates := "[SrcType := UDInt, DestType := Int]"
            }
            Convert(
                in := #s_ContadorTiempo.Minuto,
                out => #t_MinutosInt
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_49V"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3UA"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 140
            )
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #t_MinutosInt,
                in2 := #Parametros.P_Int_1
            )
            Coil( #PermisoPulsador )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3wZ"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 140
            )
            wire#w1
            Sub(
                in1 := #Parametros.P_Int_1,
                in2 := #t_MinutosInt,
                out => #t_MinutosRestantes
            )
            { S7_Templates := "SrcType := Int" }
            LE_Contact(
                in1 := #t_MinutosRestantes,
                in2 := 0
            )
            Move(
                in := 0,
                out1 => #t_MinutosRestantes
            )
        END_RUNG
        RUNG wire#w1
            Move(
                in := #t_MinutosRestantes,
                out1 => #MinutosRestantes
            )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            GT_Contact(
                in1 := #t_MinutosRestantes,
                in2 := 0
            )
            Coil( #VisMinutosRestantes )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_Ld"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            GT_Contact(
                in1 := #s_EtapaActual,
                in2 := 0
            )
            Coil( #SecuenciaIniciada )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3VC"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_EtapaActual,
                in2 := 999
            )
            Coil( #FinSecuencia )
        END_RUNG
    END_NETWORK
END_FUNCTION_BLOCK
