{
    S7_Author := "AketzaBarragues";
    S7_BlockComment := "MLC_MJ";
    S7_BlockNumber := "15156";
    S7_BlockTitle := "MLC_4Wx";
    S7_Family := "ZeusControl";
    S7_Optimized := "TRUE";
    S7_PreferredLanguage := "LAD";
    S7_Version := "1.0"
}
FUNCTION_BLOCK "FB15156_ZC_DOSIF_SI100_CARTEL"
    VAR_INPUT
        { S7_MLC := "MLC_4uQ" }
        Pulso1Seg : Bool;
        { S7_MLC := "MLC_4Jj" }
        EtapaRecirculacion : Bool;
        { S7_MLC := "MLC_3H3" }
        EstadoMarcha : Bool;
        { S7_MLC := "MLC_457" }
        Aceptar : Bool;
        { S7_MLC := "MLC_4m8" }
        TiempoEntreVentana : Int := 60;
        { S7_MLC := "MLC_3QM" }
        EstadoDetectorBTD : Bool;
    END_VAR
    VAR_OUTPUT
        { S7_MLC := "MLC_32f" }
        MostrarCartel : Bool;
        { S7_MLC := "MLC_57P" }
        Finalizado : Bool;
    END_VAR
    VAR
        { S7_MLC := "MLC_PR" }
        s_Etapa : Int;
    END_VAR
    VAR RETAIN
        s_TiempoEtapa : STRUCT
            { S7_MLC := "MLC_3WU" }
            Activar : Bool;
            { S7_MLC := "MLC_4qd" }
            Cumplido : Bool;
            { S7_MLC := "MLC_gG" }
            Actual : Int;
            { S7_MLC := "MLC_55e" }
            SP : Int;
            { S7_MLC := "MLC_32m" }
            Restante : Int;
        END_STRUCT;
    END_VAR
    VAR CONSTANT
        ETAPA_REPOSO : Int := 0;
        ETAPA_MOSTRAR_VENTANA : Int := 5;
        ETAPA_ESPERA_APERTURA : Int := 10;
        ETAPA_ESPERA_CIERRE : Int := 15;
        ETAPA_FIN : Int := 20;
    END_VAR

    {
        S7_Language := "SCL";
        S7_NetworkTitle := "MLC_4F4"
    }
    NETWORK
        (*
        ============================================================================
         ZEUS CONTROL, S.A.
         (c)Copyright (2023) All Rights Reserved
         -----------------------------------------------------------------------------
        
         Software:       TIA Portal 16
         Restricciones:  PLC serie 1200/1500
        
        
         Nombre:         FB15156_DOSIF_SI100_CARTEL
         Descripcion:    Bloque de funcion para gestion de dosificacion SI-100 manual con cartel para confirmar.
        
         Change log:
         
             Version     Fecha       Tecnico a cargo
             
             01.00.00    22.11.2022  (ABH)   Primera version
             
         ============================================================================
         *)
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_32z"
    }
    NETWORK
        RUNG wire#powerrail
            I_Contact( #EtapaRecirculacion )
            Move(
                in := #ETAPA_REPOSO,
                out1 => #s_Etapa
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4Qu"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4KG"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_Etapa,
                in2 := #ETAPA_REPOSO
            )
            Contact( #EtapaRecirculacion )
            Move(
                in := #ETAPA_MOSTRAR_VENTANA,
                out1 => #s_Etapa
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_bg"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_Etapa,
                in2 := #ETAPA_MOSTRAR_VENTANA
            )
            Contact( #EtapaRecirculacion )
            wire#w1
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
        RUNG wire#w1
            Contact( #Aceptar )
            Move(
                in := 10,
                out1 => #s_Etapa
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3wc"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_Etapa,
                in2 := #ETAPA_ESPERA_APERTURA
            )
            Contact( #EtapaRecirculacion )
            wire#w1
            S_Coil( #s_TiempoEtapa.Activar )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_TiempoEtapa.Actual,
                in2 := #TiempoEntreVentana
            )
            Move(
                in := #ETAPA_MOSTRAR_VENTANA,
                out1 => #s_Etapa
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
        RUNG wire#w1
            I_Contact( #EstadoDetectorBTD )
            Move(
                in := #ETAPA_ESPERA_CIERRE,
                out1 => #s_Etapa
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_352"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_Etapa,
                in2 := #ETAPA_ESPERA_CIERRE
            )
            Contact( #EtapaRecirculacion )
            wire#w1
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
        RUNG wire#w1
            Contact( #EstadoDetectorBTD )
            Move(
                in := #ETAPA_FIN,
                out1 => #s_Etapa
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_wb"
    }
    NETWORK
        RUNG wire#powerrail
            Contact( #EtapaRecirculacion )
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_Etapa,
                in2 := 20
            )
            wire#w1
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Actual
            )
        END_RUNG
        RUNG wire#w1
            Coil( #Finalizado )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3nj"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4FZ"
    }
    NETWORK
        RUNG wire#powerrail
            Contact( #s_TiempoEtapa.Activar )
            wire#w1
            Contact( #Pulso1Seg )
            { S7_Templates := "SrcType := Int" }
            LE_Contact(
                in1 := #s_TiempoEtapa.SP,
                in2 := 32000
            )
            Contact( #EstadoMarcha )
            { S7_Templates := "DestType := Int" }
            Inc( #s_TiempoEtapa.Actual )
        END_RUNG
        RUNG wire#w1
            { S7_Templates := "SrcType := Int" }
            GE_Contact(
                in1 := #s_TiempoEtapa.Actual,
                in2 := #s_TiempoEtapa.SP
            )
            Coil( #s_TiempoEtapa.Cumplido )
        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" }
            LT_Contact(
                in1 := #s_TiempoEtapa.Restante,
                in2 := 0
            )
            Move(
                in := 0,
                out1 => #s_TiempoEtapa.Restante
            )
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_4bQ"
    }
    NETWORK
        RUNG wire#powerrail
        END_RUNG
    END_NETWORK
    {
        S7_Language := "LAD";
        S7_NetworkTitle := "MLC_3aK"
    }
    NETWORK
        RUNG wire#powerrail
            { S7_Templates := "SrcType := Int" }
            EQ_Contact(
                in1 := #s_Etapa,
                in2 := #ETAPA_MOSTRAR_VENTANA
            )
            Contact( #EtapaRecirculacion )
            Coil( #MostrarCartel )
        END_RUNG
    END_NETWORK
END_FUNCTION_BLOCK
