Triggering Manual TagLogging Segment Change in WinCC Runtime

David Krause13 min read
HMI / SCADASiemensTutorial / 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

1. Overview: Manual Segment Change in WinCC TagLogging

WinCC TagLogging continuously records process values in runtime. By default, the runtime database creates a new segment (file) only when the configured segment time elapses, the configured segment size is reached, or the configured backup time expires. Operators who need a defined, reproducible data set bounded by a process run (start to stop) cannot rely on these default triggers alone. The solution is to start a manual segment change exactly when the operator commands it, typically at process start and process stop, so the runtime writes a closed archive file containing only the values for that batch.

Two complementary mechanisms implement this behavior in WinCC V7 and WinCC Professional (TIA Portal):

  • Event-controlled archiving with a boolean trigger tag that closes the current segment and opens a new one on every edge (recommended approach). See How to Configure Archive - WinCC V7.4: Working with Archives.
  • Acyclic archiving that starts and stops logging on tag events so the system only writes data inside the process window. Referenced in Siemens FAQ ID 850095.

Both mechanisms can be combined: acyclic start/stop defines the active logging window, and a forced segment change at stop guarantees a clean file boundary for export.

2. Prerequisites and Archive Architecture

Before implementing a manual segment change, confirm the project state and the licensing surface.

Prerequisite WinCC V7 WinCC Professional (TIA Portal)
Engineering tool WinCC Explorer 7.4 SP3 or later, 7.5 SP2, or V8.0 TIA Portal V16 or later with WinCC Professional
Runtime license WinCC RT Basic/Comfort/Advanced sufficient for TagLogging; "Number of archive tags" license must cover the active archive WinCC RT Professional archive license
Archive type TagLogging Fast (process values, 500 ms / 1 s cycle) and/or TagLogging Slow (averages, message-triggered) Data Log (fast) and Data Log (slow) inside the HMI device
Storage path Configured under Computer > Properties > Storage path; default <ProjectPath>\ArchiveManager Configured under Runtime settings > Logging > Storage path on the HMI device
Backup media Optional: network share, USB, or a separate partition for segment rollover Same; configurable per log type
TagLogging segments are written as RDB files in WinCC V7 and as SQL Server Compact (.sdf) databases in WinCC Professional. The procedure below covers both formats; only the configuration dialogs differ.

3. Understanding Event-Controlled and Acyclic Archiving

The two mechanisms used here look similar but solve different problems.

3.1 Event-Controlled Segment Change

A trigger tag (typically a boolean) is assigned to the archive. The archive evaluates the tag on every cycle. When the configured edge (rising, falling, or both) is detected, the runtime closes the current segment, assigns it a sequence number, and opens a new segment starting with the next incoming value. The data between two trigger events is contained in exactly one segment file. This is the closest equivalent to "manual" segment change because the trigger tag can be set from any HMI button, PLC bit, or VBS/C action.

3.2 Acyclic Archiving

Acyclic archiving suspends the writer entirely outside the process window. The archive does not write to the database while the start condition is false. When the start condition becomes true, the runtime begins a new segment; when the stop condition becomes true, the runtime closes the segment and idles. This is useful when the user wants to suppress logging during idle periods, not merely bound it. The combination of acyclic start/stop with a forced segment change at the stop edge produces a clean, gap-free batch file.

For batch-style operation ("produce something between start and stop"), acyclic archiving is the preferred mechanism because it limits both the segment count and the disk footprint. The acyclic mechanism is documented in Siemens FAQ ID 850095: Acyclic archiving of process values.

4. Method 1: Event-Controlled Segment Change (Recommended)

This method gives the operator a single button that closes the current segment and starts a new one. The trigger can be a faceplate button, a PLC control bit, or a script-fired value.

4.1 Configuration in WinCC V7 (TagLogging Fast)

  1. Open WinCC Explorer and right-click TagLogging Fast > Open.
  2. In the shortcut menu of the archive, choose Properties > Archive Configuration.
  3. Switch to the Archive Parameters tab. Enable Event-controlled.
  4. Create an internal binary tag, for example @TriggerSegmentChange (WinCC internal tag of type BOOL). Assign it to the Event tag field.
  5. Set the evaluation to On rising edge (or "On change" if you want both edges to start a segment).
  6. Confirm with OK and save the project.
  7. Activate Runtime. Set the trigger tag to 1 from any source (button, script, PLC). The runtime closes the current RDB and starts <ArchiveName>_00002.RDB (or the next free index). See the procedure in the Siemens manual Working with Archives in WinCC V7.4.

4.2 Configuration in WinCC Professional (TIA Portal)

  1. In the project tree, open HMI Tags and create a new tag of type Bool, for example TriggerSegment with acquisition mode Cyclic continuous.
  2. Open Logs and select the data log (Fast or Slow).
  3. In the log properties, open the Event section and assign TriggerSegment as the event tag.
  4. Choose the edge that will start a new segment (rising, falling, or both).
  5. Compile and download to the HMI device. Activate Runtime and toggle the tag.
