Hello,
How can I pass a variable value from a FB_A to FB_B.
FB_A
var_a1 := 2;
FB_B
var_b1 := var_a1; ??
Is it possible? If yes, how? Thanks
There are several ways to do so. The easiest way would be to declare var_a1 as output of FB_A:
PROGRAM PLC_PRG VAR InstanceA:FB_A; InstanceB:FB_B; END_VAR InstanceA(); InstanceB(); ... FUNCTION_BLOCK FB_A VAR_OUTPUT var_a1:INT; END_VAR var_a1 := 2; FUNCTION_BLOCK FB_B VAR var_b1:INT; END_VAR var_b1 := InstanceA.var_a1;
Hello, thanks for your answer. I tried already but is not working. I made a screenshot.
It works well on my project... Please try the attached Project...
Now I see: you have two different instances of the same FB_A. Replace the call in FB_B by this:
var_b1 := InstanceA.var_a1;
FB_Vars.project [133.29 KiB]
I see! Now is working properly.
The problem was that the program (PRG) was missing before the instance.
Β var_b1 := PRG_COM.InstanceA.var_a1;
Thanks
Log in to post a comment.
Hello,
How can I pass a variable value from a FB_A to FB_B.
FB_A
var_a1 := 2;
FB_B
var_b1 := var_a1; ??
Is it possible? If yes, how?
Thanks
There are several ways to do so. The easiest way would be to declare var_a1 as output of FB_A:
Hello,
thanks for your answer. I tried already but is not working. I made a screenshot.
It works well on my project...
Please try the attached Project...
Now I see: you have two different instances of the same FB_A.
Replace the call in FB_B by this:
FB_Vars.project [133.29 KiB]
I see! Now is working properly.
The problem was that the program (PRG) was missing before the instance.
Thanks