0

I'm new to Codesys, and PLC programming in general. I am currently being self-taught with the help of some literature. Currently working a practice program. I made a function but when I try to call it I get and error 4051, 'Throttle_Timer' is no function.

Here is the function

FUNCTION_BLOCK Throttle_Timer
VAR_INPUT
    delayTimeMs:TIME;

END_VAR
VAR_OUTPUT
END_VAR
VAR

    Delay:TON;
END_VAR

Delay(IN:=TRUE, PT:=delayTimeMs);
IF NOT(Delay.Q) THEN
   RETURN;
END_IF
Delay(IN:=FALSE);

Here is where I am trying to call it.

PROGRAM PLC_PRG
VAR
    Delay: TON;
END_VAR


(*Pressing the Speed Up Button*)
WHILE speedUp =TRUE AND Throttle<99.51 DO;
Throttle:=Throttle+0.5;

(*function call*)
Throttle_Timer(T#500ms)

END_WHILE;

I cannot for the life of me figure out why. I call the function by name and in parentheses give it the input parameter. Was hoping someone could shed some light on this.

1 Answer 1

0

In CODESYS what we usually call a function in other programming languages is a FUNCTION.

FUNCTION_BLOCK on the other hand is closer to a class in other languages. A FUNCTION_BLOCK has it's own state, and needs to be initialized with a local variable, for example in your case:

PROGRAM PLC_PRG
VAR
    mytimer: Throttle_Timer; // define an object of type `Throttle_Timer` (and initialize it)
END_VAR

mytimer(delayTimeMs := T#500MS); // execute the object block

Like classes in other languages, FUNCTION_BLOCK can have both Methods and Properties.

If you want to read more, check the documentation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.