Logging Data into a CSV File

There are some steps to start with logging data into a CSV file:

  • Define what to be logged:

    Input SELECTION types are: Selection of predefined values to be logged: bit 0 to bit 7 are used for the current version. Bit x=TRUE: the corresponding value will be logged.

    • Bit 0: Control Word
    • Bit 1: Status Word
    • Bit 2: SET_TEMP
    • Bit 3: ACT_TEMP
    • Bit 4: Duty Cycle
    • Bit 5: Control State
    • Bit 6: Output State
    • Bit 7: Latest Error
    • Bit 8: Errors (Error Word)
  • Define the log trigger:

    • Define an external trigger with LOG_TRIG, it is recommended to use a timer, e.g. BLINK function block. The LOG_TRIG should be defined greater than 1s, otherwise log data could get lost.
    • Additional to LOG_TRIG, an internal trigger can be activated with bit 4 of input MODE, which creates a trigger if and there is change in Control word or Status word.
  • Define when to log data:

    • With bit 1 and bit 0 of input MODE, it can be defined when to log data if log trigger is active. This setting can be used to optimize the storage size for data logging by reducing the number of data sets to be logged. Bit 1, Bit 0:

      00: Log all items as long as log trigger is active.

      01: Log, if one of the log values changes, when trigger is active.

      11: Log, if CW or SW changes or ACT_TEMP changes out of threshold (+/-THRESHOLD), when trigger is active.

    • With above mode 11, the input THRESHOLD needs to be defined also.

  • Define the log buffer:

    A log buffer in data area needs to be defined for all zones to collect the log data before data is written to a log file. The log buffer contains continuous area for each zone individually. The first address of the log buffer needs to be assigned to input ADR_LOG_BUFFER. It is recommended to use a data area with fixed address, e.g. %R or %M area.

    The input NUM_BUFFER_ENTRY specifies the size of a log area for each zone in number of log entries. A log entry stands for a data set containing the predefined log values with input SELECTION. The total amount of log entries of the entire log buffer will be NUM_BUFFER_ENTRY x NUM_OF_ZONE.

../_images/65fb8527f9a58b6c0a317d310740ce8e

Input THRESHOLD

../_images/1f1e783e07a8c3f90a317d3146a42dd8

The NUM_BUFFER_ENTRY should be defined as large as possible to reduce the frequency of saving the log buffer into log files, thus reducing CPU load. It is recommended to define NUM_BUFFER_ENTRY > NUM_OF_ZONE x 2, otherwise log data could get lost.

The data size of a log entry depends on the input SELECTION, the size can be about 20 bytes to 100 bytes. This information can be got at run time from the output ENTRY_SIZE and the total size of the log buffer is displayed at output BUFFER_SIZE.

It is very important to check the BUFFER_SIZE output to make sure that enough data area is available for the defined log buffer, otherwise undesired behavior can happen in PLC. The following table shows the available %M and %R area of different CPU types (status of 10.2015).

../_images/b590b32d07a8bf960a317d31607f14d3
  • Define where to save the log files:

    It is recommended to save log files on SD card. For CPU types PM592 and PM595 it is possible to be saved on the Flashdisk.

    The folder for saving is to be specified at input FILE_PATH, e.g. ‘SDCARD/folder’. The physical disk like SDCARD or FLASHDISK must be specified in the FILE_PATH. The folder following will be created if it does not exist yet as long as the function block is enabled with EN input. But only one folder level will be created, this means the parent folder must already exist.

    Bit 8 and bit 9 of input MODE can be used to specify the subfolder.

    • Bit 8: FALSE: Create subfolder automatically; TRUE: Do not create subfolder.

    • Bit 9: Valid, if bit 8 is FALSE.

      FALSE: subfolder name with index in DECIMAL.

      For example, for group 10, index 3, subfolder name is G010Z003.

Following is an example of FILE_PATH = ‘SDCARD/LOG_D’ and Bit 8 = FALSE, Bit 9 = FALSE:

../_images/c50c66c207b103990a317d3153250f44
  • Define when to create a new log file:

    The function block creates individual log files for each zone.

    As soon as the log area for each zone is full, that area will be written into a CSV file in the predefined folder. The file name contains the group and zone index as well as date information: ggzzmmdd.csv. Where:

    • ‘gg’ for group index in hexadecimal
    • ‘zz’ for zone index in hexadecimal
    • ‘mm’ for month of the year
    • ‘dd’ for day of the month

    At input NUM_FILE_ENTRY is to be defined how many entries a log files can have before creating a new log file. Before creating a new log file, the existing one will be backed up in changing the file extension without changing the name. For example, change ggzzmmdd.csv into ggzzmmdd.E74. The extension is composed of the last three hexadecimal numbers of current time without seconds. In this way, the file overwriting is avoid and all the log history is still available.

    If NUM_FILE_ENTRY is 0, then a new log file will be created daily.

    Following is an example of saved log files:

../_images/a7c5cb7307b107ce0a317d315fe31b2f
  • Common inputs:

    NUM_OF_ZONE: Number of zones to be logged into the .csv file or displayed in visualization. If TECT_GROUP is used, then the range is 1…65535. If TECT_GROUP is not used, then the range is 1…255. It is recommended to use one TECT_LOG_FILE for the whole system.

    FIRST_ZONEDATA: First structure of process data and parameters for the zone. See function block description for details.

  • Manual operations:

    • Save the log buffer into files manually: with a rising edge at input MANUAL_SAVE all the data in the log buffer will be saved into the log files immediately.
    • Clear log buffer: with a rising edge at input CLEAR_BUFFER all data in the log buffer will be cleared. But before clearing, the new entries in the logging buffer are written into the .csv file first. Then the .csv file is renamed into a backup file with the same file name but different extension, which is composed of the last three hexadecimal numbers of current time without seconds. In this way, even after a clear log buffer action, the history in the buffer will not get lost.
  • How to reduce the value of output NUM_LOG_LOST(number of logs which are lost):

    • Don’t create subfolder (MODE.bit8=TRUE) or first enable the function block with EN=TRUE until all folders are created (FOLDER_CREATED=TRUE) then start logging with EN_LOG=TRUE.
    • Increase the interval of LOG_TRIG if possible (recommendation: not less than 2 seconds).
    • Reduce the SELECTION to the necessity and increase the NUM_BUFFER_ENTRY if possible.
    • Increase the size of the second buffer (i2ndNEntry of TECT_LOGFILE_DATA_TYPE). Recommendation: 0…4.

Note

The second buffer will allocate dynamic memory on PLC. Depending on the application, it could cause system error if the second buffer is so large that the system cannot allocate memory any more.