Configuring Weekly CSV Data Logging on SIMATIC HMI Panels

David Krause16 min read
HMI ProgrammingSiemensTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Problem Statement: Weekly INT-to-CSV Logging on SIMATIC HMI

Logging a small set of INT counters from an S7-1200/1500 Data Block (DB) to a CSV file once per week is a common shop-floor requirement. Operators want a scheduled snapshot of standstill counters, hours-run tags, or batch quantities that survives a runtime restart, can be opened in Excel, and lives on a USB stick that is swapped once a week. SIMATIC Comfort Panels and Unified Comfort Panels support this scenario natively, but three recurring defects make the configuration look broken on first attempt:

  1. Multiple lines per value - one LogTag call appears to write ten rows.
  2. Logs stop after USB removal - removing the storage medium pauses the data log silently.
  3. Logs only appear after a runtime restart - the file is not refreshed during running operation.

All three defects share a single root cause: the data log is not configured for On demand acquisition with a single, edge-triggered call to the LogTag system function. This article walks through the correct configuration on a TIA Portal project, the PLC scheduler that fires the trigger once per week, the path conventions for the USB stick, and a verification procedure that proves the snapshot is one row, written on Monday, and retrievable without restarting the panel.

Scope. This procedure applies to SIMATIC HMI Comfort Panels (KTP400 to TP2200), Unified Comfort Panels (MTP700 to MTP2200), and PC Runtime with WinCC Comfort/Advanced/Professional in TIA Portal V16 through V19. The same logic applies to S7-300/400 PLCs when paired with a compatible HMI, with small syntax differences in the date/time blocks.

Prerequisites and Compatible Engineering Environment

Component Requirement
Engineering tool TIA Portal V16 / V17 / V18 / V19 with WinCC Comfort/Advanced/Professional installed
HMI runtime Comfort Panel firmware V16.0.0.0 or later; Unified Comfort Panel V17.0.0.1 or later
PLC S7-1200 firmware V4.2 or later, S7-1500 firmware V1.8 or later with integrated HMI connection
Storage medium USB stick or SD card formatted as FAT32, capacity 1 GB to 32 GB
Data Block source Optimized DB on the PLC containing the INT counters and a BOOL trigger
Network access (optional) Web server (MiniWeb) enabled on the panel for file retrieval

Before opening the project, confirm the HMI panel is on the same PROFINET subnet as the PLC and that the HMI connection in the TIA project is in Online state. A panel that cannot see the PLC will compile the data log without error but will not write a single row.

Data Log Architecture in TIA Portal

SIMATIC HMI distinguishes three log types. Each has its own storage path, retention rule, and export format.

Log type File format Default path Trigger
Data log CSV (default) or RDB (binary) \Storage Card SD\Logs\ or \USB\Logs\ Time, change, or LogTag
Alarm log CSV \Storage Card SD\Logs\ Alarm events only
Audit trail CSV (append-only, GMP-compliant) \Storage Card SD\Logs\Audit\ Operator actions

For weekly INT snapshots, only the Data log is used. The two relevant configuration blocks are:

  • Log properties - name, path, max entries, file format, file name pattern.
  • Per-tag acquisition mode - Cyclic continuous, On change, or On demand.
Acquisition mode When a row is written Typical use
Cyclic continuous Every N seconds, regardless of value Trend display, long-term sampling
On change When the tag value changes by more than a configured delta State tracking, threshold alarms
On demand Only when the HMI calls LogTag Scheduled snapshots, event-driven logging

For a weekly counter snapshot, the correct mode is On demand. Selecting Cyclic continuous with a 1-week cycle writes only one row per week but cannot be triggered manually; selecting On change writes a row every time the counter increments, which is what produces the "ten rows per snapshot" symptom in the field.

S7-1500 DB HMI Tag PLC Scheduler LogTag() call Data Log CSV USB / SD card Trigger path: PLC scheduler flips a BOOL at 06:00 Monday, HMI event calls LogTag, one row is appended to the CSV on the USB stick.

Configuring the Data Log and Logged Tags

Open the HMI device in the TIA Portal project tree, expand Historical data, and add a new data log. The following parameters are mandatory for the weekly snapshot to work correctly.

  1. Name: WeeklyCounters - the name is referenced by the LogTag call and must be unique within the HMI.
  2. Storage location: select the USB stick. In TIA Portal V17+ the symbolic path is \USB\Logs\; the runtime maps this to /media/usb/Logs/ on a Comfort Panel and to /home/industrial/Logs/ on a Unified Panel.
  3. Entries per log: set to a value greater than 52 (one year of weekly snapshots) plus 10% headroom. For a TP700 with 8 MB of internal flash, 200 is safe; for a TP2200 with SD card, 2000 is acceptable.
  4. File format: CSV for direct Excel import.
  5. File name: WeeklyCounters_<DateTime>.csv - the runtime substitutes the creation timestamp automatically.

