Suppose I have a function block POU1
which has local variables val1: INT
and val2: INT
, e.g.
FUNCTION_BLOCK POU1
VAR
val1: INT := 1;
val2: INT := 1;
END_VAR
Now suppose the user of the FB declares it as RETAIN
, e.g.
VAR RETAIN
p1: POU1;
END_VAR
p1.val1 := 2;
p1.val2 := 2;
This will result in both val1
and val2
retaining the value of 2 in case of a warm reset, but what if I don't want that to happen to say val2
i.e. I want val1
to retain it's current value, but val2
to be reset in case of a warm reset (if the user declares my FB as RETAIN
, otherwise I want both to reset)
How can I achieve this? (Also. same question goes for PERSISTENT
)
PS. I tried {attribute 'init_on_onlchange'}
and {attribute 'no_copy'}
but they did nothing (maybe I used them wrong?). I also tried creating an additional FB with {attribute 'no_instance_in_retain'}
and adding it as a local variable of POU1
but that resulted in a build error.