top of page
rajshaswat

Object Oriented Programming in PLC (OOPS) & Supported PLC

Updated: Dec 24, 2023

With paradigm shift in Industries and manufacturing after the revolution of Industry 4.0 & IoT there is lot of buzz in Automation Industry to change the way of programming for PLC. Both options of programming has their own Pro's and Con's so this article does not tells which one is better.

As major player like #Codesys, #Siemens (#Rockwell will also join the change) have changed their IDE to support this concept in more enhanced way and acceptance by PLCOpen group by providing guidelines is making us to think is it the good time to start in this direction.

One of the benefit of OOP concept is it helps towards modularity and better structure of code and can be very useful when we are working in collaboration or creating library.


But was this not happening earlier or we are achieving something more better? Let's check it out how Object Oriented Programming in PLC (OOPS) is supported


Programming Language Used in PLC:


Most of the PLC support below set of languages IEC 61131-3

  • Ladder Logic (LD)

  • Function Bock Diagram (FBD)

  • Sequential Flow Chart (SFC)

  • Structured Text (ST)

  • Instruction List (IL)


Below are Vendor Specific Languages

  • Continuous Function Chart (CFC)

  • Structured Control Language (SCL)

  • C/C++ source code (this support OOP)


because of IOT IT and OT started coming more closer then ever and when there is a interaction we try to learn and adopt good things from each other. which brings the buzz why we can not use Object Oriented Programming (OOP) concept in OT world.


But Wait ........ were we not using it earlier in PLC Programming?


Earlier we were using LD,FBD because Industry was more oriented towards electrical design & Digital design and during maintenance or troubleshooting it was easy and skillset in Industry were more skilled in electrical and digital design rather than skilled in IT application coding practices as it was not the need.Few of the PLC were supporting like GE Proficy Machine Edition to import C source code into PLC.

With new generation getting adept in IT Programming from Schools/University bring more skilled resources who are aware about OOP with Electrical & Digital design and cherry on cake is now PLC IDE also started supporting these concept in more advanced form.


On 18 Nov 2021 even PLCOpen group introduced Object Oriented Programming Guidelines in their standard and also provided examples how to convert "Classical Program" to an Object Oriented Program.



What is Object Oriented Programming ? How it can help in PLC Programming.


OOP as name suggest programming language oriented towards Object


what is Object ?

An Object is the instance of Class


so let's map it in OT :

Class---> Function Block /UDT



Object ---> Instance of Function Block




Let's see which all PLC support these

Function Block/UDT is supported by Most of PLC and we call any function block by creating instance of function block which means most of the PLC is supporting basic concept of OOPS programming.


OOPS are very predominant in IT coding and almost all the Languages support these i.e. C++, C#, Python , Java etc... but what about OT they don't have these application language( some IDE support C/C++) so whether these concept can be applied also in Ladder, FBD, ST, SFC ? and whether PLC IDE support these concept.


OOP has four major Pillars which are

**Example shown are using Codesys IDE

  • Encapsulation :Process of wrapping code and data together into a single unit using access Modifier

Private Encapsulated Function Block


Encapsulated Block with Needed Configuration Parameters


  • Abstraction: Presenting the easy way to user by hiding complex implementation & allowing user to implement client program easily.

It can be achieved by two ways :Abstract Function Block & Interface

Abstract Function Block & Abstract Method


Interface


Implementation in another Function Block


Interface vs Abstract Function Block

Interface

Abstract Function Block

​References

It will always use "Implement" keywoard

It will be extended by "Extends" keyword

Pic:1

Only Abstract Method

Abstract Function Block can have abstract and non-abstract methods.

​Pic:2

Interface supports multiple inheritance.

Abstract Function Block doesn't support multiple inheritance

​Pic:3

Local Variable can not be declared

Local Variable can be declared exception is Abstract Method.

Pic:4

It can not extends any function block

It can extends Function Block as well as implement Interface

Pic:1

Members of a interface are public by default.

​Abstract Function Block can have class members like Private, Protected, Public, Internal

​Pic6(a, b, c, d)

Interface Can only have Methods & Property

User can add Action ,Method, Property & Transition

​**Codesys Options

Instance of Interface is Allowed

Abstract Function Block Instance is Not allowed but it can be referenced using "REFERENCE" keyword also can be used with Pointer.

​**Codesys Options

Pic:5




Pic:1



Pic:2


Pic:3




Pic:4


Pic:5


Interface Property Add


Pic6a

Abstract Function Block Property Add

Pic6b

Interface only Public but Abstract Function Block Support Private ,Public, Protected & Internal

Pic6c

Pic6d

  • Inheritance: A mechanism which allow a one class to inherit the properties, behavior from the other Class.

Pressure Function Block Inherit from FB_Sensor using EXTENDS


  • Polymorphism: Poly "Many" Morphism "Form" this state when same Object can be processed in many form.

It is of Two Type :

  • Static or Compile Time (Method Overloading)

  • Dynamic or Run Time (Method Overriding)

Compile Time Polymorphism is not supported.


Below example is shown for Run Time Polymorphism which can be achieved by using Inheritance and Interface using REFERANCE


A Function Block RotatingDevice having method Start with an interlock condition to provide start command as output.

Function Block Pump Inherits from RotatingDevice and Override the Start Method where Start command is without any interlock

Implemented the Start method in Pump


Instance of rotatingdevice as productionPump and Instance of Pump as MaintenancePump and P101 a REFERENCE to rotatingdevice



Now when MaintenanceMode is False then the pump is taking the Start Method of rotatingdevice


