Overview
The S7-1200 data logging subsystem writes process values to non-volatile CSV files on the CPU's load memory (or an optional SIMATIC memory card). Once engineers move beyond simple DataLogWrite calls, three field questions almost always surface: (1) how the open log file survives an uncontrolled power-down, (2) why the recorded timestamp does not match the configured local time zone, and (3) why the integrated Web server appears to refuse to delete log files. This reference documents the exact instruction behavior, the firmware-specific edge cases, the CSV layout, and the verification steps needed to make data logging production-grade on a CPU 121x/122x/151x running firmware 2.2 through V4.x under STEP 7 (TIA Portal) V11 SP2 through V20.
For the canonical Siemens description, see the Recipes and Data Logging overview in the TIA Portal help, and the working example program published on the Siemens Industry Online Support portal: Example program for working with data logs (S7-1200, S7-1500).
S7-1200 Data Log Architecture
The S7-1200 stores data log files as plain CSV in a hidden directory under the load memory root. When a memory card is plugged in, files are written to the card; otherwise they live in internal load memory. Each log is a separate .csv file with a fixed, user-defined name (e.g. ProcessLog.csv). Files persist across power cycles because load memory is retained; volatile work RAM does not store the open-file descriptor.
Three key architectural facts drive every answer below:
- Log file open/close state is not retained in the CPU. After STOP-RUN or power-up the descriptor is gone even though the file remains on the card.
- The CSV file content persists, but only the file is opened by the user program — the CPU never silently re-opens it.
- Time-of-day in data log records is taken from the CPU clock, which is UTC-based internally; the local time zone is a display/offset attribute only.
Maximum Number of Open Data Logs
Per the official Siemens example program referenced above, the simultaneous open limit is firmware-dependent:
| CPU Family | Max Open Data Logs |
|---|---|
| S7-1200 (all firmware) | 8 |
| S7-1500 (all firmware) | 10 |
Exceeding the limit causes DataLogCreate / DataLogOpen to return error code 80B1 "Maximum number of data logs already opened" (STATUS output of the block). The total number of data log files stored on the card is bounded only by the available free memory, not by the open count.
Data Log Instruction Set
The instruction set under "Extended instructions → Recipes and data logging" in TIA Portal is identical for S7-1200 and S7-1500. Engineers must call them in the correct lifecycle order.
| Instruction | DB Variant | Purpose |
|---|---|---|
| DataLogCreate | DataLogCreateDB | Allocates a new CSV file with header row and column definitions. Returns a DWORD ID. |
| DataLogOpen | DataLogOpenDB | Re-opens an existing CSV by name; required after every power-up or STOP-RUN transition. |
| DataLogWrite | DataLogWriteDB | Appends one record. Optional TIMESTAMP parameter is CPU RTC. |
| DataLogClose | DataLogCloseDB | Flushes buffers and releases the file handle. |
| DataLogNewFile | DataLogNewFileDB | Closes the active file and opens a new one with the same column layout; used for size- or time-based rotation. |
| DataLogDelete | DataLogDeleteDB | Deletes a closed log file from load memory. Cannot delete an open file. |
Power Failure Recovery Procedure
Question 1 from the source: "If the CPU had a power failure, would I need to write an Open sequence in order to continue to log files?" — Yes, always. The data log file persists on the card, but the in-RAM file handle is lost. Any DataLogWrite call after a power-up will return error 80B2 "Data log is not open" unless an DataLogOpen has been issued first scan.
The recommended pattern in OB1 (or a startup-aware FB) is:
- Generate a rising edge from a retentive flag
LogInitialized(FALSE on first scan, TRUE thereafter). - On the rising edge, call
DataLogOpenwith the file name and pass the returnedDWORDto a global retentive tagLogID. - If
DataLogOpenreturnsDONE=TRUEand noERROR, setLogInitialized := TRUE. - If
DataLogOpenreturnsSTATUS <> 0(typically80C3file not found), callDataLogCreateonce, then re-callDataLogOpento obtain a valid ID. - Call
DataLogWritein the cyclic section, gated by theLogInitializedenable bit.
Sample ladder-equivalent structured text follows:
// First scan / power-up recovery
IF "FirstScan" OR ("LogInitialized" = FALSE) THEN
"DataLogOpen_DB"(REQ := TRUE,
MODE := 'OPEN',
NAME := 'ProcessLog.csv',
DONE => _Done,
BUSY => _Busy,
ERROR => _Err,
STATUS=> _Status);
IF _Done AND NOT _Err THEN
"LogID" := "DataLogOpen_DB".IDENT;
"LogInitialized" := TRUE;
ELSIF _Done AND _Err AND _Status = 16#80C3 THEN
// File not present — create it
"DataLogCreate_DB"(REQ := TRUE,
NAME := 'ProcessLog.csv',
DELIM := ';',
FORMAT := 0, // 0=internal float, 1=external string
TIMECOL := TRUE,
DONE => _cDone,
ERROR => _cErr,
STATUS => _cStat,
IDENT => "LogID");
"LogInitialized" := TRUE;
END_IF;
END_IF;
// Cyclic write (every 30 min in the original program)
IF "LogInitialized" AND "LogTrigger" THEN
"DataLogWrite_DB"(REQ := TRUE,
IDENT := "LogID",
TIMESTAMP := TRUE,
DATA := "LogBuffer",
DONE => _wDone,
ERROR => _wErr,
STATUS => _wStat);
END_IF;
Mark LogID and LogInitialized as Retain in the PLC tag table. Without retention, the open-ID is lost on power-down and even though the file is intact, the program has no handle to write to.
Power Loss and Write Buffering
The CPU flushes the log file when the file is closed, when DataLogWrite returns DONE=TRUE, or when internal buffers are full. An uncontrolled power-down that interrupts a DataLogWrite in mid-flush can leave the last record partial. The CSV header and all previously DONE records remain valid; only the in-flight record may be truncated to the previous complete line. To minimize this, set the data log "Maximum file size" or use DataLogNewFile on a schedule so that loss of a single record is bounded.
Time Stamp and Time Zone Behavior
Question 2 from the source: "I have configured the CPU with time of day GMT-5 (Bogota, Quito), but the timestamp is always in GMT 0. Why does this happen?"
The S7-1200 stores time of day internally as UTC (DTL format). The "Time of day" setting in the device configuration — under Properties → General → Time of day → Time zone — controls only how the Web server and the online diagnostics display the clock. The data log timestamp, however, is written using the same DTL value the CPU keeps in UTC and the DataLogWrite instruction does not apply the local offset when TIMECOL = TRUE. This matches the behavior documented in the S7-1200 System Manual: time stamps in data logs are recorded in UTC.
There are three field-proven remedies:
- Offset at read time: when exporting the CSV, add the configured UTC offset (e.g. -5 h) to the timestamp column. The Web server download file and the WinCC / HMI panel reading the file via S7 communication both receive the raw UTC.
-
Pre-compute an offset string: maintain a static tag
UTC_OFFSET_HOURS := -5and write an additional column containing the local time as a STRING. Sample snippet:\li>
// Build local time string "YYYY-MM-DD HH:MM:SS" from DTL and offset
"LogBuffer".local_ts := TO_STRING("rtc_local".YEAR) + '-' +
PAD_LEFT(TO_STRING("rtc_local".MONTH), 2, '0') + '-' +
... ;
-
Set the CPU clock in local time, not UTC: under Device → Properties → General → Time of day → Time zone, set the local time zone (Bogota/Quito/Lima — UTC-05:00) and ensure the time source is NTP or a properly synchronized master clock. The CPU will continue to store UTC internally, but if the user program calls
RD_SYS_Tand you read the local-time view through a separate tag, the displayed value matches the configured zone. The log file will still show UTC unless option 1 or 2 is used.
On firmware 2.2 specifically, the "Time of day" property page was simpler than on V4.x and the Web server clock display would honor the local offset — but the data log timestamp column never did. Engineers upgrading from V2.2 to V4.x may notice the Web server behavior unchanged, because the log file format is also unchanged.
Web Server File Erase and Access Levels
Question 3 from the source: "According to the S7-1200 system manual I should be able to erase data log files through the Web server, but once I enter the Web server I can only download the file and check recent logs. I am not able to erase log files. Why does this happen?"
Web server file system write operations — including Delete and Rename — are gated by the user-management access level. The default S7-1200 Web server ships with the "standard" user disabled and only the anonymous read-only role active. File deletion is not anonymous; the engineer must be logged in as a user assigned the "File browser / user-defined pages: read" and "...: write/delete" rights.
Resolution steps (TIA Portal V13+ shown; V11 SP2 follows the same path with fewer options):
- Open the CPU device configuration.
- Select Web server → User management.
- Add a new user (e.g.
admin) and assign the "Write/delete files" access right under the File browser group. - Compile and download the hardware configuration.
- In the Web server, click Log in (top right) and authenticate as the new user.
- Navigate to File browser → Data logs. The Delete button now appears next to each log file.
On firmware 2.2 with TIA Portal V11 SP2, the user-management table is more limited: there is only one role with a checkbox for "Write/read files". Enable that checkbox, download, and re-login to the Web server. The V11 SP2 Web UI does not show a "Delete" button as a separate icon — the operation is exposed via a checkbox and an "Apply" action. Newer firmware versions (V4.x) include a clearly labeled Delete icon next to each log entry.
If the user-management table is greyed out, the Web server itself is not enabled. Check Web server → General → Activate Web server on this module.
CSV File Format and Storage Layout
A data log CSV has the following structure (delimiter ;, default):
"Timestamp";"Pressure_bar";"Temp_C";"Flow_Lmin"
"2024-09-12 14:23:00.123";"3.42";"71.5";"120.0"
"2024-09-12 14:53:00.123";"3.40";"71.7";"121.3"
Storage locations:
| Medium | Path | Notes |
|---|---|---|
| Internal load memory (no card) | /DataLogs/<Name>.csv | Visible via Web server "File browser" → "Data logs". |
| SIMATIC Memory Card (SMC) | /DataLogs/<Name>.csv on the card | Files follow the card — swapping cards moves the data. |
The S7-1200 system manual specifies a maximum single-file size of 500 MB on internal load memory and a CPU-dependent total log volume; refer to the System Manual for the exact number for the specific CPU order number.
Firmware 2.2 Specific Notes
The original program described in the source uses CPU firmware 2.2 with STEP 7 Professional V11 SP2. Engineers maintaining legacy installations should note:
- FW 2.2 supports the full DataLogCreate / Open / Write / Close / Delete instruction set. DataLogNewFile was added in FW 4.0; not available on FW 2.2.
- Web server on FW 2.2 exposes only one login role with a single "Write/read files" toggle.
- Maximum 8 open logs applies (same as current firmware).
- The
STATUSerror code table is smaller than later firmware; some 4-digit codes documented for V4.x do not exist on FW 2.2.
For new designs Siemens recommends at least firmware 4.2 (or 4.4 for the latest S7-1200 CPUs). Migration requires re-downloading the user program and a factory reset of the CPU if the project was created in TIA Portal V11 SP2 — the project must be upgraded in TIA Portal first.
Common Error Codes and Diagnostics
| STATUS (hex) | Meaning | Typical Cause | Remedy |
|---|---|---|---|
| 0000 | No error | — | — |
| 80B1 | Maximum number of data logs already open | More than 8 (S7-1200) or 10 (S7-1500) data logs open | Close a log with DataLogClose before opening another. |
| 80B2 | Data log is not open | DataLogWrite called before DataLogOpen, or after a power-up without re-open | Implement first-scan Open/Create sequence described above. |
| 80B3 | Data log is already open | DataLogOpen called with a name already in the open set | Use DataLogClose first or reuse the existing ID. |
| 80C3 | Data log file not found | DataLogOpen called for a file that does not exist | Catch this status and call DataLogCreate, then re-open. |
| 80C5 | Data log file is write-protected | Memory card write-protect switch is set, or attribute set via Web server | Remove write protection; check card switch position. |
| 80C6 | Data log file is full | Internal limit reached; depends on CPU/format | Call DataLogNewFile (FW 4.0+) or implement manual rotation. |
| 8092 | DataLogCreate: name too long or invalid | File name > 24 chars or contains illegal characters | Use ASCII letters/digits/underscore; keep under 24 chars. |
All STATUS values are returned on the STATUS output of the instruction's instance DB. The ERROR output is set TRUE for any non-zero STATUS. DONE and BUSY follow the standard S7 asynchronous execution model: a single REQ := TRUE triggers the job; the engineer must hold REQ until DONE OR ERROR is asserted, then drop REQ for at least one cycle.
Configuration Checklist (Pre-Commissioning)
- CPU clock set with NTP source or synchronized from a master; verify in Online → Diagnostics → Time.
- Memory card installed and formatted (or internal load memory confirmed sufficient).
- Web server activated, user management configured with at least one user that has File browser write/delete rights.
- PLC tag table contains retentive tags for
LogID(DWORD) andLogInitialized(BOOL). - Data log instructions called in correct order from OB1 or an FB; first-scan edge handles re-Open after power-up.
- Buffer or trigger condition defined: 30-minute interval in the source is implemented with a TON or a clock-bit generator.
- Visualize one full write cycle, then power-cycle the CPU and confirm the next record is appended (not overwriting the file or returning 80B2).
Verification Steps
- Force the program to run for two 30-minute periods; download the CSV via Web server; confirm two records separated by 1800 s.
- Pull the 24 V supply on the CPU mid-cycle; restore power. Wait for the next scheduled write. Inspect the CSV: the new record must appear with a fresh timestamp, the file header must be intact, and no 80B2 must be visible in the online block STATUS.
- Log in to the Web server as the configured user; click Delete on a test log file. The file should disappear from the File browser within 2 s.
- Inspect the time stamp column in the CSV and compare it to the Web server "Time of day" page. Expect a constant offset equal to the configured UTC offset; this confirms UTC is the recorded value (expected behavior).
Best Practices and Field-Proven Caveats
- Use SMB-like filename conventions: stay within 8.3 characters for portability, or use underscores rather than spaces.
- One log per subsystem: open separate logs for fast analog data and slow counters — this avoids a single busy log blocking writes to other tags.
- Pre-allocate, then create: define column structure in TIA Portal under Data logs if you want the system to manage them; otherwise build them purely from code (as in the example program referenced earlier).
- Monitor free memory: use the Web server "Memory" page to keep an eye on load memory usage. When free space drops below 1 MB, the CPU may refuse new writes with 80C6.
-
Decide rotation policy: if you cannot upgrade to FW 4.0+ for
DataLogNewFile, implement your own "close + create new with timestamped name" sequence at midnight or on a size threshold. - Time zone honesty: do not attempt to set the CPU clock to local time while expecting UTC in the data log; the relationship is fixed. Document the offset in the file header column name to avoid confusion downstream.
Migration Notes to TIA Portal V13+ and FW 4.x
Projects created in TIA Portal V11 SP2 (the source environment) can be migrated with Project → Migrate project. The data log instructions do not change their interface, but instance DBs receive new version markers. After migration, recompile and download; if the Web server behavior appears different, also update the CPU firmware to match the TIA Portal version that owns the project.
Does the S7-1200 re-open data log files automatically after a power failure?
No. The CSV file persists on the load memory or memory card, but the in-RAM file handle is lost. The user program must call DataLogOpen on the first scan (or use the retentive LogID from a successful previous open) before any DataLogWrite call. Without this, DataLogWrite returns error 80B2.
Why are my data log timestamps in UTC even though I set the CPU to Bogota/Quito time (UTC-5)?
Because the S7-1200 stores time of day internally as UTC and the DataLogWrite instruction records the raw DTL value, not the local-time view. The configured time zone affects only the Web server clock display and the RD_SYS_T return value when read in the user program after applying the offset. To get local time in the CSV, either add an extra column computed in the program, or post-process the file by subtracting 5 hours.
How do I delete a data log file from the Web server?
Log in to the Web server as a user that has the "File browser: write/delete files" access right. The default anonymous user is read-only and cannot delete. Configure the user in Device → Web server → User management, download the hardware configuration, and re-login. The Delete button then appears next to each data log file in the File browser.
How many data logs can be open at the same time on an S7-1200?
Eight. Opening a ninth returns error 80B1 on DataLogCreate or DataLogOpen. The total number of stored log files on the memory medium is not limited by this number — only the open count is.
Can I use DataLogNewFile on firmware 2.2?
No. DataLogNewFile was introduced with firmware 4.0. On firmware 2.2 (used with TIA Portal V11 SP2) the engineer must implement rotation manually: call DataLogClose, then DataLogCreate with a new name (typically containing a date/time stamp) to start the next log file.