Skip to main content

Example: Object-Oriented Programming (Extended)

Product: CODESYS Development System

This example shows how object orientation is used to realize a building which has different rooms with different functionalities. The included visualization illustrates the implementation.

_example_img_oop_extended.png

Description

This example shows an object-oriented programming approach. For this purpose, a building with various rooms and functionalities was implemented. During the day, all light bulbs are off and the air conditioning is set to 21°C. At night, all light bulbs are on and the temperature is set at 15°C. With the manual mode, the light can be switched on and off separately. The CellarRoom has one light, but no service is provided. The CheapRoom also has one light, but a service is additionally provided to replace the light bulb at the end of its lifetime. The BetterRoom has a duo light with twice the lifetime of a normal room, and the ClimateBetterRoom additionally has an air conditioner whose filter has to be changed after a specific number of temperature changes.

Additional information

  • Main: Creates all four rooms and calls the required functions, depending on the mode (daytime, nighttime, manual)

  • clsRoom: Base function block for a room. The necessary functions which are required 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 function block, 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 twice the lifetime and also includes the service function

  • clsClimateBetterRoom: Extends the clsBetterRoom and adds an air conditioner

  • FB_AirCondition: This function block regulates the temperature for daytime and nighttime.

  • clsLight: Base function block which detects whether the light is on or off

  • clsLight1min: Extends the clsLight function block and implements the IService interface. This function is used to monitor the lifetime of the light bulb.

  • clsDuoLight1min: Extends the clsLight1min function block by a second timer to double the lifetime

  • FB_LifeTimer: Counts down the lifetime of a switched-on light bulb

  • Visualization: The main visualization includes different rooms. Each room consists of the following elements:

    • 1 light bulb

    • 1 service message

    • 1 service display (shows whether service is required)

    • 1 button to toggle the light on and off

    • 1 button to reset the service

    The top room additionally displays the temperature. The OpMode slider can be used to set the mode to "daytime with light", "nighttime without light" or "manual".

System requirements and restrictions

Programming system

CODESYS Development System (version 3.5.14.0 or higher)

Runtime system

CODESYS Control Win (version 3.5.14.0)

Add-on components

-

Note

_example_icon.png DOWNLOAD Project