WinCC Flexible One-Time Tag Logging: Daily CSV Export Setup

David Krause15 min read
SiemensTutorial / How-toWinCC
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

Overview of WinCC Flexible Data Logging Architecture

WinCC Flexible (the HMI configuration suite that preceded TIA Portal's WinCC Comfort/Advanced, sold under the 6AV6 series part numbers) provides two distinct mechanisms for persisting tag values: the integrated Data Log that stores values in a database file, and script-based file I/O that writes directly to a CSV or text file using VBScript and the FileSystemObject. Selecting the right mechanism is the first design decision when the requirement is a single end-of-day snapshot rather than a continuous time series.

Comparison of Logging Mechanisms in WinCC Flexible
Mechanism Storage Backend Trigger Source Output Format Panel Support
Data Log (LogTag function) MS Access (.mdb) on PC RunTime, .csv export through Runtime viewer Cyclic, On Change, On Demand Database rows with timestamp PC Panels and 270 series panels and newer
VBScript file I/O Custom path on Storage Card, USB, or local disk Script-controlled, Scheduler, button event Free-form CSV or TXT Windows CE 5/6/7 and Windows Embedded panels only
Tag Logging with "On Demand" mode Data Log database Explicit LogTag() call Database row, no automatic timestamp drift Same as Data Log

For an end-of-day snapshot containing only the tag name and its current value, the VBScript approach gives maximum control over column layout and file naming, while the Data Log approach is the officially supported mechanism for audited, time-stamped archival. A robust field implementation uses both: LogTag for buffered storage and on-screen history, then a VBScript export routine for the user-facing CSV that drops the timestamp column.

Data logging is supported as from the 270 series HMI panels and on all PC-based RunTime stations running WinCC Flexible 2007 SP3 or later. Older OP series panels (OP 73, OP 77A, TP 170A/B) and the MP 270 with Windows CE 3.0 do not support the Data Log feature. Reference: Siemens KB 26190515 - Archiving tags and messages in WinCC flexible.

Prerequisites

Confirm the following before configuring the project:

  • WinCC Flexible 2008 SP3 (build 01.04.02.00 or later), WinCC Flexible 2007 SP3, or WinCC Flexible 2010 SP2 update 1 for newer panel firmware.
  • Target panel firmware: 270 series (MP 277, TP 277, OP 277) or higher, or any PC-based RunTime panel (WinCC flexible RT).
  • HMI tag already configured in the project tree with a valid PLC connection (PROFINET, PROFIBUS, MPI, or PPI for S7-200).
  • For the VBScript CSV generator: a Windows CE 5/6/7 or Windows Embedded Standard 2009 panel. Pure Windows CE 3.0 panels do not expose the VBScript runtime.
  • Engineering station with administrator rights, to enable the Runtime scripting environment and the Data Log option in the project properties.
  • Free storage space of at least 50 MB on the Storage Card or hard drive to accommodate one full year of daily CSV files at typical 10-tag depth.

Understanding Tag Acquisition Modes

Each tag that participates in a Data Log carries an acquisition mode configured under Properties → Logging. Selecting the wrong mode is the single most common cause of "logs every second" behavior: a tag set to Cyclic with a 1-second polling interval will write a row to the database every second regardless of whether a user has pressed a start button. The acquisition cycle runs independently of any UI element.

Tag Logging Acquisition Modes
Mode Behavior Typical Use Case Trigger Required
Cyclic Logs at fixed interval (e.g., every 1 s, 10 s, 1 min) Continuous trend recording No
On Change Logs only when the value changes by more than the configured tolerance Discrete state tracking, slowly varying process values No
On Demand Logs only when LogTag() is called from a script or function Event-triggered snapshots, batch reports, end-of-shift records Yes (LogTag, button, scheduled task)

For a one-time daily snapshot the correct mode is On Demand. The Data Log database is created when the project is first compiled to the panel, but no row is written until an explicit LogTag call references the tag by name. The tag is therefore enrolled in the logging system without producing spurious records.

A tag can simultaneously be a "Logging tag" in the HMI tag editor and have its acquisition mode set to On Demand. The tag is then part of the log schema, but writes only occur when triggered. Reference: TIA Portal V20 - Basics of data logging (RT Unified).

Step-by-Step: Configuring Tags for One-Time Logging

  1. Open the WinCC Flexible project and expand the project tree to HMI Tags.
  2. Select the tag that should appear in the daily CSV (for example Motor_Speed, Tank_Level, Pressure_kPa).
  3. Open the tag's Properties dialog and switch to the Logging tab.
  4. Check Logging tag to enroll the tag in the data log schema.
  5. Set Acquisition mode to On demand. Do not select Cyclic under any circumstance for this use case.
  6. Under Logging → Data log, select the target log file (default: a single log is created automatically on first write; additional logs can be defined in Logs → Data logs).
  7. Set Sampling to On demand even if the option appears greyed out; this enforces a single write per explicit trigger.
  8. Click OK and repeat for every tag that should appear in the daily CSV.

Compile the project and transfer it to the panel. After the first transfer, the panel creates the .mdb file at \Storage Card\Logs (Windows CE) or %ProgramData%\Siemens\HMI\Logs (PC Runtime). The file exists on disk but remains empty until the first explicit LogTag call.

Implementing the LogTag Trigger via Button Event

Create a button on the desired screen, assign a function list to the Press event, and insert the LogTag system function. The function takes the tag name as a string parameter.

LogTag Function Signature
Parameter Type Description
Tag name String Name of the HMI tag to log. Must match exactly, case sensitive on PC Runtime.
Return value Boolean TRUE on success, FALSE if the tag does not exist or the log is full.

Function list configuration for a single button press:

  1. Add a new function to the Press event of the button.
  2. Select LogTag from the system function list.
  3. Enter the tag name as a string literal, e.g., Motor_Speed.
  4. Duplicate the function call for every tag in the daily CSV list.
  5. Add a second function to the same event list: a VBScript call that performs the file write (see next section).

The order matters: the LogTag calls write the value to the database, then the VBScript reads SmartTags("TagName").Value and writes the CSV row. The SmartTag read picks up the live process value, not the database row, which is acceptable because the same value was just written.

Scripting the Daily CSV File Generation

For full control over the output format (tag name and value only, with no timestamp), use a VBScript function on a Windows-based panel. The script opens (or creates) a file with today's date in the name, writes a header row, then iterates the tag list and writes one line per tag.

' WinCC Flexible VBScript - Daily CSV snapshot
' Attach this to the Press event of a button or a scheduled task.

Dim fso, file, logPath, fileName
Dim tags, i, tagName, tagValue

tags = Array("Motor_Speed", "Tank_Level", "Pressure_kPa", _
            "Valve_Position", "Pump_Running", "Temperature")

Set fso = CreateObject("Scripting.FileSystemObject")

' Build path: \Storage Card\Logs\Daily_YYYY-MM-DD.csv on Windows CE panels
logPath = "\Storage Card\Logs"
If Not fso.FolderExists(logPath) Then
    fso.CreateFolder(logPath)
End If

fileName = logPath & "\Daily_" & Year(Now) & "-" & _
           Right("0" & Month(Now), 2) & "-" & _
           Right("0" & Day(Now), 2) & ".csv"

' Open file in append mode (8 = ForAppending), create if missing
Set file = fso.OpenTextFile(fileName, 8, True)

' Write header only if the file is new (size = 0)
If file.Line = 1 Then
    file.WriteLine "TagName;Value"
End If

' Write one row per tag
For i = 0 To UBound(tags)
    tagName = tags(i)
    tagValue = SmartTags(tagName).Value
    file.WriteLine tagName & ";" & CStr(tagValue)
Next

file.Close
Set file = Nothing
Set fso = Nothing

Field notes from commissioning this script on MP 277 panels:

  • The FileSystemObject is part of the VBScript runtime on Windows CE 5/6/7; on Windows CE 3.0 (older MP 270) it is not available and the project must be migrated to a 270 series panel.
  • SmartTags("X").Value returns the HMI tag's current runtime value, not the underlying PLC address. The value is always read live and reflects the last successful update from the PLC.
  • File mode constant 8 is ForAppending. Mode 2 (ForWriting) overwrites the file. Mode 1 (ForReading) opens an existing file. The third argument True enables create if not exists.
  • The header check uses file.Line = 1: a newly created file starts at line 1 with the read/write pointer before the first line. The Right("0" & Month(Now), 2) idiom zero-pads single-digit months and days, ensuring the filename sorts chronologically.
  • Use ; (semicolon) as the delimiter to match the German/European CSV convention that Excel uses on a system with German regional settings. Switch to , for US locales, or write both and let the user pick.

Formatting the CSV Output (Tag Name and Value Only)

The original problem statement is explicit: the CSV must contain only the tag name and its value, with no date and no time column. The script above achieves this by writing a fixed two-column header and only those two columns per row. Three things to verify before declaring success:

  1. Confirm that the Data Log configuration in WinCC Flexible does not silently add a timestamp column when the log is later exported. The Data Log always includes the timestamp internally; the VBScript file is a separate artifact and is not affected by the Data Log schema.
  2. Confirm that the VBScript is not inadvertently calling a function list item that writes a separate timestamped record. Disable Cyclic logging on every tag in the daily list to avoid the database receiving duplicate entries from a parallel cycle.
  3. Confirm that the panel's regional settings match the script's date format. A panel set to English (United States) produces filenames with US date order, breaking chronological sorting on a German engineering station. The Year() / Month() / Day() functions are locale-independent and produce ISO 8601 output YYYY-MM-DD.

File Storage Locations by Panel Type

Default CSV Storage Paths
Panel Path Used by Script Notes
MP 277 / TP 277 / OP 277 (Win CE 5/6) \Storage Card\Logs Storage card is the CF or SD card; survives power loss.
Comfort Panel TP 1500 / TP 1900 (when loaded with WinCC Flexible RT) \Storage Card\Logs or \USB Storage\Logs USB stick hot-swappable for file retrieval.
PC Runtime (WinCC flexible RT on Windows 7/10/11) C:\ProgramData\Siemens\HMI\Logs or a user-defined path Use UNC paths for network shares if the user wants centralized collection.
Mobile Panel 277 (F) IWLAN \Storage Card\Logs Battery-backed; coordinate file write with charging cycle to avoid corruption.
On Windows CE panels the backslash is the path separator. The VBScript above uses \ in literal strings because the VBScript parser interprets a single backslash as an escape character. On PC Runtime both \ and / work, but stay consistent to avoid cross-platform issues during migration.

Scheduled End-of-Day Execution

To run the CSV generator automatically at 23:59 every day without operator intervention, use the WinCC Flexible Scheduler (also called the Time-triggered task planner).

  1. Open Schedules in the project tree and create a new schedule named Daily_EndOfShift.
  2. Set the trigger to Daily, start time 23:59:00, end date empty (recurring indefinitely).
  3. Assign the Press event of an internal (non-visible) button to the function list that runs the VBScript. The button is not placed on any screen; it exists only to host the event.
  4. Add the schedule as the trigger of that button's Press event. WinCC Flexible fires the event on every schedule tick, regardless of screen focus.
  5. Compile and transfer. Verify by changing the panel clock to 23:58:30 and observing the file appear at the scheduled time.

For shifts that do not end at midnight, build the trigger to fire on a specific tag change (e.g., Shift_End = TRUE) using the On Change acquisition mode on a discrete control tag wired to the PLC's shift counter.

Verification and Testing

After the project is transferred, run the following checks on the panel:

  1. Press the trigger button. The screen should not show any visible change. The CSV file should appear at the configured path within two seconds.
  2. Open the file in Notepad on the panel (or in Excel on the engineering station after copying the file). Confirm exactly two columns: TagName and Value.
  3. Verify the file does not grow during a 60-second idle period. A growing file indicates a stray Cyclic acquisition mode has been left enabled on one of the tags.
  4. Change a tag value at the PLC and re-trigger the script. The new value should appear in the next row of the same file; the previous row must not be overwritten.
  5. Power-cycle the panel. The file must survive the reboot. If it does not, the Storage Card is write-protected or the path is on volatile memory.
  6. Test the schedule by setting the panel clock to 23:58:50 and waiting. The file should appear at 23:59:00. The panel's battery-backed RTC must be functional; a dead RTC battery causes the schedule to drift or never fire.

Troubleshooting Common Issues

Field-Proven Diagnostic Matrix
Symptom Likely Root Cause Corrective Action
File grows by one row per second Tag acquisition mode set to Cyclic 1 s instead of On Demand Open Properties → Logging, set Sampling to On demand for every tag
File empty after pressing button VBScript runtime not enabled on the panel
"Object required" error in the script FileSystemObject missing on Windows CE 3.0 Migrate to a 270 series panel (Win CE 5/6) or PC Runtime
Header row duplicated on each press File opened in Write mode (2) instead of Append mode (8) Change the second argument of OpenTextFile to 8
Garbled characters in the CSV Wrong code page; the panel is set to UTF-16 and Excel expects ANSI Add file.WriteLine using Chr(9) for tab delimiter, or export to ANSI explicitly with ADODB.Stream
Schedule never fires Schedule trigger is screen-bound rather than project-global Move the trigger to a non-visible internal button; verify the schedule shows a green check in the project tree
File appears but the values are stale (yesterday's data) PLC connection is down; SmartTags(X).Value returns the last good value Check the connection diagnostics screen; verify the PLC IP or PROFIBUS address is reachable
"Permission denied" on file open File is open in Excel on the engineering station and the runtime tries to append Close the file before triggering; or implement a rotation scheme (rename to .bak after writing)

Migration Notes: WinCC Flexible to WinCC Unified

Projects originally created in WinCC Flexible can be migrated to TIA Portal and continue to use the same data log schema. In TIA Portal V17 and later, WinCC Unified replaces the WinCC Comfort/Advanced environment and introduces a new tag logging concept based on Logging tags in the HMI tag editor.

  • Tags are still classified as Logging tags, but the acquisition cycle is configured separately on the connected Data Log, not on the tag itself.
  • The legacy LogTag system function is replaced by the Logging tag's "Trigger logging" property and a new Tags area in the Unified faceplate controls.
  • VBScript is deprecated in WinCC Unified in favor of JavaScript and the new GraphQL data interface. The VBScript file I/O pattern above must be rewritten in JavaScript using the FileSystem API of the Unified Runtime.
  • For new projects, configure logging tags in the HMI tag editor under the Logging tags tab, then bind them to a trend control or to a script that exports to CSV. Reference: TIA Portal V20 - Basics of data logging (RT Unified).

Safety and Data Integrity Considerations

Before commissioning any logging function on a production panel, validate the following:

  • Confirm the Storage Card has at least 10 percent free space. A full Storage Card causes the OpenTextFile call to throw an unrecoverable error and the panel may enter a fail-safe state.
  • Implement a file rotation policy. A daily CSV over 365 days produces a year of data; the Storage Card should be replaced or the files copied to a network share every quarter.
  • If the CSV is used as a regulatory record, enable the Audit Trail option in the project properties. The Data Log entries are signed with a hash chain that Excel exports do not preserve.
  • Confirm that the panel's user authentication is configured. A button-triggered export without login allows any operator to overwrite the file; require a password group of at least level 3 ("Operator") on the event.

FAQ

Why does my WinCC Flexible tag log every second even though I pressed the start button only once?

The tag's Acquisition mode is set to Cyclic with a 1-second polling interval. The start button is not involved; the database writes on its own schedule. Open Properties → Logging and change the mode to On demand, then trigger the write with the LogTag system function.

Can I generate a CSV with only the tag name and value, no timestamp?

Yes. The integrated Data Log always adds a timestamp, but a VBScript that uses FileSystemObject writes a custom file. Use a two-column header TagName;Value and write one line per tag from a function list on the button Press event.

Which WinCC Flexible panels support VBScript for file I/O?

Panels running Windows CE 5/6/7 or Windows Embedded Standard 2009 expose the VBScript runtime and FileSystemObject. The MP 270 with Windows CE 3.0, the OP 73, OP 77A, and the TP 170A/B do not support VBScript and cannot write CSV files directly.

How do I run the CSV export automatically at end of day?

Create a Schedule in the project tree that fires daily at 23:59:00 and triggers the Press event of an internal (non-visible) button. The button's function list runs the VBScript that creates or appends the daily CSV.

Does this procedure work in WinCC Unified without changes?

No. WinCC Unified replaces VBScript with JavaScript and introduces a new Logging tags concept in the HMI tag editor. The VBScript file I/O pattern must be rewritten using the Unified JavaScript API and the FileSystem service. The fundamental design (on-demand trigger, one row per tag, two-column CSV) is preserved.

Back to blog