Printing the Last Alarm Only in WinCC Flexible HMI Reports

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

Overview

Siemens WinCC Flexible (and its successor TIA Portal WinCC) provides three independent mechanisms for alarm logging and reporting: an alarm buffer with class-based routing, a per-alarm protocol/print flag that triggers an immediate report entry, and a parameter-driven report with date/time range filtering. Operators who only need the last alarm that fired - for example, to send a single line to a line printer or a serial ticket printer - typically combine the per-alarm flag with a scheduled print job. Engineers who need last-alarm-on-demand usually pair a tag-edge trigger with the report's range parameters.

This article documents all three production techniques, the configuration dialogs, the VBScript glue used in the field, and the verification steps that prove only the most recent event is being printed. It is targeted at WinCC Flexible 2008 SP5 and at the equivalent TIA Portal WinCC Comfort/Advanced runtime, where the property names differ slightly.

Terminology: In Italian-localized WinCC Flexible builds, protocollo translates to "report" or "logging protocol", not the printing protocol stack. The relevant runtime object is the alarm logging buffer and the AlarmReport report template. This article uses the English property names that appear in WinCC Flexible 2008 and TIA Portal V16+.

Prerequisites

  • WinCC Flexible 2008 SP5 (or TIA Portal V16+ with WinCC Comfort/Advanced) installed on the engineering station.
  • A configured HMI connection to the target panel (KTP1200, TP1500, MP277, or a WinCC Runtime Professional PC).
  • Alarm classes created in the project tree under HMI Tags > Alarm Logging or Alarms.
  • A report template in the Reports editor containing the Alarm Logging Report layout object.
  • For script-based methods, enable Settings > Runtime Settings > Scripts > Use VBScript.
  • Print destination configured under Project > Printer Setup (local, network, or file printer writing to a PDF share).

Method 1: Per-Alarm Automatic Protocol Print (Default Flag)

The simplest method - and the one recommended by Siemens technical support for "I just want the last alarm" use cases - is to enable the Protocol column on every discrete alarm. When the bit assigned to the alarm transitions active, the runtime appends a single line to the configured report and sends it to the print destination. Because the runtime processes the alarm as a single record (one trigger = one print line), only the most recent event appears in the output buffer, even if older alarms are still in the alarm window.

  1. Open the project in WinCC Flexible and select Alarms > Discrete Alarms (or Alarm Logging in TIA Portal).
  2. Right-click any column header and choose Show/Hide Columns > Protocol (Italian: Protocollo). Confirm the column is visible.
  3. Set the Protocol cell of every alarm you want to log to Yes. Default in fresh projects is No.
  4. Verify the global switch: Project > Properties > Alarm Logging > Use protocol must be enabled. WinCC Flexible creates this flag with default Yes, but locked projects sometimes disable it.
  5. Assign the print destination: open Reports > Alarm Logging Report, on the General tab select the printer set under Project > Printer Setup.
  6. Compile and download to the panel. Each new alarm generates one printed line.

Reference the procedure in the WinCC Flexible 2008 System Manual under chapter "Configuring Alarm Logging".

What gets printed

Position Field Source
1 Alarm number Sequential ID assigned by the compiler
2 Date (DD.MM.YYYY) Panel RTC
3 Time (HH:MM:SS) Panel RTC
4 Status Came In / Went Out / Acknowledged
5 Alarm class Error / Warning / Information
6 Alarm text Multilingual text configured in the alarm
The per-alarm protocol line is not freely configurable in WinCC Flexible 2008. If you need a custom layout (drop the alarm number or append a tag value), use Method 2 or Method 3.

Method 2: Date/Time Range Filtering on a Triggered Report

When the report must contain a user-defined layout, schedule the print job from a tag-edge trigger and pass a one-second Start / End window to the report's range parameters. The runtime evaluates the alarms whose TimeStamp lies inside the window and prints only those - typically exactly one record per trigger.

  1. Create a report (e.g., LastAlarmReport) in the Reports editor. Insert an Alarm Logging Report layout object.
  2. Open the report's Properties > Range tab. Bind the four parameters to internal tags:
Range Parameter Internal Tag Data Type
Start Date LastAlarmStartDate Date
Start Time LastAlarmStartTime Time_Of_Day
End Date LastAlarmEndDate Date
End Time LastAlarmEndTime Time_Of_Day
  1. Create a tag LastAlarmTrigger of type Bool and tie it to the same word/bit the alarm uses. In the alarm's Trigger tab add a tag change event that sets a "print pending" flag.
  2. Add a VBScript function that captures the moment the alarm word changes and writes a one-second window around that timestamp:
' Triggered on edge of the alarm word (WinCC Flexible 2008)
Sub OnAlarmWordChange(ByVal newValue)
    Dim tNow, dNow
    tNow = Time            ' Time_Of_Day
    dNow = Date            ' Date
    SmartTags("LastAlarmStartDate") = dNow
    SmartTags("LastAlarmStartTime") = tNow
    SmartTags("LastAlarmEndDate")   = dNow
    SmartTags("LastAlarmEndTime")   = DateAdd("s", 1, tNow)
    ' Edge-trigger the print job
    SmartTags("LastAlarmTrigger") = True
