WinCC Tag Logging: Starting Logging via C-Script (V5/V6)

David Krause14 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

WinCC Tag Logging: Starting Logging via C-Script (V5/V6)

Engineers migrating from WinCC V5.x to V6, V7, or WinCC Unified V20 frequently need to start or stop tag logging from an event, a tag value change, or a button press. In WinCC 6.0 and later this is exposed as a direct property of the logging tag (the "Start event" trigger), but in WinCC 5.0 and 5.1 SP2 the only path is a C-script call into the TAGLOG standard function library. This reference documents the legacy C-script technique, explains the function exposed under Standard functions > TAGLOG > TOOLBARBUTTONS > TlgTableWindowPressStartStopButton, provides a working code example, and maps the equivalent modern trigger in WinCC V6/V7 and WinCC Unified V20.

1. Problem Context: Why Script-Triggered Logging Exists

Tag logging in WinCC is the runtime subsystem that archives process values, messages, and user data into a SQL-based archive. By default the runtime starts logging the moment the project activates, and every connected tag is sampled on the cycle or on a defined acquisition cycle. Many plant processes do not need continuous logging — they only need a snapshot when a defined event occurs:

  • A batch starts or ends (start-of-batch, end-of-batch trigger).
  • A binary tag changes (valve opened, motor started, alarm acknowledged).
  • An operator presses a button on a process screen.
  • A quality threshold is crossed on an analog measurement.

Continuous logging in these cases wastes archive space, fills the SQL database with redundant rows, and complicates post-event analysis. From WinCC 6.0 onward the logging tag has a configurable Start event property: the tag itself becomes the trigger. In WinCC 5.0/5.1 SP2 that property is not present, so the only programmatic way to start logging is through a C-script call into the TAGLOG function library.

Compatibility note. The C-script API documented here applies to WinCC V5.0, V5.1, and V5.1 SP2. The function names and the path through the standard function library remain valid through WinCC V6.0 SP3 and V6.2. From WinCC V7.0 onward the C-script API was formally deprecated; new projects should use the configuration-based trigger or migrate to WinCC Unified V20 logging tags.

2. WinCC Version Landscape and API Availability

The script-based start/stop technique is not equally supported across the WinCC product line. The table below summarizes which generation supports which trigger mechanism.

WinCC Version Configurable Start Event on Logging Tag C-Script TAGLOG API Recommended Trigger Method
V5.0 / V5.1 / V5.1 SP2 Not available Available C-script call to TlgTableWindowPressStartStopButton
V6.0 / V6.0 SP3 / V6.2 Available Available (legacy) Start event property (preferred) or C-script
V7.0 / V7.2 / V7.4 / V7.5 Available Deprecated Start event property; VB/VBA only for legacy code
WinCC Professional (TIA Portal) V15–V20 Available Not available (C-script removed) Logging tag trigger / scheduler
WinCC Unified V20 Available (logging tag trigger in HMI tags editor) Not available (C-script removed) Logging tag with trigger in "Logging tags" tab

The legacy function is therefore the canonical solution only on the V5.x branch. On every later branch the configuration-based start event replaces the script, and the modern WinCC Unified V20 data logging model exposes the same capability in the "Logging tags" tab of the HMI tags editor, used in conjunction with the trend control and f(x) curve controls.

3. Prerequisites

Before you can start logging from a C-script in WinCC 5.0/5.1 SP2, confirm the following:

  1. Tag Logging Runtime is licensed and active. The Tag Logging editor must be present in Graphics Designer and the runtime component CCMsgLogSrv.exe (archive server) must be running. Open the WinCC Explorer — if "Tag Logging" is missing the runtime license is not installed.
  2. The target archive exists. In the Tag Logging editor, create at least one archive (e.g. ProcessValueArchive) and at least one logging tag. Note the archive name and tag name — both are passed to the script as string parameters.
  3. Graphics Designer is open with the target picture. A C-action must be attached to a picture object (button, picture window, or the picture itself) so it has an event hook in runtime.
  4. The C-script editor is reachable from Graphics Designer. Right-click any object → Properties → Events → right-click the event (e.g. "Mouse click" or "Open picture") → C-action.
