Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
282 views
in Technique[技术] by (71.8m points)

plc - Table of pointers

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.

question from:https://stackoverflow.com/questions/65909692/table-of-pointers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...