{
    S7_Author := "ABH";
    S7_BlockComment := "MLC_3U2";
    S7_BlockNumber := "15993";
    S7_BlockTitle := "MLC_3Nh";
    S7_EditorMode := "SCL";
    S7_Family := "ZeusControl";
    S7_IECCheck := "TRUE";
    S7_Optimized := "TRUE";
    S7_Version := "1.0"
}
FUNCTION_BLOCK "FB15993_ZC_FAT_AO"
    VAR_INPUT
        { S7_MLC := "MLC_3t3" }
        ByteSalida : DInt := 0;
        { S7_MLC := "MLC_4VZ" }
        Area : Int := 1;
    END_VAR
    VAR_OUTPUT
        { S7_MLC := "MLC_3i8" }
        Salida_Raw : DInt;
    END_VAR
    VAR_IN_OUT
        { S7_MLC := "MLC_aA" }
        Salida_0_100 : Real;
    END_VAR
    VAR RETAIN
        s_oldByteSalida : DInt;
    END_VAR
    VAR_TEMP
        t_Area : Byte;
        t_Salida : Int;
        t_Salida_0_100 : Real;
    END_VAR
    VAR CONSTANT
        { S7_MLC := "MLC_4Zv" }
        INPUT : Byte := 16#81;
        { S7_MLC := "MLC_4vc" }
        OUTPUT : Byte := 16#82;
        { S7_MLC := "MLC_3tz" }
        MARCAS : Byte := 16#83;
        { S7_MLC := "MLC_cU" }
        "DB" : Byte := 16#84;
        { S7_MLC := "MLC_53q" }
        PERIFERIA : Byte := 16#01;
        { S7_MLC := "MLC_4js" }
        VALOR_MAX_TARJETA : Real := 27648.0;
        VALOR_CERO : Word;
    END_VAR

    { S7_Language := "SCL" }
    NETWORK
        REGION DESCRIPCION
        (*
        ###### (C)Copyright ZeusControl 2023 - 2023
        
        ---
        ### 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 analogicas 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.00 | 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 CALCULOS
            
            //  Calculo de valor puntos tarjeta en base a porcentaje
            #t_Salida_0_100 := #Salida_0_100;
            IF #t_Salida_0_100 < 0.0 THEN
                #t_Salida_0_100 := 0.0;
            END_IF;
            IF #t_Salida_0_100 > 100.0 THEN
                #t_Salida_0_100 := 100.0;
            END_IF;
            #t_Salida := REAL_TO_INT((#t_Salida_0_100 * #VALOR_MAX_TARJETA) / 100);
            
            
        END_REGION CALCULOS
        
        
        //  ==========================================================================================================
        REGION SALIDAS
            
            //  Gestion desactivacion salidas al cambio de direccion
            IF #s_oldByteSalida <> #ByteSalida THEN
                POKE(area := 16#82,
                     dbNumber := 0,
                     byteOffset := #s_oldByteSalida,
                     value := #VALOR_CERO);
                #Salida_0_100 := 0;
            END_IF;
            
            //  Escritura de salida analogica
            POKE(area := 16#82,
                 dbNumber := 0,
                 byteOffset := #ByteSalida,
                 value := INT_TO_WORD(#t_Salida));
            
            //  Gestion de salidas
            #Salida_Raw := #t_Salida;
            #s_oldByteSalida := #ByteSalida;
            
        END_REGION SALIDAS
        
    END_NETWORK
END_FUNCTION_BLOCK
