Calling a TcCOM object from the PLC

Creating a TcCOM wrapper FB

Set in the export configuration:

TcCom.TcComWrapperFb = 'true';
TcCom.TcComWrapperFbProperties = 'true'; % optional

Create instance of the TcCOM Wrapper function block

1. Create a PLC project.
2. Add the desired library under References.
Calling a TcCOM object from the PLC 1:
Under Pous/TcCOM Wrapper you get a function block that you can instantiate in the PLC. In addition, necessary data types are created in the Duts folder.

Version 1: referencing a static module instance

The function block can be used to access module instances previously created in the XAE, e.g. under System > TcCOM Objects. For this static case, the object ID of the corresponding module instance must be transferred during declaration of the function block instance.

Calling a TcCOM object from the PLC 2:
  • The instance of the TcCOM object and the calling PLC must run in the same task.
  • On the instance of the TcCOM object, make sure that under Parameter (Init) the entry ModuleCaller is set to Module and not to CyclicTask.
  • In this case, the required memory for the TcCOM is obtained from the non paged pool of the system.

Declaration

// link wrapper with a static instance 
InitStrStatic      : ST_FB_TempCtrl_TcCOM_InitStruct := (noid := 16#01010010);   // OID from object1 in System > TcCOM Objects
fbTempCtrStatic    : FB_TempCtrl_TcCOM_InitStruct(InitStrStatic);
Inputs             : ST_TempCtrl_U_T;      // data type defined in TempCtrl library
Outputs            : ST_TempCtrl_Y_T;

Execution code

fbTempCtrStatic(stTempCtrl_U := Inputs, stTempCtrl_Y => Outputs);

Version 2: dynamic instantiation and referencing from the PLC

The function block can also be used in such a way that a TcCOM object is generated from the PLC and linked to the wrapper.

Calling a TcCOM object from the PLC 3:
  • The TaskOid of the PLC task must be used to specify the real-time task in which the wrapper is called.
  • The ModuleCaller must also be set to Module here (via the Init structure).
  • In this case, the required memory for the TcCOM is obtained from the router memory.

Declaration

// dynamic instance: create TcCOM from PLC
InitStrDyn          : ST_FB_TempCtrl_TcCOM_InitStruct := (
                        nTaskOid      := 16#02010030,             // take TaskOID of PlcTask
                        eModuleCaller   := E_ModuleCaller.Module );      // set module caller to "call by module"
fbTempCtrDyn        : FB_TempCtrl_TcCOM_InitStruct(InitStrDyn);
OutputsDyn          : ST_TempCtrl_Y_T;

Execution code

fbTempCtrDyn(stTempCtrl_U := Inputs, stTempCtrl_Y => OutputsDyn);
Calling a TcCOM object from the PLC 4:

The source code for the graph shown above is available in MATLAB® via the Command Window

TwinCAT.ModuleGenerator.Samples.Start("TcCOM Wrapper Function Blocks")