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_GLOBALRETAINPERSISTENTÂ Â (*Motorbreakertrip*)Â Â 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_GLOBALRETAINPERSISTENTÂ Â (*Motorbreakertrip*)Â Â 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_BLOCKfb1VAR_IN_OUT  Tripped    :BOOL;    (*Here IwouldliketoaccessM1_TRIP*)END_VAR
fb1(Tripped:=M1_TRIP);
Regards
Johan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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??
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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:
This will not work:
(Error message 4060: VAR_IN_OUT parameter 'TRIPPED' of 'FB1' need to be variable with write access as input)
Regards
Johan
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.
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?
Best Regards
Johan
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)
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??