After creating the data log, add the INT tags from the PLC DB. The two critical settings per tag are:

Tag PLC address Acquisition mode Cycle / trigger
HMI_Counter1 %DB20.DBW0 On demand LogTag call only
HMI_Counter2 %DB20.DBW2 On demand LogTag call only
HMI_Counter3 %DB20.DBW4 On demand LogTag call only
HMI_Trigger %DB20.DBX6.0 Cyclic continuous, 500 ms Used as event source
Why On demand for every counter. A mixed configuration is the most common root cause of "ten rows per snapshot". If even one tag is set to Cyclic continuous with a 1-second cycle, the runtime writes that tag once per second regardless of the LogTag call. Setting every counter to On demand and triggering the log from a single edge event guarantees one row per snapshot, one row per trigger.

Triggering Logs with the LogTag System Function

LogTag is a WinCC system function in the Logs group. In a Comfort Panel project it appears in the event editor under System functions > Logs > LogTag. The signature takes two string parameters: the tag name and the data log name.

The recommended configuration is to attach the LogTag call to a value-change event on the trigger tag. This makes the event fire exactly once per rising edge of the trigger bit and avoids duplicate writes.

  1. In the HMI project tree, open Screens > <Start screen> (or any always-on background screen).
  2. From the toolbox, drop a rectangle or invisible button anywhere on the screen - it acts only as an event carrier.
  3. In the Properties pane, switch to the Events tab.
  4. Add an event of type Tag > Value change. Bind it to HMI_Trigger.
  5. From the function list, add System functions > Logs > LogTag.
  6. Configure the function with two parameters: HMI_Counter1 and WeeklyCounters. Repeat for HMI_Counter2 and HMI_Counter3 so the single edge writes all three counters in one row.

Calling LogTag three times in the same event is correct: the runtime writes one row containing all three tag values, not three rows. The function is synchronous; a subsequent LogTag call within the same event uses the snapshot from the same scan cycle.

VBScript Equivalent (Optional)

Unified Comfort Panels and WinCC Professional projects can call the same function from VBScript for more complex orchestration:

' On a value-change event of HMI_Trigger
Sub OnChange(ByVal Item)
    If SmartTags("HMI_Trigger") = True Then
        HMIRuntime.LogTag "HMI_Counter1", "WeeklyCounters"
        HMIRuntime.LogTag "HMI_Counter2", "WeeklyCounters"
        HMIRuntime.LogTag "HMI_Counter3", "WeeklyCounters"
    End If
End Sub
Edge polarity. The PLC code below resets the trigger bit before the next event fires. Without the reset, the tag remains TRUE, the runtime sees no new edge, and the next Monday's snapshot is missed.

PLC-Side Weekly Scheduler in SCL

The trigger must be generated by the PLC, not the HMI, because the HMI runtime clock can drift and is not synchronized with the operator's shift schedule. S7-1500 firmware V2.0 and later expose RD_SYS_T, which returns a DTL (Date and Time Long) structure with weekday information.

The following SCL block produces a one-second positive edge on HMI_Trigger every Monday between 06:00:00 and 06:00:59, and latches the trigger to prevent multiple writes within the same minute.

// FB_WeeklyLogTrigger
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR_INPUT
    i_Enable   : BOOL;   // Master enable from operator screen
END_VAR
VAR_OUTPUT
    o_Trigger  : BOOL;   // Connected to HMI_Trigger tag
END_VAR
VAR
    s_Time       : DTL;
    s_Latch      : BOOL;
    s_PrevSec    : INT;
END_VAR
BEGIN
    s_Time := RD_SYS_T();

    // Monday = 2 in DTL (Sun=1, Mon=2 ... Sat=7)
    // Window: 06:00:00 to 06:00:59 on Monday only
    IF i_Enable
       AND s_Time.WEEKDAY = 2
       AND s_Time.HOUR = 6
       AND s_Time.MINUTE = 0
       AND s_Time.SECOND < 2
       AND NOT s_Latch
    THEN
        o_Trigger := TRUE;
        s_Latch   := TRUE;
    END_IF;

    // Reset latch and trigger at 06:01:00
    IF s_Time.HOUR = 6
       AND s_Time.MINUTE = 1
    THEN
        s_Latch    := FALSE;
        o_Trigger := FALSE;
    END_IF;

    // Safety: force reset if trigger has been high more than 5 s
    IF o_Trigger AND s_Time.SECOND - s_PrevSec > 5 THEN
        o_Trigger := FALSE;
    END_IF;
    s_PrevSec := s_Time.SECOND;
END_FUNCTION_BLOCK

