InOut Variables: Rules and Specific Characteristics
InOut variables are formal parameters of function block POUs. They can be declared using the 'Usage' keyword 'InOut' in the variables table of an FB POU. An InOut formal parameter is both, input and output of the FB. Within the POU, the variable can be read or written. When reading/writing an InOut variable, a reference (pointer) to the memory address of the formal parameter is processed.
Typically, InOuts are used for complex data types such as strings, arrays and structures.
- On input side, the formal parameter must be written (that is to say, must not remain unconnected). That means:
- In FBD, a variable of a suitable data type must be connected at the left side of the block icon.
- In ST, the := operator must be used to assign the formal parameter to a suitable variable. Suitable are variables declared as Input, Output, InOut, External, Program, and Instance without the property Constant.
- On output side, an InOut variable may be connected or remain unconnected. When connected, the same applies regarding data types as described for the input side (see previous item).
- In ST, InOut variables cannot be read/written directly using the construct FB_InstanceName.InOutVarName (in contrast to Input and Output variables).
- Bit variables cannot be assigned directly to InOut variables. Instead, an intermediate variable must be used. Error example:
MyFB(MyInOutParam := MyBoolVar, further params);Workaround:
MyTempVar := MyBoolVar;
MyFB(MyInOutParam := MyTempVar, further params);
MyBoolVar := MyTempVar;