Till Interlock is False the Start command given as input is able to provide output start command

Inp_start_cmd:=True;

statuscmd:=True;

interlock:=False;

As Interlock is True the Start command given as input is not able to provide output start command

Inp_start_cmd:=True;

statuscmd:=False;

interlock:=True;

MaintenanceMode:=False


As MaintenanceMode is True the Start command given as input is able to provide output start command even Interlock is True which means the reference changed from rotatingdevice to Pump which has a start method without interlock


Inp_start_cmd:=True;

statuscmd:=True;

interlock:=True;

MaintenanceMode:=True


Interlock has no impact


Inp_start_cmd:=True;

statuscmd:=True;

interlock:=False;

MaintenanceMode:=True




so below are the list of PLC IDE marked with level of support we have now in each.

**Note below list based on my personal experience

Manufacturer Name

Development IDE

OOP/OIP Support

Siemens

TIA Portal

Class -->Function Block(FB)

Object-->Instance of FB

Encapsulation-->Variable Type

Siemens

Simatic AX (S7-1500)

Based on Visual Studio Code

Support Plain Text Editor (NO XML)

Still not available in all region


​Class -->Function Block(FB)

Object-->Instance of FB

Encapsulation-->Variable Type

Inheritance-->Extends

Abstraction-->Interface Abstract Class

Polymorphism-->Can Support Full (Not Tested)

​Rockwell Automation/Allen Bradely

Studio 5000

Class -->Function Block(FB)

Object-->Instance of FB

Encapsulation-->Variable Type

Emerson (General Electric)

Proficy Machine Edition

Class -->Function Block(FB)

Object-->Instance of FB

Encapsulation-->Variable Type

Phoenix Contact

PLCNext Engineer

​Class -->Function Block(FB)

Object-->Instance of FB

Encapsulation-->Variable Type

Inheritance-->Extends

Abstraction-->Interface Abstract Class

Polymorphism-->Interface Inheritance

Beckhoff Automation

TwinCat3

​Class -->Function Block(FB)

Object-->Instance of FB

Encapsulation-->Variable Type

Inheritance-->Extends

Abstraction-->Interface Abstract Class

Polymorphism-->Interface Inheritance

Mitsubishi Electric

GX Works

Class -->Function Block(FB)

Object-->Instance of FB

Encapsulation-->Variable Type

Codesys

Codesys Development Gmbh

​Class -->Function Block(FB)

Object-->Instance of FB

Encapsulation-->Variable Type

Inheritance-->Extends

Abstraction-->Interface Abstract Class

Polymorphism-->Interface Inheritance

Arduino PLC

Arduino PLC IDE

New Buzz in market Coming Fully Loaded.

​Class -->Function Block(FB)

Object-->Instance of FB

Encapsulation-->Variable Type

Inheritance-->Extends

Abstraction-->Interface Abstract Class

Polymorphism-->Interface Inheritance

*Mitsubishi Electric has collaborated with Codesys


PLC Based on Codesys


  • 4WEB-Automation GmbH

  • ABB AG

  • Advantech

  • Altus Sistemas de Automação S.A.

  • ANEDO GmbH

  • Automata GmbH & Co. KG

  • Beijer Electronics

  • Berghof Automation GmbH

  • Bosch Rexroth AG

  • Camille Bauer Metrawatt AG

  • Christ Electronic Systems GmbH

  • CODESYS GmbH

  • Contec Co., Ltd.

  • Crevis

  • CrossControl

  • Danieli Automation SpA

  • Deep Sea Electronics Ltd

  • DEIF A/S

  • Delta Electronics, Inc.

  • Eaton

  • Eckelmann AG

  • EKE-Electronics Ltd.

  • elrest

  • ELSIST Srl

  • Exor International S.p.A.

  • Festo SE & Co. KG

  • Hans Turck GmbH & Co. KG

  • Hitachi Europe GmbH

  • ifm electronic gmbh

  • Inovance

  • INTER CONTROL

  • Janz Tec AG

  • JUMO GmbH & Co. KG

  • KEB Automation KG

  • KEBA Industrial Automation GmbH

  • Kendrion Kuhnke Automation GmbH

  • Kontron Electronics AG

  • Lenze SE

  • NEXO SRL

  • NUM AG

  • Opto 22

  • Parker Hannifin Manufacturing Germany GmbH & Co. KG

  • Pixsys Srl

  • powerIO GmbH

  • SCHRAML GmbH

  • Schubert System Elektronik

  • Sensor-Technik Wiedemann GmbH

  • sm motion control gmbh

  • Sontheim Industrie Elektronik GmbH

  • Topcon Electronics GmbH & Co. KG

  • TRsystems GmbH

  • TTControl

  • WAGO GmbH & Co. KG

  • WEG Drives & Controls

  • WIKA Mobile Control GmbH & Co. KG

  • MakerPRO from Compressor Control Corporation for Prodigy PLC

So looks like we have now most of features and PLC to proceed in the direction of OOPS concept in Industrial Programming. so Let's try it out and get aligned with new age dimensions of Industry4.0 with IoT/IIoT connected System




Links for Video Tutorial for Object Oriented Programming using Codesys

Object Oriented Programming Classes & Object in PLC

Encapsulation & Inheritance in PLC

Abstraction ,Abstract Class & Interface in PLC


PolyMorphism



1,456 views3 comments

3 Comments


Can you share the code


Like
Replying to

yes please, the one used on the tutorials. can you archive it and send it to me

Like
bottom of page