End Sub
  1. Schedule the report: Reports > LastAlarmReport > Properties > Print Job > Trigger, bind to LastAlarmTrigger = 1. The runtime re-evaluates the range parameters on every trigger.
  2. Reset LastAlarmTrigger to 0 in the same script after a 200 ms delay (use a cyclic scheduler) so the next alarm can re-trigger the print.

Sample printer output (file printer, one record per alarm)

17.06.2025  14:23:11.421  +  Error    1042  Press_101: Hydraulic low pressure
17.06.2025  14:24:02.118  +  Error    1043  Press_101: Motor overload
17.06.2025  14:25:48.502  +  Warning  2017  Oven_3:    Zone B temperature drift

Each line is a discrete print event. The full alarm window continues to scroll independently; only the printed subset is filtered through the range. See the TIA Portal WinCC Professional Documentation, section "Reports with Parameter Sets", for the modern equivalent.

Method 3: Scripted Direct Print (No Alarm Logging Object)

For panels without an alarm logging license, or when the printed record must include computed values (e.g., a measured value at the moment the alarm fired), call the report from a VBScript and format the line manually through a file-printer share.

  1. Map a network share on the panel as \\fileserv\HMI_Logs\LastAlarm.txt using the Printer Setup > File Printer dialog.
  2. From the alarm's Events > Change Value action, call a global VBScript that writes a CSV record to a buffer tag, then prints the buffer with HMIRuntime.PrintReport.
  3. The print is performed with the Print Report system function. Pass the report name "LastAlarmReport" and a hard-coded printer name (e.g., "LinePrinter01").
' WinCC Flexible / TIA Portal V16+ VBScript
Sub PrintLastAlarm(ByVal alarmNumber, ByVal alarmText, ByVal severity)
    Dim outLine
    outLine = Now & ";" & severity & ";" & alarmNumber & ";" & alarmText
    ' Append to a rolling buffer tag (string)
    SmartTags("PrintBuffer") = outLine & vbCrLf & SmartTags("PrintBuffer")
    If Len(SmartTags("PrintBuffer")) > 4096 Then
        SmartTags("PrintBuffer") = Left(SmartTags("PrintBuffer"), 4096)
    End If
    ' Trigger a tiny report that prints only PrintBuffer via a Text object
    HMIRuntime.PrintReport "LastAlarmReport", "LinePrinter01"
End Sub
The PrintReport call is synchronous on Comfort Panels and asynchronous on WinCC Runtime Professional. Wrap it in an error handler to avoid blocking the alarm scheduler on a stalled printer.

Verification

  1. Force-trigger three discrete alarms within 10 seconds (toggle the HMI tag from PLCSIM or the tag simulator).
  2. Confirm that exactly three lines were emitted to the configured printer queue. Use the panel's Control Panel > Print Queue on Windows CE / Windows Embedded targets, or the spooler net print on PC runtimes.
  3. Open the alarm window on the panel. Verify all three alarms are still visible in the scrolling buffer; printing does not remove them.
  4. With the printer offline, force a fourth alarm. The runtime should buffer the print job (up to 64 events on a TP1500, more on Runtime Advanced) and flush once the printer is reachable.
  5. Capture a screenshot of Reports > Alarm Logging Report > Properties > Range showing the bound tags. Save with the project archive for audit traceability.

Troubleshooting Matrix

Symptom Likely Cause Fix
No print at all Use protocol flag disabled at project level Project > Properties > Alarm Logging > Use protocol = Yes
Entire alarm history prints Per-alarm Protocol column = No on every alarm but Print On Change selected on the report Set the column to Yes on the discrete alarms only, or set the report trigger to "On Tag Change" with a one-second range
Old alarm reprinted on new event Range end time is 00:00:00 when start time is past midnight Use DateAdd("h", 24, ...) rollover, or bind End Time to a moving now + 2 s tag
Print shows alarm number "0" Alarm text is empty; runtime fills with a placeholder Assign alarm text in every language; check the Multilingual editor for missing entries
Printer jams the alarm scheduler Synchronous print on a slow serial printer Switch to a network printer and add a 200 ms post-trigger delay
Translated "protocollo" lost in runtime Language switch removed the alarm text Re-export the text library and re-download the project
Time stamp off by one hour DST transition during a long-running panel Enable Automatic daylight saving in the panel's regional settings; reboot runtime
Print job printed twice Trigger tag is a BOOL and script re-fires on the same rising edge Use a one-shot edge detector with a 500 ms lockout in the cyclic scheduler

Migration to TIA Portal WinCC

WinCC Flexible 2008 projects migrate to TIA Portal through the Migration > Migrate Project wizard. The alarm logging configuration transfers intact, but the property names change:

WinCC Flexible 2008 TIA Portal V16+
Discrete Alarms > Protocol column Alarms > Properties > Logs > "Log" checkbox
Reports > Range > Start Date / Time Report > Properties > Parameter Set > Filter > Time range
HMIRuntime.PrintReport HMIRuntime.Print
SmartTags() SmartTags()
Time/Date system functions Same, but tag types are now DTL for combined date/time