Both versions require a real signal source. Setting the trigger tag to 1 from a VBS action is allowed; the runtime samples the tag and executes the segment change within the configured logging cycle (500 ms by default in TagLogging Fast, 1 s in Slow). Allow one full cycle before the next trigger to avoid dropped edges.

5. Method 2: Acyclic Archiving for Bounded Logging

When the operator wants the segment to contain only the values from start to stop and not a single sample outside that window, configure acyclic archiving.

5.1 WinCC V7 (TagLogging Slow)

  1. Open the TagLogging Slow archive and select Properties > Archive Configuration.
  2. In Archive Parameters, select Acyclic as the archiving type.
  3. Assign a start tag and a stop tag (both BOOL). The archive writes only when start = 1 AND stop = 0.
  4. Set the Start ID and Stop ID to the desired tag names, for example ProcessStart and ProcessStop.
  5. Optionally enable Event-controlled as well so that the start edge automatically triggers a new segment.

5.2 WinCC Professional (TIA Portal)

  1. Open the data log in the project tree.
  2. Switch the logging mode to Acyclic.
  3. Bind a start tag and a stop tag from the HMI tag table.
  4. Define the segment size and segment time under Runtime settings > Logging as documented at Defining the Log Size and Segmentation (RT Professional).

The acyclic condition is checked on every logging cycle. The runtime will start a new segment on the rising edge of the start tag and close the segment on the rising edge of the stop tag. No code is required.

6. Method 3: Script-Based Manual Segment Trigger

When the operator must trigger a segment change from a custom script (for example, from a button in a C or VBS action), WinCC V7 exposes a small set of internal C functions. The function names below are documented in the WinCC V7 C scripting reference for the archive API.

6.1 VBScript (WinCC V7) Example

' ----------------------------------------------------------------
' Forces a new segment in the TagLogging Fast archive at process stop
' Place this code in a button "Click" event on a process overview
' ----------------------------------------------------------------
Sub OnClick(ByVal Item)
    Dim sArchiveName
    Dim bRet

    sArchiveName = "ProcessArchive_Fast"

    ' TLGCreateSegment is an internal WinCC function exposed via
    ' the ArchiveConnector. Returns True on success.
    bRet = HMIRuntime.Logging.CreateSegment(sArchiveName)

    If bRet Then
        HMIRuntime.Trace "Segment change OK for " & sArchiveName & vbCrLf
    Else
        HMIRuntime.Trace "Segment change FAILED for " & sArchiveName & vbCrLf
    End If
End Sub

The exact object name depends on the WinCC version: in V7.4 use HMIRuntime.Logging, in V7.0/V7.1 the legacy path HMIRuntime.Logging is the same. The function returns a boolean indicating success and writes a status line to the diagnostic trace. Combine it with the event-controlled trigger tag for redundancy.

6.2 C Action (WinCC V7) Example

// ----------------------------------------------------------------
// Manual segment change on a button press (C action in V7)
// Trigger: HMI button "SegmentChangeBtn"
// ----------------------------------------------------------------
#include "apdefap.h"

BOOL OnClick(LPCTSTR lpszPictureName, LPCTSTR lpszObjectName)
{
    // The runtime function is declared in the archive header.
    // Returns TRUE on success.
    BOOL bResult = TLGCreateSegment("ProcessArchive_Fast");
    if (bResult) {
        printf("Segment change OK\n");
    } else {
        printf("Segment change FAILED\n");
    }
    return bResult;
}

Both calls assume the archive name is configured in the project; passing an unknown archive name returns FALSE / raises a runtime error. Check the WinCC diagnostic file WinCC_SStart_<...>.log and the APDiag output for the specific error code if the call fails.

Always trigger the segment change from a steady state (e.g., after the process is fully stopped) and not from a moving target such as a continuously changing tag. A second trigger within one cycle of the original may be ignored.

7. Configuration Reference: Archive Properties in WinCC V7

The following parameters control segmentation behavior. The names below are taken from the Archive Configuration dialog and match the descriptions in How to Configure Archive - WinCC V7.4.

Parameter Default Range / Type Effect on manual segment change
Archiving type Cyclic continuous Cyclic continuous / Cyclic selective / Acyclic / Event-controlled Set to Event-controlled for trigger-based, Acyclic for start/stop
Segment time 1 d 1 min - 365 d Forced rollover boundary independent of the trigger
Segment size 1 MB 10 KB - 1 GB Forced rollover on size; keep above expected run size to avoid mid-run rollover
Backup time Disabled 1 min - 365 d Forces a copy of the closed segment to the backup path
Event tag None BOOL / DWORD internal or external tag Edge here starts a new segment; rising/falling/both selectable
Start tag (acyclic) None BOOL Rising edge starts logging
Stop tag (acyclic) None BOOL Rising edge stops logging and closes the segment
Action on segment change None Function name (VBS / C) Optional: fire a function on every closed segment for export, copy, or notification

8. Configuring Archives in WinCC Professional (TIA Portal)

