Best practice: access to TcCOM data

Introduction

The section Configuration of data access to data of a TcCOM object described how to set data access to a TcCOM in TC TcCom Interfaces in the configuration parameters of a Simulink® model. In the following, advantages and disadvantages and also application scenarios as well as useful hints are given as to when which type of data access to a TcCOM may be useful.

Access via ADS

Properties

Use Cases

Notes

Access via mapping

Properties

Use Cases

Notes

Access via Data Pointer

Properties

Use Cases

Best practice: access to TcCOM data 1:

Data Pointer example

An example can be found here: Shared memory between TcCOM instances.

Exported Global/Imported external

Properties

Use Cases

Best practice: access to TcCOM data 2:

Example for Exported Global/Imported external

An example can be found here: Shared memory between TcCOM instances.

Special case: Interaction via the TcCOM Wrapper FB

The TcCOM Wrapper FB (see Applying the TcCOM Wrapper FB) simplifies the interaction between PLC and TcCOM. This FB primarily enables, with little programming effort, the cyclic execution of the linked TcCOM object from the PLC code, including the exchange of input and output data. However, it also allows simple acyclic access to the object's parameters and, if required, flexible access to the DataAreas as well.

The wrapper provides the ITcADI interface (see ADI Interface) on the one hand and (optionally) properties on the function block (see FB properties) on the other. The TcCOM Wrapper FB should be called in the same context as the TcCOM.

Function block properties

ITcADI interface

Changes persist

Above, it was described how data can be changed in a TcCOM instance at TwinCAT runtime. If TwinCAT is restarted, these changes will be lost unless further recovery measures have been taken. The default behavior of a TcCOM is that when a TcCOM instance is started, the parameterization is performed according to its Startup Values.

In addition, remanent variables can be defined that retain their value beyond the usual program runtime. Remanent variables can be declared as RETAIN variables or even more strictly as PERSISTENT variables.

More information about remanent data (Persistent and Retain) in the TwinCAT PLC: Link

In the following three ways are described in which values can be restored after restarting TwinCAT.

1) Startup values

See Parameterization of a module instance for differentiation between Online, Prepared, Default and Startup Values.

Best practice: access to TcCOM data 3:

TwinCAT 3 XAE necessary

Startup values are changed in the TwinCAT configuration, i.e. in the engineering. Changes can be entered here. However, the change must be compiled and downloaded to the runtime system.

If online values are changed during runtime, you can read the current online values via ADS, for example. This can be done, for example, with the TE1410 TwinCAT Interface for MATLAB®/Simulink®. The read values can then be entered as new startup values in the TwinCAT configuration.

Use the Automation Interface example for this purpose:

TwinCAT.ModuleGenerator.Samples.Show('AutomationInterface')

In the example, a live script is used to show different functions. The section Read and write parameter online values via ADS describes how to read and write online values from a TcCOM. The section Read and change parameter startup value describes how to read and also write startup values.

The new startup values are entered in the TwinCAT configuration on the engineering system. To make the changes available on the runtime system, you must activate the configuration on the system. You can also realize this with the Automation Interface (sysManager.ActivateConfiguration). You can either restart the system directly via Automation Interface (sysManager.StartRestartTwinCAT), or you can let the system run without restarting. At the next start of TwinCAT, the startup values are set and the TcCOM starts up with the new startup values.

2) Retain Data

At TC TcCom Interfaces you can create the model parameters (and also other groups) as DataArea of type Retain Source DataArea. You can then create a retain handler in the TwinCAT configuration and connect it to the DataArea. For details see NOV-RAM and Retain Handler.

Best practice: access to TcCOM data 4:

NOV RAM necessary

To work with the Retain Handler, you need an IPC/CX with built-in NOV-RAM. The use of an EtherCAT Terminal with NOV-RAM (e.g. EL6080) is not supported.

3) Persistent Data

You can access persistent data in the TwinCAT 3 PLC without TwinCAT XAE and without NOV-RAM.

Best practice: access to TcCOM data 5:

TwinCAT 3 PLC runtime required

To use persistent data, you must declare variables as persistent in the PLC.

Persistent data can only be created in the PLC. Therefore, use the PLC to define the data you want to persist. Work with the TcCOM Wrapper FB, for example, to read data from the TcCOM and persist them via the persistent PLC variable. Create a state machine for starting the TcCOM object after a TwinCAT restart in order to write the persisted data back into the TcCOM object before it is called again in the code.