Help with __SYSTEM.VAR_INFO

ph0010421
2025-01-24
2025-01-26
  • ph0010421 - 2025-01-24

    hi all
    I have a FB with IN/OUT variable.
    Inside the FB, I want to get the address of the IN/OUT variable.
    If I use __SYSTEM.VAR_INFO, I get the address of the FB copy rather than 'external' variable.

    VAR_IN_OUT
        MyVar: bool;
    END_VAR
    VAR
        Info: __SYSTEM.VAR_INFO;
    END_VAR
    
    Info := __VARINFO(MyVar);
    

    This give me the address of MyVar but I actually want the address of the variable passed to MyVar

    Any clues please??

    thanks, ph

     

    Last edit: ph0010421 2025-01-24
  • trusty-squire - 2025-01-26

    Not knowing exactly what you want to accomplish, you can try to use

    VAR_INPUT
        MyVar: POINTER TO BOOL;
    END_VAR
    

    MyVar contains the address of your referenced variable, and MyVar^ dereferences it allowing you to access the value. If this doesn't meet your needs, could you add more detail on what you are trying to accomplish?

     
  • Fless

    Fless - 2025-01-26

    to get the address just use ADR( )

    variables defined in a VAR_IN_OUT block are references pointing to the passed variables.

    VAR_IN_OUT
        MyVar: bool;
    END_VAR
    VAR
        adrMyVar: __XWORD;
    END_VAR
    
    adrMyVar := ADR(MyVar);
    
     
  • ph0010421 - 2025-01-26

    thanks...I changed to I POINTER which is perfect.

     

Log in to post a comment.