beckhoff TwinCAT 3 — 15.25.3.2 Creating an FB in the PLC that creates the C++ object and offers its functionality

C++-samples | TcCOM samples 4. Add the FB_init constructor method to the PLC Proxy function block. For the case, that it is not an online change but rather the initialization of the function block, a new TcCOM object (Class instance of the specified class) is created and the interface pointer to the specified interface is obtained. First, the versioned class ID is calculated from the library ID and the class ID using the F_GetClassIdVersioned() method. Then the used FW_ObjMgr_CreateAndInitInstance() function is also given the name and the target state of the TcCOM object.

These two parameters are declared here as input parameters of the FB_init method, whereby they are to be specified in the instantiation of the Proxy function block. The TwinCAT C++ class to be instantiated does without TcCOM initialization data and without TcCOM parameters. With this function call the object itself counts up a reference counter. 5. It is imperative to release the used reference again and to delete the object, provided it is no longer being used. To this end call the FW_ObjMgr_DeleteInstance() function in the FB_exit destructor of the function block. 6.

Declare an instance of the Proxy function block to call the methods provided via the interface in the р This completes the implementation of the Proxy function block. application. The calls themselves take all place over the interface pointer defined as output of the function block. As is typical for pointers a prior null check must be made. Then the methods can be called directly, also via Intellisense. р The sample is ready for testing. TwinCAT 3 321 Version: 1.19.1