🧩 Can You Use C++ in CODESYS?
Not directly. CODESYS is designed around PLC programming languages (LD, ST, FBD,
SFC, etc.), not C++.
However, you can extend or interact with CODESYS systems using C++ in a few
specific ways:
✅ Option 1: C++ for External Libraries or Modules
You can write external C/C++ libraries (DLLs or shared libraries) and call them
from CODESYS if your runtime supports this.
Use CODESYS External Library Tool to define interfaces.
This is typically done via SysLib or C-Interface APIs.
Useful when integrating custom hardware drivers, algorithms, or real-time code.
✅ Option 2: Use C++ on a Separate System and Communicate
Run your C++ code on a separate device or PC and communicate with the CODESYS
controller via:
Modbus TCP/RTU
OPC UA
MQTT
Shared memory or socket communication
This is common in hybrid systems where C++ handles high-performance computation,
and CODESYS controls I/O.
✅ Option 3: CODESYS Control Runtime Customization (Advanced)
If you're building a custom device or adapting CODESYS Runtime to embedded Linux,
you can embed C/C++ code in your runtime layer. This is very advanced and only for
system integrators or OEMs.
❌ Not Possible: Writing PLC Programs in C++
You cannot write PLC logic in C++ directly within the CODESYS IDE. The supported
logic languages are:
Ladder Diagram (LD)
Structured Text (ST)
Function Block Diagram (FBD)
Sequential Function Chart (SFC)
Continuous Function Chart (CFC)
🔁 Example: Calling a C++ DLL from Structured Text
If you expose a simple C++ function like:
cpp
Copiar
Editar
extern "C" int add(int a, int b) {
return a + b;
}
You can compile it into a shared library and import it in CODESYS using a function
prototype in a CODESYS Library.
But this requires:
Creating a CODESYS library project
Using the External Library Manager
Targeting a platform that supports C calls