# LGF_DataLogC (FB / 1.0.0)

Overview

Author: Siemens Industry Support

## Short description

LGF_DataLogC (C -> Compact) function integrates all the datalog system functions and can be used as standalone data logger.

### Block Interface

| LGF_DataLogC (FB) |
--- | --- | ---
Bool |  |  | enable |  | valid |  |  | Bool
String |  |  | name |  | busy |  |  | Bool
Bool |  |  | triggerLogEntry |  | error |  |  | Bool
Bool |  |  | clearLog |  | status |  |  | Word
Bool |  |  | deleteLog |  | writeEntryDone |  |  | Bool
LGF_typeDataLogParameter |  |  | parameter |  | clearLogDone |  |  | Bool
|  |  |  |  | deleteLogDone |  |  | Bool
|  |  |  |  | lastEntryReached |  |  | Bool
|  |  |  |  | noOfEntries |  |  | UDInt
|  |  |  |  | diagnostics |  |  | LGF_typeDiagnostics
Variant |  |  | data |  |  | Variant

### Input parameter

Identifier | Data type | Default value | Description
--- | --- | --- | ---
enable | Bool | FALSE | TRUE: Enable functionality of FB
name | String | 'DefaultDataLog' | Name of datalog, also used as file name
triggerLogEntry | Bool | FALSE | Rising edge trigger one entry in data log (only if `parameter.isLoggingByInterval` := FALSE)
clearLog | Bool | FALSE | Rising edge triggering clearing of datalog file
deleteLog | Bool | FALSE | Rising edge triggering deletion of datalog file if exist
parameter | LGF_typeDataLogParameter | --- | This UDT belongs to the Module `LGF_DataLogC` and lists all possible parameter to configure its behaviour.

### Output parameter

Identifier | Data type | Description
--- | --- | ---
valid | Bool | TRUE: Valid set of output values available at the FB
busy | Bool | TRUE: FB is not finished and new output values can be expected
error | Bool | TRUE: An error occurred during the execution of the FB
status | Word | 16#0000 - 16#7FFF: Status of the FB, 16#8000 - 16#FFFF: Error identification
writeEntryDone | Bool | TRUE: DataLog write done successfully
clearLogDone | Bool | TRUE: DataLog clear done successfully
deleteLogDone | Bool | TRUE: DataLog delete done successfully
lastEntryReached | Bool | TRUE: Last entry of datalog reached, if `enableRingBuffer` is set, start from beginning, otherwise block ends here
noOfEntries | UDInt | Number of entries in datalog
diagnostics | LGF_typeDiagnostics | Diagnostic structure to store and transfer diagnostic information from blocks through the interface.

### In/Out parameter

Identifier | Data type | Description
--- | --- | ---
data | Variant | Data structure to log in datalog file

### Retain static parameter

Identifier | Data type | Retain | Description
--- | --- | --- | ---
statNoOfEntries | UDInt | ✓ | Number of entries in datalog
statLlastEntryReached | Bool | ✓ | TRUE: Last entry of datalog reached, if `enableRingBuffer` is set, start from beginning, otherwise block ends here

### Status & Error codes

