Pass a varible value from FB_A to class FB_B

drChiavo
2016-01-20
2016-01-21
  • drChiavo - 2016-01-20

    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

     
  • RolandWagner

    RolandWagner - 2016-01-20

    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;
    
     
  • drChiavo - 2016-01-20

    Hello,
    thanks for your answer. I tried already but is not working. I made a screenshot.

    IMG: Result.PNG

     
  • RolandWagner

    RolandWagner - 2016-01-21

    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;
    

    IMG: FB_Vars.png

    FB_Vars.project [133.29 KiB]

     
  • drChiavo - 2016-01-21

    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.