Project activation state. C-scripts only execute in runtime. A C-action that calls TlgTableWindowPressStartStopButton from the Graphics Designer editor is parsed but not executed until the project is activated. Use a simulator tag or the WinCC Tag Simulator to validate the call before going to the plant.

4. The TAGLOG Standard Function Library in WinCC C-Script

The C-script editor in WinCC 5.x and 6.x ships with a tree of standard functions under Standard functions. The branch relevant to runtime logging control is Standard functions > TAGLOG. It contains the following sub-branches, each exposing one C function:

Sub-branch Function Prototype Behavior
TOOLBARBUTTONS > TlgTableWindowPressStartStopButton void TlgTableWindowPressStartStopButton(LPCTSTR lpszArchiveName, LPCTSTR lpszTagName, BOOL bStart) Starts or stops a logging tag in the named archive. Used as a script-trigger equivalent of the toolbar Start/Stop button in the WinCC Tag Logging table window.
TOOLBARBUTTONS > TlgTableWindowPressStartButton void TlgTableWindowPressStartButton(LPCTSTR lpszArchiveName, LPCTSTR lpszTagName) Start-only convenience wrapper.
TOOLBARBUTTONS > TlgTableWindowPressStopButton void TlgTableWindowPressStopButton(LPCTSTR lpszArchiveName, LPCTSTR lpszTagName) Stop-only convenience wrapper.
TOOLBARBUTTONS > TlgTableWindowPressPrintButton Print trigger Forces a print of the current table view — not used for start/stop control.
TOOLBARBUTTONS > TlgTableWindowPressExportButton Export trigger Triggers CSV export of the visible table — not used for start/stop control.

The three TlgTableWindowPress*Button functions are the documented public API for runtime start/stop control. They dispatch to the same internal handler as the toolbar buttons in the WinCC Tag Logging table window, which is why the function name references the button rather than the logical operation. Using the consolidated TlgTableWindowPressStartStopButton with a BOOL flag is preferred because the same function can be parameterized for both directions, simplifying code review.

Function-name vs. function behavior. Despite the "Table Window" prefix, these functions do not require a visible table window. They operate directly on the archive server. The name is a holdover from the original 5.0 implementation where the start/stop button lived in the table window toolbar.

5. Calling TlgTableWindowPressStartStopButton

5.1 Function signature

/* WinCC C-script TAGLOG standard function */
void TlgTableWindowPressStartStopButton(
    LPCTSTR lpszArchiveName,  /* Logical archive name, e.g. "ProcessValueArchive" */
    LPCTSTR lpszTagName,      /* Logging tag name, e.g. "Tank1_Level"          */
    BOOL    bStart            /* TRUE = start, FALSE = stop                   */
);

5.2 Parameter rules

  • lpszArchiveName: must match the "Archive name" property in the Tag Logging editor. Case-sensitive. Internal default archives are typically ProcessValueArchive, ProcessControlledArchive, and user-defined names.
  • lpszTagName: must match a logging tag that is configured inside the named archive. If the tag is not in the archive the call returns silently and a warning is written to the WinCC diagnostics file WinCC_Sys_<computername>.log.
  • bStart: pass TRUE to begin logging the tag, FALSE to suspend logging. State is held in the archive server until changed again or until runtime ends.

5.3 Where to call it from

The function can be invoked from any C-action hook on any picture object. Common hooks:

  • Button — Mouse click: operator-initiated start/stop of a specific logging tag (e.g. start recording while a test is running).
  • Picture — Open picture: start logging automatically when the operator opens a process picture.
  • Tag — OnChange: a standard WinCC tag (not the logging tag itself) acts as the trigger — e.g. an "Event_StartBatch" boolean that fires when the batch is launched.
  • Global Script — Trigger: a scheduler-driven C-action that starts logging on a calendar event.

6. Complete Working Example

The example below configures a button on a process picture that starts logging the tag Tank1_Level in archive ProcessValueArchive when clicked, and stops logging when clicked again. It includes a status tag, an internal state variable, and runtime feedback.

6.1 Configuration (Graphics Designer)

  1. Create a button object named btnStartLogging on the target picture.
  2. Create a WinCC tag of type BOOL named LoggingActive (internal or process tag — any source the project can read works).
  3. Open the button's Properties → Events → Mouse → Click action, right-click and choose "C-action".
  4. \

6.2 C-script body

