Hi, i'm calling a function block from a function block. What I'm want to know is how to access the output value of the function block i will be calling from my current function block.
I mainly need to know what the syntax looks like.
This is my prg, its very simple. I'm wanting to get my syntax correct, before i create larger programs.
PROGRAM MAIN
VAR
DigIn_1 AT %IX0.0 : BOOL;
DigOut_1 AT %QX0.0 : BOOL;
Numbers:One;(my FB)
NumberTotal:INT;
END_VAR
DigOut_1:=DigIn_1;
NumberTotal:=Numbers.Number1 + Numbers.Number2;(my code to get FB output values, is it correct? Is there any other way of doing Call FB)
FUNCTION_BLOCK One
VAR_INPUT
DigIn_1 AT %I : BOOL;
END_VAR
VAR_OUTPUT
DigOut_1 AT %Q : BOOL;
Number1 :INT;
Number2 :INT;
END_VAR
VAR
END_VAR
IF DigOut_1 THEN
Number1:=3;
Number2:=5;
END_IF
Thanks Stu
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
here you go
it is depending of the language
if using ST here you see some examples in the exp file
in another language like IL you put CAL in front.
you must declare every function block in the VAR list. (it will make an copy of the block and use it.
i saw the helpfile still a lot of german language sorry for that.
made you an example
shooter hat geschrieben:
yes because the position is important not the name, the first name is from the caller and the name in the function can be different.
Cool, something new i've learnt . Although i think i may keep the name of the function the same, maybe less confusing
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, how do you do this in twincat? I know how to call an inputs e.g. mZ1_OpenLock (Direction:=TRUE,BackEnable:=TRUE,);. But how do you call outputs??
Stu
do you mean mZ1_OpenLock.output?
where output is defined in the varlist.
Hi, i'm calling a function block from a function block. What I'm want to know is how to access the output value of the function block i will be calling from my current function block.
I mainly need to know what the syntax looks like.
This is my prg, its very simple. I'm wanting to get my syntax correct, before i create larger programs.
PROGRAM MAIN
VAR
DigIn_1 AT %IX0.0 : BOOL;
DigOut_1 AT %QX0.0 : BOOL;
Numbers:One;(my FB)
NumberTotal:INT;
END_VAR
DigOut_1:=DigIn_1;
NumberTotal:=Numbers.Number1 + Numbers.Number2;(my code to get FB output values, is it correct? Is there any other way of doing Call FB)
FUNCTION_BLOCK One
VAR_INPUT
DigIn_1 AT %I : BOOL;
END_VAR
VAR_OUTPUT
DigOut_1 AT %Q : BOOL;
Number1 :INT;
Number2 :INT;
END_VAR
VAR
END_VAR
IF DigOut_1 THEN
Number1:=3;
Number2:=5;
END_IF
Thanks Stu
here you go
it is depending of the language
if using ST here you see some examples in the exp file
in another language like IL you put CAL in front.
you must declare every function block in the VAR list. (it will make an copy of the block and use it.
i saw the helpfile still a lot of german language sorry for that.
made you an example
( @NESTEDCOMMENTS := 'Yes' )
( @PATH := '' )
( @OBJECTFLAGS := '0, 8' )
( @SYMFILEFLAGS := '2048' )
FUNCTION_BLOCK firstblock
VAR_INPUT
firstin: INT;
END_VAR
VAR_OUTPUT
firstout1: INT;
END_VAR
VAR
secondin: INT;
secondout: INT;
block2:secondblock;
END_VAR
( @END_DECLARATION := '0' )
secondin:= firstin*10;
block2(in1:=secondin , out1=>secondout );
firstout1:=secondout+10;
END_FUNCTION_BLOCK
( @NESTEDCOMMENTS := 'Yes' )
( @PATH := '' )
( @OBJECTFLAGS := '0, 8' )
( @SYMFILEFLAGS := '2048' )
PROGRAM PLC_PRG
VAR
in1: INT;
out1: INT;
result: INT;
block1:firstblock;
END_VAR
( @END_DECLARATION := '0' )
in1:=100;
block1(firstin:=in1 , firstout1=> );
result:=block1.firstout1;
END_PROGRAM
( @NESTEDCOMMENTS := 'Yes' )
( @PATH := '' )
( @OBJECTFLAGS := '0, 8' )
( @SYMFILEFLAGS := '2048' )
FUNCTION_BLOCK secondblock
VAR_INPUT
in1: INT;
END_VAR
VAR_OUTPUT
out1: INT;
END_VAR
VAR
END_VAR
( @END_DECLARATION := '0' )
out1:=in1+1;
END_FUNCTION_BLOCK
import in an empty codesys
i can not attach files as extensions are not allowed.
In FBD it is most easy and when you translate it to ST you will see the structure easily.
greetings paul,
block.pro [27.59 KiB]
Thanks very much this clears up a few syntax issues. I presume when calling "Functions" the same syntax is used?
Stu
almost same you do not have to declare functions in the var.
So you call them directly, no name change?
yes correct see help file
made you an example
( @NESTEDCOMMENTS := 'Yes' )
( @PATH := '' )
( @OBJECTFLAGS := '0, 8' )
( @SYMFILEFLAGS := '2048' )
FUNCTION functionname : REAL
VAR_INPUT
in1: REAL;
in2: REAL;
in3: REAL;
END_VAR
VAR
work1: REAL;
work2: REAL;
work3: REAL;
END_VAR
( @END_DECLARATION := '0' )
( average with a twist)
work1:=in13;
work2:=in22;
work3:=in3*1;
functionname:= (work1+work2+work3)/6;
END_FUNCTION
( @NESTEDCOMMENTS := 'Yes' )
( @PATH := '' )
( @OBJECTFLAGS := '0, 8' )
( @SYMFILEFLAGS := '2048' )
PROGRAM showfunction
VAR
result: REAL;
inp1: REAL;
inp2: REAL;
inp3: REAL;
END_VAR
( @END_DECLARATION := '0' )
inp1:=3;
inp2:=2;
inp3:=1;
result:=functionname(inp1, inp2, inp3);
END_PROGRAM
there is only one result and it should be in a variable with the same name as the function is. watch the declaration of the vartype in line 1
take this and make it an .exp file
then import it to codesys
still getting alarm not able to receive exp extension.
Thank you, your help is very appreciated just one thing your "in" variables are different in the function compared to the program.
yes because the position is important not the name, the first name is from the caller and the name in the function can be different.
Cool, something new i've learnt . Although i think i may keep the name of the function the same, maybe less confusing