Download project

Trend API Example

The "Trend API Example" demonstrates how the VisuTrendStorageAccess library provides function blocks for reading trend data. This document illustrates how to use the library.

Product description

The sample project demonstrates how trend data can be read by means of the VisuTrendStorageAccess library. In this example, trend data is saved by the trend recording manager and then read as ST code by the VisuTrendStorageAccess API.
In addition to querying historical data, active messaging is also possible when saving new data. The trend data can then be exported (example: CSV file) for later processing by other applications, for example by using the IIoT Libraries SL from the CODESYS Store.

More information

In the sample project "TrendStorage API Example.project", four tasks are defined.

  • The "Standard task" calls the PLC_PRG program for simulating data.
  • The simulated data is saved to the database by the "TrendRecordingTask" and the Trend Recording Manager.
  • The "VISU_TASK" is responsible for updating the visualization.
  • The actual reading of trend data is performed by "Task200ms", the "TrendStorageAPI_TestProg" program, and the
    "TrendStorageReader" function block.

The ITrendStorageWriterListener interface is used for active messaging of new data. For this purpose,
the TrendStorageWriterListener function block implements the ITrendStorageWriterListener interface and is
registered for the TrendStorageReader function block. If new data has been saved, then the DataWritten method
is called with the start and end time stamps and the number of saved data records.

The TrendStorageReader and the Read method are used for searching for data records.

eError2 := instTrendStorageReader.Read(
liTimstampFrom  := liTimstampFrom2,
liTimstampTo        := liTimstampTo2,
itfTrendStorageReaderConsumer := instTrendStorageReaderConsumer);

The TimeStampRead and ValueRead methods are then called automatically for each value.
In the example, the TrendStorageReaderConsumer function block implements the ITrendStorageReaderConsumer
interface and writes the values to the controller console in CSV format. If the size of the returned data would
block the database too long, then ETrendStorageReaderErrors.AdditionalReadCallRequired is returned as error code
and the read process must be continued at a later time by calling the ContinueReading method with the same parameters.

Description of the visualization

The simulated signals are displayed in a trend element in the upper area of the visualization.

  • The minimum and maximum time stamps of the trend data are displayed in the "Min/Max Time" tab (see Figure 1).
  • The current values of the DataWritten method are displayed in "New Data" (see Figure 2).
  • Values are searched in the "Read Values" tab (see Figure 3).

The start time stamp is displayed in the upper field and the end time stamp in the lower field.
The "Compute timestamps" button converts the specified data into the corresponding time stamp (reverse function:
"Compute date/time"). Then the search can be started by clicking the "Read Trend Storage" button.
Clicking "Stop Reading" will cancel the read process. If the "Detailed output" button is active, then the data
is printed to the controller console (do not start CODESYS Control Win V3 via SysTray).
Otherwise, the number of data records is displayed in the "count rows" field.

System requirements and restrictions

System requirements and restrictions Info
Programming System CODESYS Development System Version or higher
Runtime System CODESYS Control Version
Required Accessories -

Screenshot thumbnail
Tab "Min/Max Time"
Screenshot thumbnail
Tab "New Data"
Screenshot thumbnail
Tab "Read Values"