TheNewGuy9419
TheNewGuy9419

Reputation: 1

Calling a function in Structured text, Codesys 2.3

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.

Upvotes: 0

Views: 1121

Answers (1)

Guiorgy
Guiorgy

Reputation: 1734

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.

Upvotes: 0

Related Questions