Modules | The TwinCAT Component Object Model (TcCOM) concept TcCOM uses GUIDs for: ModulIDs, ClassIDs and InterfaceIDs. 32-bit long integers are used for: ParameterIDs, ObjectIDs, ContextIDs, CategoryID. Interfaces An important component of COM, and therefore of TcCOM too, are interfaces. Interfaces define a set of methods that are combined to perform a certain task. An interface is referenced with a unique ID (InterfaceID), which must never be modified as long as the interface does not change. This ID enables modules to determine whether they can cooperate with other modules. At the same time the development process can take place independently, if the interfaces are clearly defined.
Modifications of interfaces therefore lead to different IDs. The TcCOM concept is designed such that InterfaceIDs can superpose other (older) InterfaceIDs ( "Hides" in the TMC description / TMC editor). In this way, both versions of the interface are available, while on the other hand it is always clear which is the latest InterfaceID. The same concept also exists for the data types. TcCOM itself already defines a whole series of interfaces that are prescribed in some cases (e.g. ITComObject), but are optional in most. Many interfaces only make sense in certain application areas. Other interfaces are so general that they can often be re-used.
Provision is made for customer-defined interfaces, so that two third-party modules can interact with each other, for example. All interfaces are derived from the basic interface ItcUnknown which, like the corresponding interface of COM, provides the basic services for querying other interfaces of the module (TcQueryInterface) and for controlling the service life of the module (TcAddRef and TcRelease). The ITComObject interface, which must be implemented by each module, contains methods for accessing the name, ObjectID, ObjectID of the parent, parameters and state machine of the module. Several general interfaces are used by many modules:
ITcCyclic is implemented by modules, which are called cyclically ("CycleUpdate"). The module can register via the ITcCyclicCaller interface of a TwinCAT task to obtain cyclic calls. The ITcADI interface can be used to access data areas of a module. ITcWatchSource is implemented by default; it facilitates ADS DeviceNotifications and other features. The ITcTask interface, which is implemented by the tasks of the real-time system, provides information about the cycle time, the priority and other task information. The ITComObjectServer interface is implemented by the ObjectServer and referenced by all modules. A whole series of general interfaces has already been defined.
General interfaces have the advantage that their use supports the exchange and recycling of modules. Only if no suitable general interfaces exist should you define your own interfaces. Class Factories "Class Factories" are used for creating modules in C++. All modules contained in a driver have a common Class Factory. The Class Factory registers once with the ObjectServer and offers its services for the creation of certain module classes. The module classes are identified by the unique ClassID of the module.
When the ObjectServer requests a new module (based on the initialization data of the configurator or through other modules at runtime), the module selects the right Class Factory based on the ClassID and triggers creation of the module via its ITcClassFactory interface. Module service life Similar to COM, the service life of a module is determined via a reference counter (RefCounter). The reference counter is incremented whenever a module interface is queried. The counter is decremented when the interface is released. An interface is also queried when a module logs into the ObjectServer (the ITComObject interface), so that the reference counter is at least 1.
The counter is decremented on logout. When the counter reaches 0, the module deletes itself automatically, usually after logout from the ObjectServer. If another module already maintains a reference (has an interface pointer), the module continues to exist, and the interface pointer remains valid, until this pointer is released. TwinCAT 3 36 Version: 1.19.1