Code / Value | Identifier / Description
--- | ---
16#0000 | STATUS_FINISHED_NO_ERROR NO error occurred during call / Active processing
16#7000 | STATUS_NO_CALL No job being currently processed
16#7001 | STATUS_FIRST_CALL First call after incoming new job (rising edge `enable`)
16#7002 | STATUS_SUBSEQUENT_CALL Subsequent call during active processing without further details
16#7010 | STATUS_MAX_ENTRIES_REACHED maximum Number of entries reached
16#8401 | ERR_WRONG_COMMAND_CALL_ORDER Error: wrong command call order - `deleteLog` or `clearLog` must be false during startup / enabling the block
16#8600 | ERR_UNDEFINED_STATE Error due to an undefined state in state machine
16#8601 | ERR_DATALOG_OPEN Error: `DataLogOpen` throws an error, please see `diagnostics.subFunctionStatus` in diagnostic structure for more detailed information
16#8602 | ERR_DATALOG_CREATE Error: `DataLogCreate` throws an error, please see `diagnostics.subFunctionStatus` in diagnostic structure for more detailed information
16#8603 | ERR_DATALOG_CLOSE Error: `DataLogClose` throws an error, please see `diagnostics.subFunctionStatus` in diagnostic structure for more detailed information
16#8604 | ERR_DATALOG_WRITE Error: `DataLogWrite` throws an error, please see `diagnostics.subFunctionStatus` in diagnostic structure for more detailed information
16#8605 | ERR_DATALOG_CLEAR Error: `DataLogClear` throws an error, please see `diagnostics.subFunctionStatus` in diagnostic structure for more detailed information
16#8605 | ERR_DATALOG_DELETE Error: `DataLogDelete` throws an error, please see `diagnostics.subFunctionStatus` in diagnostic structure for more detailed information

## User defined datatype(s)

### LGF_typeDataLogParameter (UDT / V1.0.0)

This UDT belongs to the Module `LGF_DataLogC` and lists all possible parameter to configure its behaviour.

Identifier | Data type | Default value | Description
--- | --- | --- | ---
header | String | '' | Headline of datalog, string of all data fields, separated by a comma: "field1,field2,field3,..."
maxNumberOfEntries | UDInt | 1000 | Maximum number of entries in datalog
timestampFormat | USInt | 0 | Timestamp format - see manual in "DataLogCreate" for used PLC Type (S7-1200 or S7-1500)
clearOnOpen | Bool | FALSE | Clear datalog during opening datalog while enabling block
deleteFile | Bool | FALSE | Delete as well datalog file during datalog delete
enableRingBuffer | Bool | FALSE | TRUE: Overwrite old values and start from the beginning if datalog reaches its maximum entries FALSE: Stop logging if `maxNumberOfEntries` entries reached
loggingByInterval | Bool | FALSE | TRUE: Log on interval time parameter FALSE: log on "triggerEntry"
loggingInterval | Time | T#1M | Time for automatic logging interval

### LGF_typeDiagnostics (UDT / V1.0.1)

Diagnostic structure to store and transfer diagnostic information from blocks through the interface.

Identifier | Data type | Default value | Description
--- | --- | --- | ---
status | Word | 16#0000 | Status of the Block or error identification when error occurred
subfunctionStatus | Word | 16#0000 | Status or return value of called FB's, FC's and system blocks
stateNumber | DInt | 0 | State in the state machine of the block where the error occurred

## Functional description

The function `LGF_DataLogC` combines the system functions for creating and writing data logs in one block.

The procedure provides that an existing Datalog is opened on the basis of the name (`name`), if it was not created before, this is recognized and the function creates the Datalog.

Afterwards, depending on the parameterization, the data is written from `data` in an adjustable interval or only on request to `triggerLogEntry`.

ReadMe The functionality of Datalogs can be found in the user manual:

- `DataLogCreate`
- `DataLogOpen`
- `DataLogClose`
- `DataLogWrite`
- `DataLogClear`
- `DataLogDelete`

NOTICE

  The following parameters are only effective when creating a data log:

  - `parameter.header`
  - `parameter.maxNumberOfEntries`
  - `parameter.timestampFormat` (S7-1200 and the S7-1500 support different formats, see the manual `DataLogCreate`)

NOTICE
  When logging data by interval (`isLoggingByInterval`) time variances occur, which are caused by a fluctuating cycle time.
  Therefore it is recommended to call the function in a time interrupt OB besides the call in the cyclic program and to set the trigger for writing in this interrupt OB.

NOTICE
  A data log which is deleted by the function without deleting the file cannot be created again as long as the file exists, it must first be deleted manually in the system.
  Please also note the parameter `parameter.deleteFile` which also deletes the file next to the data in case of a delete command `deleteLog`.

## Change log

Version & Date | Change description
--- | ---
| 1.0.0 | Simatic Systems Support
| 19.02.2022 | First released version