Assignment attempt in ST
Syntax
interface_variable_1 ?= interface_variable_2;
Meaning |
assignment attempt of a variable based on an →interface by using the operator
"?=" to a different
variable based on an →interface to check wheter the interface is implemented If the referenced instance is a →function block that implements the interface, the result is a valid reference to this instance. Otherwise, the result is NULL.. Deviation from IEC-standard logi.CAD 3 does not support assignment attempts for →references (using REF_TO). |
Example
INTERFACE IF1
END_INTERFACE
INTERFACE IF2
END_INTERFACE
INTERFACE IF3
END_INTERFACE
FUNCTION_BLOCK FB1 IMPLEMENTS IF1, IF2
VAR
Var1 : INT;
END_VAR
END_FUNCTION_BLOCK
FUNCTION_BLOCK FB2
VAR
iFB1 : FB1;
IF1Var1, IF1Var2 : IF1;
IF2Var : IF2;
IF3Var : IF3;
END_VAR
(* assignment *)
IF1Var1 := iFB1;
// correct assignment: Variable IF1Var1 is based on the interface IF1, the function block type of iFB1 implements the same interface.
// Hence, IF1Var1 contains a valid reference.
IF1Var2 := IF1Var1;
// correct assignment: Variable IF1Var2 is based on the interface IF1, the variable IF1Var1 is is based on the same interface.
// Hence, IF1Var2 contains a valid reference.
(* assignment attempts *)
IF1Var2 ?= IF1Var1;
// valid reference: The variables are based on the same interface.
// Is equal to this assignment: IF1Var2 := iFB1;
IF2Var ?= IF1Var1;
// valid reference: The variable IF1Var1 is based on the interface IF1, the variable IF2Var is based on the interface IF2.
// Both interfaces are implemented by FB1 and - due to the 1st assignment - IF1Var1 has the value of the instace iFB1 (this instance is of type FB1).
IF1Var2 ?= IF2Var;
// valid reference: The variable IF2Var is based on the interface IF2, the variable IF1Var2 is based on the interface IF1.
// Both interfaces are implemented by FB1 and - due to the previos assignment attempt - IF2Var has the value of the instace iFB1 (this instance is of type FB1).
IF3Var ?= IF1Var1;
// Due to the first assignment: IF1Var1 has the value of the instance iFB1 (this instance is of type FB1). The variable IF3Var is based on the interface IF3. FB1 does NOT implement the interface IF3.
// result of the assignment attempt: IF3Var is NULL.
END_FUNCTION_BLOCK