When I wrote the first program all the code was place in the main PLC_PRG task. As the program was growing the need for splitting the code into sub-programs and task became evident. Here are the rules that I have followed:
In the main PLC_PRG program all the 'regular' commands are placed: for controlling the lights, sockets, blinds and heaters. I have placed in separate programs the following tasks:
Finally my list of programs and the tree of processes looks as follows:
Function blocks, functions and program RS232 are described in a separate article.
The program SQL_DataStorage is also described in a dedicated article, the GardenRecorder function block collects tha information about opening/closing of sprinklers.
DataSaveToFile makes it possible to write data to csv files. Since the communication with a SQL database is working flawlessly, this proces is no longer used.
EmailSender sends emails when something important happens - it informs me about alarms, triggered movement sensor and all the movements in the house within a few minutes after the alarm was launched.
ReadClock is responsible for updating the global variable CURRENT_TIME as well as CALENDAR_CALC and CALENDAR from the OSCAT library. I read some time ago that reading the real-time clock consumes significant portion of the processing power and should not be done in the main program. The task Update_Clock calling the RadClock() program is executed every second.
SensorReader reads all analog inputs every second and correct the values by a value fond empirically.
Timers manages all the schedulers (FbScheduleweekly z Building_common.lib) and is run every second.,
VIS_Management updated some visualization.
In order to add a new program, function block or a function, one needs to right-click on the window with programs (POUs) and choose Add Object.
In order to add a task on the task list in the Resources tab, one needs to choose Task configuration, right-click on the task list and click Append Task. The new task needs to have a name, a priority and a Type where:
When a new task is ready, it needs to receive a program call. Right-click on the task and choose Append Program Call. For example, my MainTask calls the PLC_PROG().