/* Toggle logging of Tank1_Level on each click */
{
    /* Read current state from the internal flag */
    BOOL bCurrentlyLogging = GetTagBit("LoggingActive");

    /* Flip the state: clicking when inactive starts, when active stops */
    BOOL bStart = !bCurrentlyLogging;

    /* Call the TAGLOG standard function. Archive name and tag name
       must match the Tag Logging editor configuration exactly.        */
    TlgTableWindowPressStartStopButton(
        "ProcessValueArchive",
        "Tank1_Level",
        bStart
    );

    /* Persist the new state for the next click */
    SetTagBit("LoggingActive", bStart);

    /* Optional: provide operator feedback on the picture */
    if (bStart)
    {
        SetText(lpszPictureName, "btnStartLogging", "Stop Logging");
    }
    else
    {
        SetText(lpszPictureName, "btnStartLogging", "Start Logging");
    }
}

6.3 Event-triggered variant (no operator click)

For a fully automatic start, attach the call to a tag's OnChange event instead of a button. The example starts logging when a process tag Batch_Start goes TRUE and stops it when Batch_End goes TRUE.

/* C-action on the Batch_Start tag, OnChange event */
if (GetTagBit("Batch_Start"))
{
    TlgTableWindowPressStartStopButton(
        "ProcessValueArchive",
        "Tank1_Level",
        TRUE
    );
    SetTagBit("LoggingActive", TRUE);
}

/* C-action on the Batch_End tag, OnChange event */
if (GetTagBit("Batch_End"))
{
    TlgTableWindowPressStartStopButton(
        "ProcessValueArchive",
        "Tank1_Level",
        FALSE
    );
    SetTagBit("LoggingActive", FALSE);
}
Idempotency. Calling TlgTableWindowPressStartStopButton with bStart = TRUE on an already-active tag is a no-op. Calling it with bStart = FALSE on an already-stopped tag is also a no-op. The state flag (LoggingActive in the example) is therefore safe to write unconditionally.

7. Differences Between Script-Triggered and Event-Triggered Logging

Understanding the difference between the two start mechanisms is critical when migrating a V5.x project or reviewing a code review request.

Property Script-Triggered (V5.x only) Event-Triggered (V6+, WinCC Unified V20)
Configuration Logging tag has no start event; a C-action is required Logging tag carries a configurable start event in its properties
Trigger source Any C-action hook (button, picture, tag, scheduler) A selected WinCC tag's value or edge
Code maintenance Requires C-script review when archive/tag names change Pure configuration; no script to maintain
Portability across versions Limited to V5.x and V6.x V6, V7, TIA Portal, WinCC Unified V20
Diagnostic surface WinCC diagnostics file + archive server status Logging tag diagnostics in the HMI tags editor and runtime

If you maintain a V5.x project that is being upgraded in stages, the C-script call is the only option. If you are starting a new project or migrating an existing one to WinCC Unified V20, configure the start event on the logging tag in the HMI tags editor and remove the C-script entirely.

8. Migration Path: From WinCC V5/V6 C-Script to WinCC Unified V20

Modern WinCC Unified V20 data logging is configured in the "HMI tags" editor, in the "Logging tags" tab. Each logging tag carries its own trigger and is consumed by the trend control, the f(x) curve control, and the alarm control. The migration steps are:

  1. Open the project in TIA Portal and the HMI device that targets WinCC Unified V20.
  2. Open the HMI tags editor, select the "Logging tags" tab.
  3. Create a new logging tag with the same name as the V5.x logging tag (e.g. Tank1_Level).
  4. Assign the same data source tag (process tag) that drives the V5.x archive.
  5. Configure the acquisition cycle and the trigger. The trigger in WinCC Unified V20 replaces the C-script call — it can be a tag value, an edge, or a scheduled time.
  6. Bind the trend control on the Unified screen to the logging tag. The trend control renders the data the same way the V5.x Tag Logging table window did.
  7. Delete the C-action that called TlgTableWindowPressStartStopButton from the migrated picture.

At runtime, the trend control reads from the Unified archive automatically; no script is involved. Per the Unified V20 documentation, the logging tag model is the only model for runtime data acquisition in Unified — the legacy TAGLOG C-API does not exist in Unified.

9. Verification and Diagnostics