In TIA Portal the log settings are part of the HMI device and follow a different dialog flow.

  1. Open the HMI device > Runtime settings > Logging.
  2. Define the storage paths for the Fast and Slow data logs as described under Defining the Log Size and Segmentation (RT Professional).
  3. For each log, open Properties > Segment > Event and assign a Bool tag.
  4. Choose Single for one segment per trigger or Cyclic to also respect segment time / size.
  5. Compile the project and download. The runtime applies the configuration at next start.

9. Verification and Runtime Testing

After configuration, validate the segment change behavior on the engineering station or a test panel before going live.

  1. Activate the project in Runtime. Confirm the archive is logging by checking the active segment file timestamp.
  2. Trigger the event tag (set to 1, then back to 0 for a rising-edge evaluation). Wait for one full logging cycle.
  3. Inspect the archive directory. A new file with the next sequence number must appear; the previous file must be closed (size no longer changes).
  4. Open the closed segment with the WinCC archive viewer or export it to CSV. Confirm only the values up to the trigger are present.
  5. Repeat the trigger three times. Verify the sequence number increments by 1 each time and no gaps exist.
  6. If a backup path is configured, confirm the closed file is copied within the backup interval.
For RT Professional the segments are SQL Server Compact (SDF) databases; for verification, use the WinCC Runtime viewer or a third-party SDF reader such as SQL Compact Toolbox (offline analysis only).

10. Troubleshooting Matrix

Symptom Likely cause Diagnostic step Corrective action
Trigger tag toggles but no new segment is created Edge evaluation set to the wrong direction Open the archive properties and verify the edge setting Change to Rising edge if the operator sets 1 on start
Segment change happens continuously Trigger tag is a process value that oscillates Read the tag in the tag simulator Use a dedicated pulse tag driven by a button or PLC bit
Script returns FALSE / runtime error Archive name typo or archive disabled Check WinCC diagnostic log for error code (e.g., 0x80047200) Confirm archive name and re-enable the archive
Acyclic archive does not start on the rising edge Stop tag is already 1 when start becomes 1 Reset stop tag to 0 in the PLC before start Coordinate the start/stop logic in the PLC; use mutually exclusive flags
Disk fills up during a long process run Segment size too small; backup path not configured Check the archive directory size and the backup folder Increase segment size, enable backup, or move segments to a separate drive
Closed segment file is corrupt Power loss during write Inspect the .LOG / .RDB file headers Enable UPS for the HMI, force segment close on shutdown via the VBS OnError handler
Multiple operators trigger the same archive Trigger tag is shared without coordination Watch the trigger tag in the tag monitor Use a one-shot pulse (set/reset pattern) to avoid double-firing

11. Best Practices and Field Notes

  • Keep the trigger tag and the start/stop tags separate. A trigger tag fires once per command; a start/stop pair defines the active window. Mixing them causes undefined behavior.
  • Use a pulse of 2-3 logging cycles to guarantee detection. Some WinCC versions ignore pulses shorter than one cycle (e.g., 500 ms for TagLogging Fast).
  • Place the closed-segment backup on a network share and enable the backup time. This protects against disk failure on the panel.
  • When exporting, use the WinCC OLE DB provider or the Connectivity Pack; do not copy the RDB while it is open by Runtime. Schedule the copy after the segment close event.
  • Document the segment naming convention in the project (e.g., <ProcessName>_YYYYMMDD_HHMMSS) and rename segments on the trigger event via the "Action on segment change" hook. This is the only reliable way to bind the file name to the batch.
  • For TIA Portal projects, remember that RT Professional does not expose every archive API that V7 does. Prefer the configuration dialog (event tag, acyclic) over custom scripts when possible.

Can I trigger a segment change from a PLC tag in WinCC V7?

Yes. Configure an external binary tag from the PLC, then assign it as the Event tag on the archive properties. Set the edge to rising and confirm the trigger pattern in the PLC uses a one-shot pulse to avoid double-firing.

What is the difference between event-controlled and acyclic archiving?

Event-controlled archiving closes the current segment and starts a new one on a trigger edge while the archive keeps running. Acyclic archiving suspends the writer entirely; values are recorded only between a start edge and a stop edge. Use the combination for clean batch files.

Where are the closed segment files stored?

WinCC V7 stores segments as RDB files under the path configured in Computer > Properties > Storage path (default <ProjectPath>\ArchiveManager). WinCC Professional stores segments as SDF files under Runtime settings > Logging > Storage path.

Why does my segment change script return FALSE?

The archive name passed to TLGCreateSegment or HMIRuntime.Logging.CreateSegment must match the configured archive name exactly (case-sensitive). A disabled archive, a closed project, or a missing license also returns FALSE; check the WinCC diagnostic log for the underlying error code.

How do I bind the segment file name to the process run?

Use the "Action on segment change" hook in the archive properties to call a VBS or C function that renames the closed segment to a batch-specific name (e.g., Process_<BatchID>_<Timestamp>.RDB). In TIA Portal, the equivalent is the function list entry on the Segment Change event.

Back to blog