Calling a TcCOM object from the PLC

Creating a TcCOM wrapper FB

Set in the export configuration:

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

Working with the TcCOM Wrapper FB

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.

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. See red area in graphic below.

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.

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. In the graphic below, this is the green area as a minimum example and the blue area with extended parameterization.

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.
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('TcComWrapper TemperatureController')