Tutorial: Apply Trends
The Trend component provides the functionality to store variable values in the database and display the history. Writing the values is done on the Codesys side, eDesign provides a library for this. Reading (displaying) is done on the HMI side.
CODESYS Setup
The first step to set up the trends is to write values in CoDeSys. Download the latest eDesign library and insert it into your project. The CoDeSys library provides a function block responsible for opening the database and writing trends. The current implementation supports writing 10 variables simultaneously and 3 basic methods:
- Init DB
TrendsFBInstance.init ($WWWDB$/trend, 4000);
- Write values
TrendsFBInstance.write ( REAL_TO_STRING (var1), REAL_TO_STRING (var2), REAL_TO_STRING (var3), REAL_TO_STRING (var4), REAL_TO_STRING (var5), REAL_TO_STRING (var6), REAL_TO_STRING (var6), REAL_TO_STRING (var6), REAL_TO_STRING (var9), REAL_TO_STRING (var10) );
- Finish writing a series
TrendsFBInstance.writeFinish ();
init ($WWDB$/trend, 4000);
The first line of the PRG is the init call. It can be placed here and called in any loop. Once the database is opened, it will not be opened again and will contain the pointer to the database.
Path to DB
WWWDB $ is a PlaceholderFilePath that points to a specific folder on your device where the eDesign DB files exist. Check the CODESYSControl.cfg file on your PLC. In the SysFile section you will find several lines with PlaceholderFilePath. To make this placeholder the working line:
PlaceholderFilePath.4 = /var/www/eDesign/customer/db, $WWDB$
must be present in the configuration. If this is not the case, add it and restart the CoDeSys runtime. Note the number after PlaceholderFilePath (4). This is a unique number and should be adjusted if necessary.
Maximum number of stored records
Limit the DB size by defining the maximum number of records it contains. This must be set. Do not enter a high number, otherwise the memory on your device may be full.
write(var1, var2, var3, var4, var5, var6, var7, var8, var9, var10)
The write method writes the values to the database in the correct order and with the current timestamp. The timestamp depends on the date and time settings of your device. It has 10 parameters (10 variables to be stored) of a STRING type and therefore is needed to perform the conversion from its original type.
writeFinish()
The write-finish method is useful when writing values that represent stacks. When a stack finishes, the writing stops and gaps appear in the chart. If writeFinish is not used, the chart connects the dots.
Download example
Download | Link |
---|---|
Example of a Trend Project | download |
HMI Setup
Create trend in backend
After the CODESYS has been successfully set up and the values are written to the database, the diagrams can be displayed. First, go to the admin area to create a trend chart in the backend area.
Go to the Trend menu item in the menu (1) and open the Trend Editor.
A button appears in the upper left corner that says "New" (2). Click on it and create a new connection.
- Set a name of chart
- Set a X axis Label and Format
- Choose the alignment of the legend
- A time period can be selected from which data will be displayed
- If this button is activated, you can export the current view
- You can export the entire data in order to analyse it in excel
- This allows you to delete the entire data with the push of a button
- The number of points that are drawn can be set here
- It determines which method of interpolation will be used
- Set some Labels for the Y Axis
- Data sets should always be pinned to a Y-axis
- Save your settings and create the page
Generate CODESYS code
eDESIGN will prepare you the code that needs to be inserted into CODESYS. All variables are generated based on the current trend settings, so you do not have to write them yourself.
- For coding the CODESYS part you can use the generate code button
- The inserted code consists of 2 parts. Copy the declaration part to the beginning.
- Put the code part in the bottom window. Now fill missing placeholder with the proper values.
Apply Trends
Now we go to our page editor and paste our trend chart there to test if it works.
Go to the Edit Content mode and click in the container to see our toolbar. Select the trend chart (1).
Open the properties and select the trend chart we created (2).
Video
Video: Trace and Trend Option