Skip to main content

Data Sampling with Trace

You can use a Trace to follow the value curve of variables on the controller in a similar way as a digital sampling oscilloscope. At application runtime with trace, all statements are executed first within the task cycle. Then, data sampling starts with value storage including time stamps. These time stamps are relative and refer to the start time of the data sampling. The data yields a discrete time signal and CODESYS displays its course in the trace editor.

A "sample" (data record) is composed of the value and the time stamp. The runtime system writes the samples to a buffer with a definable size. CODESYS requests the data, saves it in the trace editor buffer, and displays it in the trace diagram as a function of time. You can monitor the value curve of the configured variables continually because CODESYS displays the latest data.

You can provide a trigger to the data sampling. When the trigger is released, the data sampling is halted and the data is displayed around the trigger time.

The configuration and the display of a trace are possible in the CODESYS project by means of trace objects in the trace editor. There are the following two object types:

  • Trace: Inserted below the IEC application in the device tree. This kind of object always contains strictly an application-specific trace configuration. You can download this trace configuration to the controller and run it with the application.

  • DeviceTrace: Inserted below the device object in the device tree. If the PLC supports a "Trace Manager", then you can use one or more DeviceTrace objects to access one or more traces that are running on the controller. These can be both application-specific or controller-specific traces. For example, a controller can support traces for recording the processor load. Menu commands allow for access from the CODESYS project to the Trace Manager in the device.

Access to the Trace Manager from IEC code is possible by means of the functions from the library CmpTraceMgr.library. For more information, see the library documentation.

Important

A running data sampling with trace can lead to a significant increase in the cycle time of the IEC task.

Important

Data sampling with trace also continues running after logging out of the device.

Runtime system component CmpTraceMgr, Trace Manager

The device description of a runtime system with Trace Manager includes the tracemanager entry in the TargetSettings section.

In this case, CODESYS transfers only the trace configuration when downloading the application to the PLC. When you start the trace, the application interprets the configuration on the RTS by means of the Trace Manager, executes the data sampling, and buffers the data sets on the controller.

The CmpTraceMgr runtime system component provides extended functionality, as compared to data sampling with IEC code.

Data sampling is therefore possible as follows:

  • Parameters on the controller (for example, the processor load (cpuload, plcload), or the temperature curve of a CPU or a battery)

    The measurement of the processor load per processor core (cpuload) is interesting for multicore controllers.

  • Device signals (for example, the current path of a drive)

  • System variables of another runtime system component

You can configure parameters like IEC variables in the Trace Configuration dialog of the Variable Settings.

The display of traces that run on the controller is possible in the trace editor of a DeviceTrace object.

Data sampling after triggering

To monitor data that depends on an event or a condition, you can free the data sampling that depends on a trigger. At runtime, the application checks whether the event has occurred or the condition is fulfilled, and then it buffers the data accordingly.

The trace configuration allows for triggering by the following:

  • A trigger variable that maps the event

  • A condition as expression

  • A combination of trigger variable and condition

Saving samples to a file

You can save samples from the development system to a file. The file can also include the trace configuration.

Table 1. Possible file formats

File Extension

File Type

Description

*.trace:

Trace file

Contains the samples and the trace configuration in XML format

You can execute the Load Trace command to load the file to the trace editor when offline and analyze the samples without a PLC.

*.txt

Text file

Contains the samples in ASCII format

You can edit the file with an external tool.

*.trace.csv

Trace dump

File in CSV format includes the trace configuration and optional samples

You can create the file by clicking Export Symbolic Trace Config. You can transfer the file to the PLC and load it to the application. Then, execute the Load Trace command in CODESYS to display this in the trace editor.

You can also click Trace → Save Trace and select the *.trace.csv file format. You can transfer the file to the PLC and load it with an HMI for analysis.

*.traceconfig

Symbolic trace configuration

Contains the trace configuration CSV format

You can create the file by clicking Export Symbolic Trace Config. The CmpTraceMgr runtime system component can read the file.



For more information, see: Trace