After migration, re-bind the four range tags because the parameter set editor regenerates internal names. Re-test the trigger edge with the new Tag change event model introduced in TIA Portal V14 SP1. The migration procedure is documented in the TIA Portal WinCC Commissioning Manual.

Performance and Sizing

On a Comfort Panel (TP700 / TP1500) the alarm logging buffer holds 1024 entries by default. Increasing the buffer above 4096 events requires expanding the persistent storage partition. The per-alarm print path adds approximately 8 ms of runtime latency on a TP1500; the range-filtered report path adds 25-40 ms. For alarm rates above 1 event per second, prefer Method 1 (per-alarm flag) and disable the alarm window refresh to avoid UI stalls.

For PC-based runtimes (WinCC Runtime Professional), the alarm logging database uses Microsoft SQL Server Express by default. A 2 GB database holds approximately 5 million alarm records. The per-alarm print throughput is bounded by the spooler, not the database. Print delivery itself can use the LPR, IPP, or SMB transports catalogued in the list of printing protocols, but the choice of transport is configured in the printer driver, not in the WinCC report.

Edge Cases and Field-Proven Caveats

  • Midnight rollover: The End Date tag must advance with the Start Date when the script fires within the last second of the day. A common fix is to compute EndDate = IIf(StartTime > "23:59:59", DateAdd("d", 1, StartDate), StartDate).
  • Burst suppression: A real PLC fault can fire the same alarm word 50 times in 200 ms. Add a debounce of 250 ms in the VBScript before re-arming the trigger tag.
  • Multi-language plants: The print line uses the currently selected runtime language. If the alarm text in the active language is empty, the runtime falls back to the project default. Audit the multilingual text library before each FAT.
  • Power loss: Comfort Panels with a UPS option queue up to 32 print events in non-volatile memory. After recovery, the events flush in arrival order - not in the original timestamp order - which can cause a "stale" last-alarm printout. Plan a clear buffer procedure on power-up.
  • Print spooler saturation: A jammed ticket printer on a serial port holds the PrintReport call indefinitely on Comfort Panels. The scheduler cannot fire the next alarm until the call returns. Move the printer to the network or use a file-printer share.

Related Platforms: AVEVA InTouch Reference

The "print only the latest event" pattern is not unique to Siemens. AVEVA InTouch Alarm Printer ships a similar utility that streams alarms from a node's alarm memory to a printer on an event-by-event basis. AVEVA uses a circular buffer in memory and forwards only the new entries since the last poll. The conceptual mapping to WinCC Flexible is: the alarm window buffer is the source, the per-alarm Protocol flag is the forwarding rule, and the print job is the destination. Engineers familiar with InTouch can apply the same three-tier separation of concerns to WinCC.

Standards Context

Alarm handling in WinCC is not directly governed by IEC 61131-3; the standard covers PLC programs, not HMI reporting. The report column layout follows the conventions used in the broader printing-protocol ecosystem, documented in the Microsoft Print Services Protocols Overview (MS-PR SOD), which covers the SMB and IPP transports that the optional network printer driver on PC-based runtimes uses. The general classification of "protocol" in the WinCC context (a row of structured fields, not a network protocol) is consistent with the list of printing protocols maintained as a public reference.

FAQ

How do I print only the most recent alarm in WinCC Flexible?

Enable the Protocol column on each discrete alarm (Alarms > Discrete Alarms > right-click header > Show/Hide Columns > Protocol) and set it to Yes. The runtime prints one line per alarm transition, so only the last event is added to the print buffer at any given moment.

Can I filter the alarm report by date and time range?

Yes. Open the report's Properties > Range tab and bind the four parameters (Start Date, Start Time, End Date, End Time) to internal tags. A VBScript triggered by the alarm word change can write a one-second window around the event time before the print job is fired.

Why does the printed line include the alarm number even though I do not need it?

WinCC Flexible 2008's built-in alarm logging report template is not editable. To drop the number, build a custom report (Method 2 or 3) and pass only the fields you want to a Text object bound to a buffer tag.

Does the per-alarm print also write to the alarm window?

Yes. The alarm window is independent of the print path. All active and historical alarms remain visible in the panel UI; the print job is a parallel output. To suppress alarms from the window, change the alarm class to "System" and uncheck "Display in Alarm Window".

How does this change when I migrate from WinCC Flexible to TIA Portal?

The Protocol column becomes the Log checkbox in TIA Portal. HMIRuntime.PrintReport is replaced by HMIRuntime.Print, and the report range parameters are exposed under Parameter Set > Filter > Time range. Re-bind the four range tags after migration and re-test the trigger edge.

What printer transport should I use for reliable alarm printing?

Use a network printer over IPP or SMB (catalogued in the public list of printing protocols) rather than a serial port. Serial printers can hold the synchronous PrintReport call open, blocking the alarm scheduler. File printers writing to a network share are the most resilient choice for unattended panels.

Back to blog