Limitations
TwinCAT 3 C++ modules are executed in Windows kernel mode. Developers must therefore be aware of some limitations:
- Win32 API is not available in kernel mode
- Windows kernel mode API must not be used directly.
TwinCAT SDK provides functions, which are supported. - User mode libraries (DLL) cannot be used. (see Third Party Libraries)
- The memory capacity for dynamic allocation in a real-time context is limited by the router memory (this can be configured during engineering), see Memory allocation.
- A subset of the C++ runtime library functions (CRT) is supported
- C++ exceptions are not supported.
- Runtime Type Information (RTTI) is not supported.
- Subset of STL is supported (see STL / Containers)
- Support for functions from math.h through TwinCAT implementation (see Mathematical Functions)
TwinCAT functions as replacement for Win32 API functions
The original Win32 API is not available in Windows kernel mode. For this reason a list of the common functions of the Win32 API and their equivalents for TwinCAT is provided here:
Win32API | TwinCAT functionality |
WinSock | TF6311 TCP/UDP real-time |
Message boxes | |
File I/O | See Interface ITcFileAccess, Interface ITcFileAccessAsync and Sample19: Synchronous File Access, Sample20: FileIO-Write, Sample20a: FileIO-Cyclic Read / Write |
Synchronization | See Sample11a: Module communication: C module calls a method of another C module |
Visual C CRT | See RtlR0.h |
RTTI dynamic_cast function in TwinCAT
TwinCAT has no support for dynamic_cast<>.
Instead, it may be possible to use the TCOM strategy. Define an ICustom interface, which is derived from ITcUnknown and contains the methods, which are called from a derived class. The base class CMyBase is derived from ITcUnknown and implements this interface. The class CMyDerived is derived from CMyBase and from ICustom. It overwrites the TcQueryInterface method, which can then be used instead of dynamic cast.
TcQueryInterface can also be used to display the IsType() function through evaluation of the return value.
See Interface ITcUnknown.