Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
280 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...