After wiring the C-action, validate it with the following sequence before going to the plant.

  1. Activate the project. In WinCC Explorer — File → Activate. The project should reach the runtime state without any "function not found" warnings on the diagnostic screen.
  2. Trigger the action. Click the button or fire the trigger tag with the Tag Simulator. The button label should change to "Stop Logging".
  3. Inspect the archive. In WinCC Explorer → Tag Logging → right-click the archive → "Display archive data". The table window should show a row with a fresh timestamp for the logging tag.
  4. Inspect the diagnostics file. Open <ProjectPath>\diagnose\WinCC_Sys_<computername>.log (V5.1) or the equivalent in V6. Search for the archive and tag name. A successful start should produce no error rows. A failed call typically emits a line containing the archive/tag name and a "tag not found" or "archive not found" reason.
  5. Check the archive server status. In WinCC Explorer → Tag Logging → right-click → "Status". The archive server reports a connected/active state for the archive. A red icon indicates the archive server is not running or the SQL backend is unavailable.

10. Common Faults and Fixes

Symptom Likely Cause Fix
Click does nothing; diagnostics file shows "tag not found" Tag name in script does not match the Tag Logging editor exactly Copy the tag name from the editor and paste it into the script string literal. Watch for trailing spaces and case.
Click does nothing; archive is grayed out in Tag Logging editor Archive server is not running Right-click the archive in WinCC Explorer and select "Start" (WinCC 5.x). Verify the SQL server is reachable.
Logging starts but stops immediately The C-action runs on every picture open, and the state tag was never persisted Use a persistent internal tag or a process tag for LoggingActive instead of a local C variable.
Function not found in C-script editor Project was upgraded but the standard function library was not refreshed Re-install the standard functions from the WinCC installation media, or rebuild the project from the source PDL.
Script runs but archive is empty Acquisition cycle is set to 0 or archive is configured as "short-term" with no online connection Open the archive properties in Tag Logging and confirm a non-zero acquisition cycle. Confirm the archive is "online" (green indicator).
Stop event never fires Trigger tag is the logging tag itself, creating a feedback loop Use a separate process tag as the trigger. The logging tag is the destination, not the source.

11. Field-Proven Caveats

  • Script ordering. If the C-action is on the picture's Open picture event and the logging tag is in a picture that is not yet opened, the call still works — the function operates on the archive server, not on a screen object. Naming the function "TableWindowPress..." is misleading.
  • License cost. A separate logging tag consumes one license point on the legacy Archive license model. Toggling 50 tags via script does not bypass the per-tag license count.
  • SQL backpressure. If the SQL backend cannot keep up with the logging rate, the archive server drops rows and emits a warning. The C-script call still returns success; verification of archive content is required.
  • Time base. The function does not accept a time parameter — it always operates on the current state. For a delayed start, use a global script with a trigger time and a counter.
  • Multi-client projects. The function affects the server-side archive. All clients see the change. Do not run the call from every client unless the intent is exactly that.

12. Frequently Asked Questions

Where is TlgTableWindowPressStartStopButton located in the C-script editor?

Open the C-script editor from any object event, then navigate the tree: Standard functions > TAGLOG > TOOLBARBUTTONS > TlgTableWindowPressStartStopButton. Double-click the entry to insert the function call into the script body.

Can I start logging for multiple tags with one call?

No. The function is per (archive, tag) pair. To start logging for N tags, write a loop that calls the function N times with the same archive name and each tag name. Keep the array of tag names in a static C array or read them from a process tag list.

Does the function work in WinCC 7.5?

The TAGLOG C-API is deprecated from V7.0. The function may still be present in the standard function library for backward compatibility, but new projects should use the configurable start event on the logging tag in the Tag Logging editor or migrate to WinCC Unified V20 logging tags.

What happens if the archive is full?

The archive server continues to accept new rows; the configured overflow behavior (segment switch, delete oldest) takes over. The C-script call does not check archive size. If overflow deletion is disabled, the database will grow until the disk is full and the archive server will stop accepting rows, returning errors in the diagnostics file.

How do I replace this script in WinCC Unified V20?

Configure the start trigger directly on the logging tag in the HMI tags editor, "Logging tags" tab, as documented in the Unified V20 data logging basics. Delete the C-action from the migrated picture. The logging tag will start and stop on the configured trigger with no script involvement.

Back to blog