Calling a User function

SCADAdoc
2012-02-20
2012-02-21
  • SCADAdoc - 2012-02-20

    Hello - Below is the code I am having trouble with. I can accomplish this simple task by using the Function Block type for "Alarm", but I've never use a straight "Function" before and I wanted to try it. I cannot seem to pick out how to get the "Alarm" solution returned to PLC_PRG. Could someone please help? TIA.

    PROGRAM PLC_PRG
    VAR
    Level_SP : INT := 35;
    Current_Level : INT:= 40;
    Level_Alarm : BOOL;
    END_VAR
    ==========
    Level_Alarm := Alarm(Level_SP, Current_Level);

    ==============

    FUNCTION Alarm : BOOL
    VAR_INPUT
    setpoint:INT;
    variable:INT;
    END_VAR

    VAR
    output:BOOL;
    END_VAR
    ============
    IF variable >= setpoint THEN
    output :=TRUE;
    ELSE
    output :=FALSE;
    END_IF
    ===============
    ================

     
  • singleton - 2012-02-21

    Hi,
    the return value of the function is its name:

    IF variable >= setpoint THEN
    Alarm :=TRUE;
    ELSE
    Alarm :=FALSE;
    END_IF
    
     
  • SCADAdoc - 2012-02-21

    Hi Singleton -
    Thank you for your reply - that works perfectly! I appreciate your help.

     

Log in to post a comment.