Compile the block, download it to the S7-1500, and connect o_Trigger to "DB20".HMI_Trigger. Set the master enable i_Enable from a button on the HMI so operators can pause the weekly snapshot during maintenance.

Alternative: HMI Scheduler

If the PLC does not need to be involved, the same trigger can be generated entirely in the HMI using a scheduled task. In TIA Portal open Schedules > Add new and configure a weekly event with the following properties:

Property Value
Start time Monday 06:00:00
Recurrence Weekly, every 1 week
Time range Start to end of day
Event Set tag HMI_Trigger = TRUE

Add a second scheduled task at 06:01:00 that sets the same tag to FALSE. This recreates the edge without PLC code, but loses the protection of a master enable tied to the operator screen.

Storage Paths, USB Behavior, and File Retrieval Methods

The HMI runtime differentiates between three storage media. The data log path in the project must match the medium that is physically present at runtime, otherwise the log is created on a different partition than expected.

Path in TIA Portal Runtime mount (Comfort) Runtime mount (Unified) Max file size
\Storage Card SD\ /media/simatic/X61/ /media/sd/ SD card capacity
\USB\ /media/usb/ /media/usb/ USB stick capacity
\Storage Card SD\Logs\ Recommended default Recommended default SD card capacity
USB removal behavior. On Comfort Panels, pulling the USB stick while a data log is open causes the runtime to pause the log and queue entries in RAM. The log resumes only after the same or a different USB stick is re-inserted and the runtime re-mounts the medium. If the panel is restarted with the USB absent, the queued entries are lost. The Unified Panel behaves similarly, but additionally writes a .lock file in /home/industrial/Logs/ until the original USB is reinserted. Always configure the storage path to Storage Card SD and copy the file to USB as a separate step, or use a Siemens-approved industrial USB stick with mechanical retention.

File Retrieval Options

  1. MiniWeb (HTTP file browser). Enable the web server on the HMI (Project tree > HMI > Web server > Activate). On a Comfort Panel, navigate to http://<panel-ip>/Files/; the data log appears in the folder tree. On a Unified Panel, the same path is https://<panel-ip>/ with a login prompt if HTTPS is enabled.
  2. FTP/SFTP. Comfort Panels do not include an FTP server. Use the web server or remove the storage medium directly.
  3. Direct removal. For shift-based workflows, the operator removes the USB stick after the Monday snapshot, copies the CSV, and reinserts the stick. The runtime reopens the data log automatically within 5 to 10 seconds.
  4. Recipe synchronization. For automated retrieval, configure a recipe on the HMI that exports the data log file to a network share via the ExportDataRecords system function (WinCC Professional only).

Defect Matrix and Field-Proven Diagnostics

Symptom Likely cause Diagnostic Fix
10+ rows per snapshot Tags set to Cyclic continuous with sub-second cycle Open HMI > Historical data > WeeklyCounters, inspect per-tag acquisition mode Set all snapshot tags to On demand
Log only after runtime restart USB stick was removed during a previous shift; runtime is in paused state Check panel system events for "Log paused" message Re-insert USB stick, wait 10 s, retrigger
No rows at all Trigger tag not connected, or PLC clock is wrong Online > Watch table on the PLC DB, verify HMI_Trigger pulse Correct trigger wiring or set PLC time via SET_TIME
CSV file is empty (0 bytes) Path points to a medium that is not mounted, or file name pattern invalid WinCC Runtime trace: Diagnostics > System events Change path to \Storage Card SD\Logs\, rebuild project
Tags show stale values in CSV Acquisition mode is On change, counter incremented multiple times before trigger Inspect data log entries in the runtime viewer Switch to On demand; verify PLC trigger fires before the counter increments
File appears corrupt in Excel CSV was opened on the panel during a write Open the CSV on a PC with Excel; check for truncated last row Stop the data log before retrieval, or copy via MiniWeb
Duplicate rows on consecutive Mondays Trigger bit not latched or not reset Inspect HMI_Trigger in the HMI tag table Add the latch/reset logic shown in the SCL example

Enabling the WinCC Runtime Trace

For deeper diagnostics, enable the system trace on the panel. On a Comfort Panel, connect via ProSave and open Logs > System. Filter for the keyword LogTag to see every call, including the tag name and data log name. A failed call produces an entry of the form HmiRtLog - LogTag failed: log not started or LogTag failed: tag not found. The corresponding error codes are listed in the TIA Portal Information System under Diagnostics > System events > Logs.

