Data Logger/CSV Write

This example project incorporates the IIoT .CSV Library functions to generate a data logger that takes in various Tag data types i.e. REAL , WORD, etc. stores them in a format and writes these Tag values out to a .CSV file on command or automatically.

Due to the complexity of the project, an example can be downloaded from the website at datalogger project .

The various parts of the project are described below and this can be used as a starting point to create your own solution.

The data logging project utilizes the SD Card for the storage location.

System Requirements and Installation

This section requires the following:

  • P2CDS-622 CPU

  • P2000 Base (any variant)

  • P2000 PowerSupply (any variant)

  • Latest version of CODESYS installed on Host PC

  • OSCAT “Basic” library installed.

  • “Util” library installed.

  • “SysTime” installed.

  • Familiarity with the “Continuous Function Chart” programming language.

Caution

To do this project, the steps outlined in the previous section Preparation have to be completed successfully.

Install IIoT Library

To access the free IIoT Library functions e.g. CSV functions, you must install the IIoT Single license with the CODESYS Installer.

This license is located on the CODESYS website store at IIoT License

Project Generation

Open Archived Project

(1). Download the archived CODESYS project from below link to your local working directory.

Download here- Datalogger Project

(2). With CODESYS IDE launched, click File > Project Archive > Extract Archive. Select all options in pop-up. Click “yes” on next pop-ups.

(3). Update everything (including Library’s) to latest revisions. You may have to add a Library, e.g. Basic OSCAT.

Caution

When the SD Card is utilized continually as in a Data Logger application, it is highly recommended that the SD Card updates/writes are assigned its own Task. This is due to the possibility that, depending on size, the SD Card can take up to 100ms to update.

Inspect and Setup Project

This project has three(3) separate applications that can be run. Select the CSVWriterCFCExample as the active application if not active already.

(4). Right Click on CSVWriterCFCExample > Set Active Application.

Looking at the Top Level of the design (WriteValues), you can see the example was created using the CFC programming language.

The project has a Visualization that can be used to generate new writes into the .CSV file using Visu buttons.

The default .CSV file generated first is called CSVWriterCFCExampleData.csv after this a new file can be generated that is discussed below.

Elements of the Design

The following describe each block of the design. For further documentation, click on the Block of interest.

Various data types are stored by command i.e. xExecute driven high, into a particular function block. These blocks are buffers for the logging process and are stored internally in the library element, then written out to a file by command CSV.WriteFile and the xExecute strobe.

The design will write all the Tags or Data one defines on a single row of the CSV file until a CSV.NewLine command is initiated. Then the next logged values will be written on the next row.

Frequency of logging data is determined when the xExecute is strobed for a particular function block. In this project the first block’s logging is started with the press of the Visu tag button into the xExecute input, then that blocks xDone is daisy-chained into the next log block’s xExecute so it they are all done in sequence.

NOTE: there are numerous Tags (up to 64) that can be logged by inserting as many logging function blocks as required.

Support Functionality (non-CSV Library)

  • Get the current Time (GetPlcTime) - This function incorporates the SysTimeRtcGet library call and generates the current local PLC time.

  • Obtain the Timestamp (Minutes) (OSCAT_Basic_DT_STRF) - This OSCAT library function extracts the corresponding time element out of the at/time string depending on the value into the FMT input. In this case, I am extracting the minutes value to be used in the name or the CSV file. This gives it a timestamp in the name.

  • Concatenate Strings for a filename (CONCAT) - To create the final text string for the filename, I have to concatenate the various text pieces together to get final name LogSnapshot_minutes.csv’. Then when the CSV.NewFile is executed, this is the filename used.

Closing Comments

This project shows how to utilize the aspects of the IIoT CSV library functionality in the CSV WRITE mode and also implementing some of the functions associated with the OSCAT library.

A basic datasheet for the CVS complete functionality of the CVS solutions can be found in the IIoT install directory.

In addition, the Library Manager under the CVS Utility section lists the Function Blocks available.