Access to BIT variable via IN_OUT from a FB

JohanH
2014-01-23
2014-01-25
  • JohanH - 2014-01-23

    Is there any way to access a bool variable as an IN_OUT to a FB when it is declared as a BIT rather than a BYTE that is "standard" in Codesys?

    This will work:

    VAR_GLOBAL RETAIN PERSISTENT
       (*Motor breaker trip*)
       M1_TRIP   AT %MB10    :BOOL;
       M2_TRIP   AT %MB11    :BOOL;
       M3_TRIP   AT %MB12    :BOOL;
       M4_TRIP   AT %MB13    :BOOL;
       M5_TRIP   AT %MB14    :BOOL;
    END_VAR
    

    This will not work:
    (Error message 4060: VAR_IN_OUT parameter 'TRIPPED' of 'FB1' need to be variable with write access as input)

    VAR_GLOBAL RETAIN PERSISTENT
       (*Motor breaker trip*)
       M1_TRIP   AT %MX10.0   :BOOL;
       M2_TRIP   AT %MX10.1   :BOOL;
       M3_TRIP   AT %MX10.2   :BOOL;
       M4_TRIP   AT %MX10.3   :BOOL;
       M5_TRIP   AT %MX10.4   :BOOL;
    END_VAR
    
    FUNCTION_BLOCK fb1
    VAR_IN_OUT
       Tripped      :BOOL;      (*Here  I would like to access M1_TRIP*)
    END_VAR
    
    fb1(Tripped:= M1_TRIP );
    

    Regards
    Johan

     
  • shooter - 2014-01-24

    change the tripped var from in_out to INPUT.
    and you should use the lower as you use a BOOL but the address is a BYTE.

     
  • JohanH - 2014-01-24

    Hi
    Thanks for your prompt reply. Problem is that I want it to be a Pointer to the variable on the outside of the FB (in this case "M1_trip"). If I make it an ordinary INPUT that will not be the case. Instead a instance variable is created ( fb1.tripped). But an IN_OUT it will point directly to "M1_TRIP" Meaning that FB will read/write directly to "M1_TRIP" and not the instance variable.

    In my case I want to read the status of "tripped" inside the FB and depending on other conditions sometimes set it to FALSE.

    What you mean by use the lower. Could you please explain more?

    Zitat:
    and you should use the lower as you use a BOOL but the address is a BYTE.

    Best Regards
    Johan

     
  • shooter - 2014-01-24

    yes possible with pointers, however i hate them.
    please stick with the 61131

    so you have an input somewhere that is called trip, why not use another one called realtrip and manipulate that one, as it is bad practice to use an input as output.
    i never understood IN_OUT.

    or give us the program (in export format please) and will have a look at it.
    is it necesarry to have them persistent and remain? as this is slow and has limits on times to use (flash writing)

     
  • JohanH - 2014-01-25

    I believe that the IN_OUT is part of 61131 so at least that kind of POINTER must be part as well.
    Not so sure that reserve 8 BIT for a BOOL variable like Codesys does is according to 61131 however.

    The reason for using IN_OUT, is to inside the FB access an variable declared outside the FB.
    There are several occasions when this is useful.
    I.e. Modbus communication often uses the "M" area as this is by default is mapped to the Modbus interface (ABB, Wago..). To pass this value to a FB as an INPUT is waste of memory as this will create an instance variable that will be an duplicate of the variable already used in "M" area. Instead using an IN_OUT will create a pointer to the original variable in "M" area and no "duplicate". Also when working with "retain" variables its better to declared them on the outside and use IN_OUT. If at least one of the function block variables is a retain variable, the total instance is stored in the retain area. Meaning that the retain memory part will be filled up fast.
    I guess this all depends on the programmer and how he wants to structure the program.

    Any how. My question remains. Is there any way to point out a BOOL variable from a FB (IN_OUT) when its declared with BIT??

     

Log in to post a comment.