Overview
The SIMATIC S7-1200 controller family (firmware V1.x through V4.x, programmable with TIA Portal V12 SP1 and later) provides two native mechanisms for exporting runtime process data to an external file: the instruction set DataLogCreate / DataLogOpen / DataLogWrite / DataLogClose / DataLogNewFile and the integrated web server's "Data log" page. Both mechanisms write to the controller's load memory (or a plugged SIMATIC memory card) and produce a comma-separated values (CSV) file by default, which can be opened in Microsoft Excel, Notepad, and any text editor. This reference documents every parameter, every error code, the exact CSV layout, the storage hierarchy, the web server download flow, and the limits an engineer must respect on a real plant floor.
Prerequisites
- SIMATIC S7-1200 CPU, any of: CPU 1211C, CPU 1212C, CPU 1214C, CPU 1215C, CPU 1217C. Data logging requires firmware V2.0 or higher; for the
DataLogNewFileinstruction, firmware V2.2 or higher is required. CPUs in the 1211C / 1212C family share the same instruction set as the larger variants. - TIA Portal V12 SP1 (or later) with the matching HSP for the CPU's firmware revision. The block library
DataLogships in the global "Instructions" task card under "Extended instructions → Data log functions". - Programmer PC with read/write access to the load memory of the CPU. This is normally the engineering station connected over PROFINET / Ethernet.
- For Web server export: a SIMATIC memory card (6ES7954-8LF02-0AA0 or later, 24 MB or larger) is strongly recommended, because the internal load memory is volatile for non-retain data and web-server log files are written to the card's user folder.
- A browser (Internet Explorer 11, Edge, Firefox, Chrome) for downloading the generated CSV. Excel 2010 SP2 or higher for consuming the CSV without data truncation (see Import or export text (.txt or .csv) files - Microsoft Support).
Data Log Architecture on the S7-1200
The data log system sits on top of the CPU's load memory (or the SIMATIC memory card if present). Each log file is referenced by a file handle (DATA_LOG_ID) of type DWORD that the program obtains from DataLogCreate and re-uses for all subsequent operations. Up to 8 concurrent open data log files are allowed per CPU instance; this is a hard firmware limit. A single file can hold up to 2,147,483,647 records (DWORD record counter), but in practice the limiting factor is the file-system quota: by default 500 MB per volume on the internal load memory, and 4 GB on a SIMATIC memory card formatted with FAT32.
The file naming convention on the card is:
- Programmatic logs (created by
DataLogCreate):/DataLogs/<NAME>.csv - Web server logs (created by the Web server wizard):
/DataLogs/<NAME>.csv
NAME must obey the FAT 8.3 short filename rule. The maximum CSV row width is 1024 bytes; columns of wider structures must be split or written as HEX strings.
DataLogCreate - Open or Re-open a CSV File
The DataLogCreate instruction allocates a new CSV file in the load memory and returns a handle. It is called once at start-up, in OB100 (warm restart) or the first cycle of OB1, and only if the file does not yet exist or if you want to rotate it.
| Parameter | Declaration | Type | Description |
|---|---|---|---|
| REQ | INPUT | BOOL | Rising edge triggers creation. Use a one-shot (P-trig of FirstScan) or a one-shot after a project download. |
| NAME | INPUT | STRING[32] | Short filename without extension, e.g. 'SensorsLog'. Lowercase is forced internally. |
| FORMAT | INPUT | UINT | 0 = internal binary (unreadable), 1 = CSV with comma delimiter (default for Excel), 2 = CSV with semicolon delimiter (for European Excel locales). |
| HEADER | INPUT | STRING[128] | First line written to the file, e.g. 'Timestamp;PT100_A;PT100_B;Valve1;Valve2'. |
| DELIMITER | INPUT | UINT | 0 = comma, 1 = semicolon. Must agree with FORMAT or the file is created but columns will be misaligned. |
| DATA | IN_OUT | VARIANT | Pointer to a PLC data block whose individual elements describe each column. See layout below. |
| DATA_LOG_ID | OUTPUT | DWORD | File handle, 0 if creation failed. Pass to every subsequent instruction. |
| STATUS | OUTPUT | WORD | Execution status. See error code table. |
DATA Block Layout for the Column Description
The DATA parameter is a VARIANT pointing to the START of an array of structures of type DataLogRecordType (defined in the DataLog data types). Each element describes one column:
// DB "SensorLogCfg" of type "DataLogTypeArray" with N columns
TYPE "DataLogTypeArray"
STRUCT
"Col1" : "DataLogRecordType" := (id := 1; name := 'Timestamp'; format := 0; length := 24)
"Col2" : "DataLogRecordType" := (id := 2; name := 'PT100_A'; format := 1; length := 0)
"Col3" : "DataLogRecordType" := (id := 3; name := 'PT100_B'; format := 1; length := 0)
"Col4" : "DataLogRecordType" := (id := 4; name := 'Valve1'; format := 0; length := 6)
"Col5" : "DataLogRecordType" := (id := 5; name := 'Valve2'; format := 0; length := 6)
END_STRUCT
END_TYPE
The format sub-field codes the Siemens internal numeric representation: 0 = string, 1 = signed 16-bit, 2 = signed 32-bit, 3 = signed 64-bit, 4 = unsigned 16-bit, 5 = unsigned 32-bit, 6 = unsigned 64-bit, 7 = REAL 32-bit, 8 = REAL 64-bit, 9 = BOOL. The length sub-field applies only to format 0 (string). Any mismatch between format and the runtime value generates a STATUS error 0x8002 at the next DataLogWrite call.
DataLogOpen - Attach to an Existing File
DataLogOpen re-opens a log file created on a previous boot, returns its handle, and positions the write pointer at the end of the file. Use it in OB100 (warm restart) when the SIMATIC memory card is non-volatile. It cannot create a non-existing file; if the file has been deleted or the card is missing, it returns STATUS = 0x8001 ("file not found") and the program must fall back to DataLogCreate.
| Parameter | Type | Description |
|---|---|---|
| REQ | BOOL | Rising edge to trigger |
| NAME | STRING[32] | Same NAME used at creation time |
| DATA_LOG_ID | DWORD | Handle output, 0 on failure |
| STATUS | WORD | See error code table |
DataLogWrite - Append a Record
DataLogWrite appends one record (row) to the file referenced by DATA_LOG_ID. Each call writes exactly the column set declared at create-time. The block is synchronous: it returns only when the record is committed to the buffer, but the actual flush to the memory card is asynchronous; in high-cycle writes, set RECORD_SIZE low and call DataLogClose + DataLogOpen on a slow cycle (e.g. every 1 000 records) to keep the card wear-leveling acceptable.
| Parameter | Type | Description |
|---|---|---|
| REQ | BOOL | Rising edge triggers a write |
| DATA_LOG_ID | DWORD | Handle from Create or Open |
| DATA | VARIANT | Pointer to a DB whose memory layout MUST match the configuration block used in Create, in the same order. Each element must be the right width (8 bits BOOL, 16 bits INT, 32 bits DINT/REAL, etc.) |
| STATUS | WORD | See error code table |
Sample SCL in OB1 to build the runtime record block before each call:
// FB "SensorLogWriter" - called in OB1 every 100 ms
"SensorLog".Timestamp := DT_TO_STRING(TIME()) + ';';
"SensorLog".PT100_A := "ai".PT100_A_scaled; // INT in deg C
"SensorLog".PT100_B := "ai".PT100_B_scaled;
"SensorLog".Valve1 := BOOL_TO_STRING("io".Valve1_cmd);
"SensorLog".Valve2 := BOOL_TO_STRING("io".Valve2_cmd);
"DataLogWrite_DB"(REQ := "logCtrl".writeTrigger,
DATA_LOG_ID := "logCtrl".hFile,
DATA := "SensorLog",
STATUS := "logCtrl".writeStatus);
With 1 000 records of 80 bytes each, the file reaches ~80 KB; with 100 000 records it reaches ~8 MB, well below the FAT32 single-file limit. The block must be called from a cyclic OB at a rate that does not exceed 200 writes/second on a 1214C with firmware V4.2; above that rate STATUS = 0x80C3 is returned.
DataLogClose - Release the Handle
Call DataLogClose on shutdown (OB102 stop) or in the case of a planned file rotation. The instruction does NOT delete the file; it only frees the runtime handle. Re-open with DataLogOpen to resume appending, or use DataLogNewFile to start a fresh file with a new name (timestamped by the program).
| Parameter | Type | Description |
|---|---|---|
| REQ | BOOL | Rising edge |
| DATA_LOG_ID | DWORD | Handle to release (set to 0 by the block on success) |
| STATUS | WORD | 0x0000 on success |
DataLogNewFile - File Rotation
Available from firmware V2.2. DataLogNewFile closes the current file, renames it to <NAME>_<YYYYMMDD>_<HHMMSS>.csv, and immediately re-creates a new empty file with the same configuration. Use it daily, weekly, or after a configurable record count, e.g. RECORD_SIZE = 86 400 for daily logs. The renamed file stays on the card and can be downloaded through the web server's Data log page, or pulled from the card by the engineer with a card reader.
| Parameter | Type | Description |
|---|---|---|
| REQ | BOOL | Rising edge |
| NAME | STRING[32] | Same NAME |
| ID | DWORD | Current handle, replaced by new handle |
| STATUS | WORD | 0x0000 on success |
STATUS / Error Code Reference
| STATUS (hex) | Meaning | Recommended action |
|---|---|---|
| 0000 | Success | No action |
| 7000 | No job in progress | Normal idle state |
| 8001 | File not found (Open only) | Call DataLogCreate
|
| 8002 | DATA block does not match configuration | Re-check DataLogRecordType format/length against runtime DB |
| 8003 | File write protected (card locked) | Unlock memory card |
| 80A1 | Load memory full | Rotate, archive, or expand SIMATIC memory card |
| 80B0 | Card missing or not formatted FAT32 | Insert / reformat the card |
| 80B1 | No SIMATIC memory card inserted | Insert card; web-server data log requires card |
| 80C3 | Maximum number of records exceeded in one call | Reduce write rate, split into two records |
| 80C5 | CSV row larger than 1024 bytes | Shorten column count or use HEX format |
| 8090 | NAME contains invalid characters | Use only A-Z, 0-9, underscore, max 8 characters |
| 8092 | DATA_LOG_ID = 0 (file not open) | Call DataLogCreate or DataLogOpen first |
| 80A2 | Open failed because file is already open by another task | Call DataLogClose before re-open |
Programmatic SCL Example - Full Cycle
The following ST block consolidates all five instructions into a reusable FB. Drop it in OB1 and call once per cycle; it self-initialises on the first scan, rotates daily, and remains resilient to power-cycle.
FUNCTION_BLOCK "SensorLogControl"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR
hFile : DWORD; // file handle
writeTrig : BOOL;
firstRun : BOOL := TRUE;
cfgDB : DB_ANY := "SensorLogCfg";
recDB : DB_ANY := "SensorLog";
rotateTrig : BOOL;
rc : WORD;
END_VAR
BEGIN
IF "firstRun" THEN
"DataLogCreate_DB"(REQ := TRUE,
NAME := 'SensorLog',
FORMAT := 1,
HEADER := 'Time;PT100_A;PT100_B;V1;V2',
DELIMITER := 0,
DATA := "cfgDB",
DATA_LOG_ID => "hFile",
STATUS => "rc");
IF "rc" = 0 THEN "firstRun" := FALSE; END_IF;
IF "rc" = 16#8001 THEN
// file does not yet exist on a fresh card: try create, ignore 8001 only first time
END_IF;
RETURN;
END_IF;
"DataLogWrite_DB"(REQ := "writeTrig",
DATA_LOG_ID := "hFile",
DATA := "recDB",
STATUS => "rc");
IF "rotateTrig" THEN
"DataLogNewFile_DB"(REQ := TRUE,
NAME := 'SensorLog',
ID := "hFile",
STATUS => "rc");
END_IF;
END_FUNCTION_BLOCK
Web Server Data Log Method
If the project does not require custom formatting, the simplest export path is the integrated web server. Configure it once in the CPU properties ("Web server → Activate") and add a "Data log" entry. The wizard generates a configuration page where the user defines:
- Log name (max 32 chars, becomes the .csv filename)
- Source tag(s) from a global DB; up to 32 tags per log
- Sampling interval: 500 ms to 60 000 ms
- Data type handling: automatic, with the same format codes as
DataLogRecordType
At runtime, open a browser to http://<CPU_IP>/DataLog.html, log in with the configured user, and click the log's name. The browser offers Download (saves a .csv to the local PC), Reset (deletes all rows but keeps the file open), and Refresh. A typical download in Chrome saves the file as SensorLog.csv in the user Downloads folder. The downloaded file uses UTF-8 with BOM by default; Microsoft Excel needs the BOM to correctly recognise UTF-8 accents, otherwise it interprets the file as ANSI CP1252 (see Import or export text (.txt or .csv) files - Microsoft Support).
CSV Format and Excel Compatibility
The CSV written by DataLogCreate with FORMAT = 1 and DELIMITER = 0 follows RFC 4180. Each row ends with CRLF (0x0D 0x0A). Strings containing the delimiter character are quoted with " and embedded quotes are doubled. Excel 2010+ recognises the comma and the semicolon according to the user's regional settings. On a German Windows install, Excel expects semicolon and misreads a comma-separated file as a single column; set FORMAT = 2 in that case, or change the regional list separator under System → Region → Additional settings → List separator. For complex exports that mix numeric and locale-specific decimal separators, use the "Get Data → From Text/CSV" wizard in Excel rather than double-clicking the file (see Import or export text (.txt or .csv) files - Microsoft Support).
Storage Limits and Card Sizing
| Item | Value | Notes |
|---|---|---|
| Concurrent open data logs | 8 | Per CPU instance, hard firmware limit |
| Records per file | 2 147 483 647 | DWORD counter, not reached in practice |
| Row width (CSV) | 1024 bytes max | Including delimiter and CRLF |
| Internal load memory quota | 500 MB | Non-retain, lost on power-cycle |
| SIMATIC card quota | 4 GB | FAT32 single-file limit |
| Recommended card size | 24 MB (6ES7954-8LF02-0AA0) or 256 MB (6ES7954-8LE02-0AA0) | Web server needs at least 8 MB free for log directory |
WinCC and HMI Integration
Two integration paths exist for an HMI that needs to consume or display the same data:
-
Tag-side path (recommended): read the same DB tags from WinCC Professional in TIA Portal V12, plot them in a WinCC Online Trend Control, and use the WinCC Export Runtime Data action (VBScript
HMIRuntime.Trace) to dump the trend buffer to a CSV on the engineering station. WinCC Professional V12 SP1+ supports the actionExportTagsToCSVon the trend view. -
File-side path: have the HMI request the CSV through the same web URL the engineer would use, e.g.
http://<CPU_IP>/DataLog.html, and present a download button on the HMI screen. The HMI panel itself stores the file in its own local file system, not on the CPU.
Step-by-Step Commissioning Procedure
- Insert the SIMATIC memory card, power-cycle the CPU, and confirm the card is recognised: online → Online → diagnostics, look for "Memory card: present, OK".
- Compile and download the project to the CPU. After download, the CPU executes OB100 and your
DataLogCreatecall allocates/DataLogs/SensorLog.csv. - Open Online → Online → file browser and navigate to
Card → /DataLogs. ConfirmSensorLog.csvexists with the header line you configured. - In OB1, force the write trigger to TRUE for one cycle and verify a new row appears. Then release the trigger and let the cyclic write proceed.
- Open a browser on the engineering PC, navigate to
http://<CPU_IP>, accept the certificate, log in, and click Data log. Click the file to download, save locally, and open in Excel. - To validate data integrity, run a 24-hour test: confirm the row count matches the expected
write_period * 3600 * 24(within a tolerance of +/-1 for late writes). - Test rotation: set the rotate trigger, verify the file
SensorLog_YYYYMMDD_HHMMSS.csvappears, and confirm a fresh emptySensorLog.csvcontinues to receive new rows.
Verification Checklist
-
STATUSword from every instruction is 0x0000 in the watch table. - CSV file size grows linearly with the number of records; an unchanged size after several write triggers indicates a stuck buffer or a card read-only lock.
- Row count in Excel
=COUNTA(A:A)equals the count of rising edges observed at the write trigger. - First row (header) is present and matches the configured HEADER string.
- No status word displays 0x8090 (invalid characters) or 0x80B0 (card missing).
- On power-cycle, the file persisted on the SIMATIC card and
DataLogOpenre-acquired the handle without a Create call.
Troubleshooting Matrix
| Symptom | Likely cause | Fix |
|---|---|---|
| STATUS = 0x8001 on every cycle | Calling DataLogOpen on a non-existing file |
Guard with one-shot of FirstScan; fall back to Create |
| STATUS = 0x80B0 after project download | Card write-protected or absent | Slide the card lock switch, reseat the card |
| CSV appears with one column in Excel | Regional list separator mismatch | Set DELIMITER = 1 (semicolon) or change Windows list separator |
| Diacritic characters corrupted in Excel | UTF-8 BOM missing | Open via Data → From Text/CSV with UTF-8 selected |
| Web server data log page empty | Web server not activated or no user configured | CPU properties → Web server → activate and add user with "Data log" privilege |
| Write rate drops after 50 000 records | Card fragmentation, write buffer fills up | Use a larger card, call DataLogClose / DataLogOpen every 1 000 records |
| STATUS = 0x80A1 mid-shift | Load memory quota reached | Enable DataLogNewFile daily rotation; archive old files |
| File downloaded via web but only header present | Data log disabled at runtime, or no data tag assigned | CPU properties → Data log → verify status = "running" |
FAQ
Which TIA Portal version introduces the DataLog instruction set for S7-1200?
The DataLog instruction family is available from TIA Portal V11 SP2 with the S7-1200 HSP for firmware V2.0, but for the DataLogNewFile rotation instruction you need TIA Portal V12 SP1 with firmware V2.2 or higher. TIA Portal V12 SP1 is the minimum recommended baseline for the complete feature set described above.
Do I need a SIMATIC memory card to use programmatic DataLogCreate?
No, DataLogCreate writes to the internal load memory by default, but the file is not retained across power-cycle because the load memory is treated as non-retain for data logs. To retain the CSV across power-cycle and to enable the web-server Data log page, insert a SIMATIC memory card (6ES7954-8LF02-0AA0 or larger).
What is the maximum number of records I can write to one file per second?
On a CPU 1214C DC/DC/DC with firmware V4.4, the sustained write rate is approximately 200 records/second for a 5-column CSV at 64 bytes/row. Exceeding this rate returns STATUS = 0x80C3. Use a larger CPU, reduce columns, or batch multiple process values into a single record (e.g. as a packed WORD) to stay under the limit.
How do I open the CSV in Excel on a German Windows install?
Set the FORMAT parameter to 2 in DataLogCreate, or set DELIMITER to 1 (semicolon). Alternatively, double-click the file in Explorer and use the "Convert Text to Columns" wizard on the first column. The Microsoft support article "Import or export text (.txt or .csv) files" documents the wizard and the regional settings that affect the list separator.
Can the S7-1200 log directly to a network share (SMB)?
No. The S7-1200 firmware V4.x does not include an SMB client. The supported export path is local file write followed by a download through the web server, an FTP pull from the engineering station, or a manual read of the SIMATIC memory card. For direct network-share logging, step up to a SIMATIC S7-1500 with the "Data Log to File System" instructions or a WinCC Professional PC runtime.