{
    S7_Author := "ABH";
    S7_BlockComment := "MLC_4QY";
    S7_BlockNumber := "15991";
    S7_BlockTitle := "MLC_WB";
    S7_EditorMode := "SCL";
    S7_Family := "ZeusControl";
    S7_IECCheck := "TRUE";
    S7_Optimized := "TRUE";
    S7_Version := "1.0"
}
FUNCTION_BLOCK "FB15991_ZC_FAT_DO"
    VAR_INPUT
        { S7_MLC := "MLC_WW" }
        ByteSalida : DInt := 0;
        { S7_MLC := "MLC_3T4" }
        Area : Int := 1;
    END_VAR
    VAR
        OrdenSalida : Array[0..7] of Bool := [
            { S7_MLC := "MLC_4Lh" }
        (),
            { S7_MLC := "MLC_Nt" }
        (),
            { S7_MLC := "MLC_457" }
        (),
            { S7_MLC := "MLC_3ft" }
        (),
            { S7_MLC := "MLC_pk" }
        (),
            { S7_MLC := "MLC_4NU" }
        (),
            { S7_MLC := "MLC_3bZ" }
        (),
            { S7_MLC := "MLC_4nz" }
        ()
        ];
    END_VAR
    VAR RETAIN
        s_oldByteSalida : DInt;
    END_VAR
    VAR_TEMP
        for_i : Int;
        t_Area : Byte;
    END_VAR
    VAR CONSTANT
        { S7_MLC := "MLC_4Pr" }
        INPUT : Byte := 16#81;
        { S7_MLC := "MLC_WS" }
        OUTPUT : Byte := 16#82;
        { S7_MLC := "MLC_3dW" }
        MARCAS : Byte := 16#83;
        { S7_MLC := "MLC_3Rj" }
        "DB" : Byte := 16#84;
        { S7_MLC := "MLC_Ww" }
        PERIFERIA : Byte := 16#01;
    END_VAR

    { S7_Language := "SCL" }
    NETWORK
        REGION DESCRIPCION
        (*
        ###### (C)Copyright ZeusControl 2023 - 2024
        
        ---
        ### Información del Sistema
        | Hardware Compatible | Entorno de Ingeniería |
        |---------------------|-----------------------|
        | PLC serie 1200/1500 | TIA Portal 18         |
        
        ---
        > **Restricciones:** Ninguna.
        
        ---
        ### Descripción Funcional
        
        Función para el forzado de las salidas digitales para las pruebas FAT de los cuadros.
        
        ---
        ### Dependencias Requeridas
        | Tipo | Elementos |
        |------|-----------|
        | FC   | - |
        | FB   | - |
        | DB   | - |
        | UDT  | - |
        
        ---
        ### Historial de Cambios
        | Versión  | Fecha      | Técnico | Cambios |
        |----------|------------|---------|---------|
        | 01.00.00 | 12.09.2023 | (ABH)   | Primera version. |
        | 01.00.01 | 24.05.2024 | (ABH)   | Se añade gestion desactivacion de salidas al cambio de direccion. |
        *)
        END_REGION DESCRIPCION
        
        
        //  ==========================================================================================================
        REGION GESTION_TIPO
            
            //  Gestion de tipo
            CASE #Area OF
                0:
                    #t_Area := #INPUT;
                1:
                    #t_Area := #OUTPUT;
                2:
                    #t_Area := #MARCAS;
                3:
                    #t_Area := #DB;
                4:
                    #t_Area := #PERIFERIA;
                    
                ELSE
                    #t_Area := #INPUT;
            END_CASE;
            
        END_REGION GESTION_TIPO
        
        
        REGION SALIDAS
            
            //  Gestion desactivacion salidas al cambio de direccion
            IF #s_oldByteSalida <> #ByteSalida THEN
                FOR #for_i := 0 TO 7 DO
                    
                    POKE_BOOL(area := #t_Area,
                              dbNumber := 0,
                              byteOffset := #s_oldByteSalida,
                              bitOffset := #for_i,
                              value := FALSE);
                    
                    #OrdenSalida[#for_i] := FALSE;
                    
                END_FOR;
            END_IF;
            
            //  Escritura de bit de salidas
            FOR #for_i := 0 TO 7 DO
                
                POKE_BOOL(area := #t_Area,
                          dbNumber := 0,
                          byteOffset := #ByteSalida,
                          bitOffset := #for_i,
                          value := #OrdenSalida[#for_i]);
                
            END_FOR;
            
            #s_oldByteSalida := #ByteSalida;
            
        END_REGION SALIDAS
        
    END_NETWORK
END_FUNCTION_BLOCK