Commissioning and Verification Procedure

  1. Compile the HMI project, download to the panel, and start runtime.
  2. Insert the USB stick and wait until the runtime logs a Storage medium connected system event. On a Comfort Panel this is visible in the diagnostics view; on a Unified Panel it appears in the notification area.
  3. Open an online watch table on the PLC and force HMI_Trigger to TRUE for 2 seconds, then back to FALSE.
  4. Within 3 seconds, navigate to \USB\Logs\ via MiniWeb and download WeeklyCounters_*.csv.
  5. Open the CSV in Excel. The expected content is one header row and one data row, with the three INT counters aligned to columns 1, 2, and 3.
  6. Confirm the runtime time and the timestamp in the CSV match within 1 second. A mismatch of hours indicates a UTC vs local-time misalignment on the panel - correct via Control Panel > Date/Time.
  7. Set the PLC clock forward to the next Monday 05:59:55 and observe the trigger pulse. Verify the new row appears in the CSV without restarting the panel.
  8. Remove the USB stick for 30 seconds, reinsert, and confirm the data log resumes within 10 seconds by inspecting the next Log resumed system event.
Long-term test. Leave the panel running over a full week, including at least one power cycle on the PLC. A correctly configured system writes exactly one row per scheduled trigger regardless of PLC restarts, HMI reboots, or USB removals.

Performance Considerations

Each LogTag call writes a fixed header plus the tag values to the CSV. On a TP700 with a USB 2.0 stick, the typical write latency is 80 to 150 ms per call. A snapshot of three INT tags therefore completes in under 500 ms, which is below the 1-second window used in the SCL scheduler. Avoid calling LogTag for more than 20 tags in a single event; if more are required, batch the calls across two events 1 second apart to keep the runtime responsive.

Field-Engineering Notes

On a TP900 Comfort Panel paired with an S7-1500 CPU 1511-1 PN, the configuration described above writes a 200-byte CSV per week. With 52 weekly entries per year plus header, the file size remains under 20 KB. The default 2,000-entry limit per data log supports nearly 38 years of weekly snapshots on a single file, but most plants rotate the USB stick quarterly and archive the CSVs to a network share.

For multi-shift plants where the operator needs to read the counters on a different day, expose a manual trigger button on the HMI that calls LogTag directly. The button event should not be tied to a tag change, and the button should be access-protected through the user administration. This provides a fallback path when the PLC clock is wrong or the scheduler is disabled during commissioning.

For plants in regulated industries (pharma, food, water), the Audit Trail is the correct log type, not the Data log. Audit Trail entries are append-only, signed, and cannot be deleted from the runtime. The trigger mechanism is the same LogTag function, but the destination path is fixed and the format is GMP-compliant CSV with operator ID and reason code.

References to Official Documentation

Authoritative sources for the procedures in this article:

  • Siemens Industry Online Support - main portal for firmware updates, manuals, and FAQ entries on WinCC data logging.
  • SIMATIC HMI systems product page for panel specifications and supported firmware versions.
  • TIA Portal Information System, accessible from the Help menu of TIA Portal, for the canonical reference of the LogTag system function, the data log editor, and the scheduled tasks editor. Always verify the parameters against the installed TIA Portal version's help, because the function signature has evolved between V15 and V19.

Frequently Asked Questions

Why does my data log write ten rows when I call LogTag once?

One or more tags in the data log are configured with the acquisition mode "Cyclic continuous" and a sub-second cycle. The runtime writes those tags on their own schedule and ignores the LogTag call. Open HMI > Historical data, select the data log, and set every tag you want to snapshot to "On demand".

Why does logging stop when I remove the USB stick?

SIMATIC HMI runtime pauses any data log whose storage path becomes unavailable. Comfort and Unified Panels write a "Log paused" system event when the medium is removed. Reinsert the same or a different formatted USB stick within the retention period, and the runtime resumes the log automatically after roughly 5 to 10 seconds. For unattended operation, point the storage path to the SD card and copy the CSV to USB as a separate recipe step.

How do I trigger the snapshot exactly once per week?

Generate a 1- to 2-second positive edge on a BOOL tag from the PLC at the desired day and time, and attach the LogTag call to a value-change event of that tag. Use the SCL example with RD_SYS_T and a latch variable to ensure only one edge per scheduled window. The HMI scheduler is an alternative for projects where the PLC is not available.

Can I retrieve the CSV file over the network without removing the USB stick?

Yes. Enable the Web server on the HMI and use the built-in MiniWeb file browser at http://<panel-ip>/Files/ to download the CSV. On a Unified Comfort Panel the same interface is available over HTTPS. WinCC Professional additionally supports the ExportDataRecords system function for scripted transfer to a network share.

Why does the snapshot row show the previous week's value, not the current one?

The data log captures the tag value at the moment the LogTag call is executed, not at the moment the trigger bit was set. If the PLC updates the counter after the trigger pulse, the logged value lags by one cycle. Insert a one-cycle delay in the PLC between setting the trigger and the counter update, or place the LogTag call on a value-change event of a tag that is updated only after the counters are stable.

Back to blog