I'm using Wago PLC - PFC200 - for home automation. I already did most of the things like lights or blinds automation. Recently I decided to do some refactoring and I started to think that such PLC is not a PC with a garbage collector and it might be beneficial instead of passing POU's in the table pass pointers to those POU's.
I started with something like this:
Declaration:
VAR
Lighs: ARRAY [1..siTotalLightsCount] OF Relay;
END_VAR
where Relay
is my POU (program organization unit - like a class).
Initialization:
Lighs[1] := MainLightRelay;
Lighs[2] := WindowLightRelay;
Lighs[3] := IslandLightRelay;
Usage in POU method:
FOR siCurrent := 1 TO siTotalLightsCount DO
Lighs[siCurrent].xCentralOff := xCentralOffSignal;
END_FOR
But I might be beneficial to save some memory for variables and go with such an approach:
Declaration:
VAR
Lighs: ARRAY [1..siTotalLightsCount] OF POINTER TO Relay;
END_VAR
Initialization:
Lighs[1] := ADR(MainLightRelay);
Lighs[2] := ADR(WindowLightRelay);
Lighs[3] := ADR(IslandLightRelay);
Usage in POU method:
FOR siCurrent := 1 TO siTotalLightsCount DO
Lighs[siCurrent]^.xCentralOff := xCentralOffSignal;
END_FOR
Is that make sense? I had like 15 rooms in my home, most of the rooms has more than one light (so more Relay
objects). It's not much, however, PLC is not PC, there are some memory constraints.