Download project
This example demonstrates how object orientation is used to realize a building which has different
rooms with different functionalities. The included visualization illustrates the implementation.
This example demonstrates an object oriented programming approach. Therefore a building with
different rooms and functionalities was implemented. At daytime, all the light bulbs are switched off
and the air condition is set to 21. At nighttime, all light bulbs are switched on and the temperature
is set to 15. With the manual mode, the light can be switched on and off separately.
The "cellar room" has one light but no service is provided. The "cheap room" also has one light, but
additionally a service is provided which changes the light bulb when the end of its lifetime is reached.
The "better room" has a duo light with the doubled lifetime of a normal room and the "climate better room"
additionally has an air conditioner, where the filter has to be changed after a certain amount of temperature
changes.
Main
: Creates all the four rooms and calls the necessary functions, depending on the mode
(daytime, nighttime, manual).
clsRoom
: Base function block for a room. The necessary functions which are needed for every room
are provided here. All four rooms inherit from this function block.
clsCellarRoom
: Extends the base room and has an instance of the clsLight
function block to
implement the light bulb.
clsCheapRoom
: Extends the base room and includes an instance of the clsLight1min
, which implements
a light bulb with a lifetime of one minute. It also includes the service function.
clsBetterRoom
: Extends the base room and includes an instance of clsDuoLight1min
, which has the
doubled lifetime and it also includes the service function.
clsClimateBetterRoom
: Extends the clsBetterRoom
and adds an air condition.
FB_AirCondition
: The temperature for the day- and nighttime is regulated with the help of this function block.
clsLight
: Base function block which recognizes whether the light is switched on or off.
clsLight1min
: Extends the clsLight
and implements the IService
interface. With this function
the lifetime of the light bulb is monitored.
clsDuoLight1min
: Extends the clsLight1min
with a second timer to double its lifetime.
FB_LifeTimer
: Counts down the lifetime of a switched on light bulb.
Visualization
: The main visualization includes different rooms. Each consists of a light bulb,
a service message, a service display that shows whether a service is needed and two buttons, one to toggle
the light on or off and one to reset the service. The topmost room additionally shows the temperature.
With the "OpMode"
slider the mode can be set to daytime with light, night time without light or manual
to switch the lights on and off separately.
System requirements and restrictions | Info |
---|---|
Programming System | CODESYS Development System Version 3.5.14.0 or higher |
Runtime System | CODESYS Control Version 3.5.14.0 |
Required Accessories | - |