TP900 Comfort: Dynamic Recipe Export Filenames to Network Share

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

1. Problem Overview

Siemens SIMATIC TP900 Comfort panels (and the broader Comfort Panel family, 6AV2 124-1MC01-0AX0 and successors) ship with a recipe subsystem that supports exporting the currently loaded record set to CSV files via the ExportDataRecords system function. The default configuration writes the export to a fixed path and a fixed filename, which causes two field issues:

  1. Every export overwrites the previous file because the filename is constant (e.g. record.csv).
  2. The exported file does not identify which recipe it came from, so post-processing scripts cannot disambiguate records on the server side.

The desired behavior is a base path of \\network\logs\ combined with a recipe-specific filename, for example \\network\logs\Recipe_42.csv, sourced from an HMI tag that holds the current recipe name. This article documents the full configuration chain, the script-based workaround needed because the system function does not accept a runtime-built string directly from a button event, and the network/permissions prerequisites that frequently block the export silently.

Scope: This procedure applies to Comfort Panels (TP700 / TP900 / TP1200 / TP1500 / TP1900 / TP2200) and to the Multi Panel / RT Advanced PC runtime that share the same WinCC recipe engine. It is valid for TIA Portal V16 and later, including V17, V18, V19, and the V21 release documented in the Siemens TIA Portal Help.

2. Prerequisites

Item Requirement
HMI firmware WinCC Comfort V16 or later, image matching the TIA Portal version used for configuration
TIA Portal V16 / V17 / V18 / V19 / V21 (the V21 documentation is available at the Siemens TIA Portal V21 recipe import/export page)
Recipe data record At least one recipe configured under "Recipes" in the HMI project tree with the data record tag enabled
HMI tag for filename Internal WString or String tag, e.g. Sname, writable from PLC or script
Network share Windows SMB share reachable from the panel, with a UNC path (\\server\share\folder) — drive-letter mappings are not supported on Comfort Panels
Account User credentials that the panel runtime can supply to authenticate against the share (configured in the panel's Network & Identity settings)
UNC paths only. Comfort Panels do not support mapped drive letters (Z:\). The runtime resolves paths strictly via UNC, so the source pattern \network\logs\record.csv shown in the question is interpreted as a relative path. Use \\server\share\logs\record.csv or an absolute path that begins with \\.

3. Anatomy of ExportDataRecords

The ExportDataRecords system function is one of the documented recipe operations in the Comfort Panel programming reference. Its signature in TIA Portal exposes three input parameters visible in the configuration dialog:

Parameter Type in dialog Runtime meaning
Name String (default) or HMI_Tag Target file name including extension. Selecting the down-arrow toggles the source between a literal string and an HMI tag.
Path String (default) or HMI_Tag Target directory (UNC). The default is the local \Storage Card\ on a TP900.
Overwrite Boolean If false, the function fails when the target file already exists; if true, it overwrites silently. Default is true.

The dialog accepts a literal string or an HMI tag for each parameter, but it does not accept a string expression. This is the architectural reason that a button event cannot directly pass "\\network\logs\" & Sname & ".csv": the system function expects either a constant or the full content of a tag, not a concatenation result. The accepted engineering pattern is therefore to pre-assemble the complete path into a single HMI tag before calling the system function, and select that tag as the Name source.

4. Configuring the Filename HMI Tag

  1. In the project tree, open HMI Tags → Default tag table.
  2. Add a new tag. Name it Sname (or any identifier consistent with your project).
  3. Set Data type to WString[254] — Windows-style strings are required for UNC paths; String is acceptable for short recipe names but offers no Unicode support.
  4. Set Length to a value that accommodates the full path. For a 64-character path plus 64-character recipe name, WString[254] is a safe ceiling.
  5. Set Acquisition mode to Cyclic continuous if the PLC will write the recipe name continuously, or leave as On demand if the script will populate it.
  6. Add a second tag Spath with the same data type to hold the fully assembled path string \\server\logs\Sname.csv.

5. Building the Path String

Two patterns are field-proven. The first writes the recipe name to Sname and concatenates a constant base path on the panel side. The second computes the full path in the PLC and writes the result to Spath directly.

5.1 PLC-side concatenation (S7-1200 / S7-1500)

Use the Siemens standard CONCAT string functions. In SCL:

// Inputs
VAR_INPUT
    iRecipeName : String;   // e.g. 'Recipe_42'
END_VAR

VAR_TEMP
    tBase : String := '\\\\server\\logs\\';
    tExt  : String := '.csv';
END_VAR

// Build path into Sname (WString-compatible via implicit conversion on the HMI tag)
Sname := CONCAT(IN1 := CONCAT(IN1 := tBase, IN2 := iRecipeName), IN2 := tExt);

The four-character sequence \\\\ in a string literal represents two literal backslashes when the panel runtime receives the string, producing a valid UNC prefix.

5.2 HMI-script-side concatenation (VBScript on the panel)

Comfort Panels support VBScript inside scheduled tasks and as the action of an event. The script below can be assigned to a button's Press event directly:

Dim base, ext, full
base = "\\\\server\logs\\"
ext  = ".csv"

' Read recipe name from HMI tag
Dim sName
sName = SmartTags("Sname")

' Build the full path
full = base & sName & ext

' Write to the HMI tag consumed by ExportDataRecords
SmartTags("Spath") = full

' Now invoke the system function
SmartTags("RecipeExportTrigger") = True

The RecipeExportTrigger tag is a Boolean wired to a second event on the same button (or a separate button) that calls ExportDataRecords with Name = HMI_Tag bound to Spath. This indirection is required because TIA Portal does not allow a button event to call a system function with a tag value that was just modified in the same handler — the value is read at compile time of the call.

6. Avoiding Overwrites

Even with a unique recipe name, two consecutive exports of the same recipe will collide. The engineering solutions, in order of preference:

  1. Disable overwrite. In the ExportDataRecords dialog, set the Overwrite parameter to false. The function will then return an error if the file exists, which can be caught and presented to the operator.
  2. Append a timestamp. Build the filename as Sname & "_" & FormatDateTime(Now, "yyyymmdd_hhnnss") & ".csv". The Now() function is available in the panel's VBScript environment and returns the panel's local time.
  3. Append a sequence number from the PLC. Maintain a counter in the PLC and concatenate it. Less elegant but deterministic, which simplifies downstream audit trails.

For a regulated batch environment, combine approaches 1 and 2: disable overwrite and also include a millisecond counter or PLC-side monotonic timestamp to guarantee uniqueness even if the operator double-taps the export button within the same second.

7. Network Share and Permission Setup

The most common field failure for recipe export to a network share is not the HMI logic — it is the SMB / authentication layer. Apply the following checklist:

  1. Create the share on the Windows host, e.g. \\SERVER\RecipeLogs.
  2. Grant Modify (not just Read & Execute) to the user account the panel will authenticate as. Modify is required because ExportDataRecords creates a new file; read-only shares will return an ERROR_ACCESS_DENIED in the panel's log.
  3. Set NTFS permissions matching the share permissions. A common error is granting Share-level access while the folder's Security tab denies write.
  4. Configure the panel's network identity: in the panel project, Devices & Networks → select the HMI → Properties → Network & Identity. Enable User authentication and enter the domain account, e.g. DOMAIN\hmi-service. The password is supplied through ProSave or the configuration download.
  5. Verify DNS resolution from the panel: open the panel's Control Panel → Network & Dial-Up Connections and ping the server. The ping tool on WinCE-based Comfort Panels uses ICMP and will report host resolution failures.
  6. Disable SMBv1 on the server if you are running a modern Windows host. Comfort Panels default to SMBv2; mismatched protocol versions cause STATUS_BAD_NETWORK_NAME errors logged as event 14 in the HMI diagnostic buffer.
Security note. The username and password for share access are stored in the panel project and downloaded with the runtime. Anyone with physical access to the panel configuration download (ProSave) can extract them. For a production system, segregate the share to a service account with write-only access to a specific folder, and apply Windows audit logging to detect bulk reads.

8. Verification Procedure

  1. Compile and download the panel project to the TP900.
  2. On the operator screen, load a recipe (e.g. Recipe_42).
  3. Press the export button. Watch the Spath tag online value through TIA Portal's Online & Diagnostics view; it should read \\SERVER\RecipeLogs\Recipe_42.csv immediately before the export.
  4. On the Windows server, open the RecipeLogs folder and confirm the file appears with a recent timestamp.
  5. Load a different recipe (e.g. Recipe_43), repeat the export, and confirm a separate file is created.
  6. Export Recipe_42 again with Overwrite disabled. The export should fail with a system event and the operator should see a configured alarm message.

For a scripted timestamp variant, also confirm by exporting the same recipe twice within one second: two distinct files should exist on the share.

9. Diagnostic Buffer Codes

WinCC Comfort logs recipe and file-system errors into the panel's diagnostic buffer. The most common codes and their meanings:

Event ID Meaning Likely cause
14 Network path not found DNS, routing, or UNC syntax error; \\ collapsed to \
15 Authentication failed Wrong credentials, expired password, SMBv1/v2 mismatch
22 Path not accessible Path exists but the configured user has no write permission
14001-14003 Recipe system internal error Recipe not loaded, no active data record, or tag binding mismatch
0x80070005 Access denied (Windows native code) NTFS read-only, share permission set to Read
0x80070050 File exists (overwrite disabled) Expected when using the anti-overwrite pattern from §6.1

Open the diagnostic buffer via the panel's Control Panel → OP → System Properties → Device Status → Diagnostic Buffer, or remotely via ProSave's Backup / Restore view with the panel in transfer mode.

10. Troubleshooting Matrix

Symptom Likely root cause Fix
File always named record.csv Literal string in Name field, not HMI_Tag Press the down-arrow in the dialog and select the Spath tag
Export produces no file and no error Button event runs script that writes tag, but the system function was already bound at compile time Use the two-event pattern from §5.2 (script + trigger tag)
File appears on local \Storage Card\ Path is treated as relative, not UNC Prefix with \\ and use a fully qualified host name
Export fails on first run after panel reboot Network stack not yet up when the user presses the button Add a startup script that pings the server; gate the export button on a network-ready HMI tag
Concatenation drops characters Target tag length too short, or PLC string type limited to 254 chars Use WString[254] on the HMI side, String on the PLC side, and validate length in the script
Overwrite silently happens Overwrite parameter defaulted to true Explicitly set to false; combine with timestamp for guaranteed uniqueness

11. Advanced: Triggering Export from the PLC

To avoid a script on the panel entirely, the PLC can write Spath directly and a single area pointer or scheduler event on the panel can detect the change. The pattern is:

  1. PLC writes the assembled path to Spath (HMI tag, WString).
  2. PLC sets ExportTrigger (HMI tag, Bool) to true for one cycle.
  3. A scheduled task on the panel polls ExportTrigger every 200 ms. On a rising edge, it calls ExportDataRecords with the Name parameter set to HMI_Tag bound to Spath.
  4. Reset ExportTrigger from the PLC after a 500 ms delay, or from the panel script after a successful return code.

This pattern is more deterministic than a button event and is the recommended approach for production lines where the export is part of a batch end-of-step sequence.

12. Related Recipe Operations

Once ExportDataRecords is working, the mirror operation ImportDataRecords follows the same parameter logic: the Name can be bound to an HMI tag, allowing the PLC to select which CSV to load by writing the path to the tag. The Siemens TIA Portal V21 documentation lists the full matrix of import / export / clear / load / save system functions, and is the authoritative reference for the dialog parameter semantics used in this article.

Why is my exported CSV always named record.csv even though I set the HMI tag?

The Name field in the ExportDataRecords dialog is still a literal string. Click the down-arrow button on the right of the Name input and switch the source type to HMI_Tag, then select the Spath tag. Recompile and download for the change to take effect.

Can I use a relative path like \network\logs\ on a TP900 Comfort?

No. Comfort Panels resolve export paths as UNC only; a single-backslash path is interpreted relative to the local storage card and silently writes to \Storage Card\network\logs\. Use a fully qualified UNC path such as \\server\share\logs\.

How do I prevent the panel from overwriting an existing file?

Open the ExportDataRecords configuration, expand the Overwrite parameter, and uncheck it. If the file exists the function will return an error; handle that in the operator alarm system. For guaranteed uniqueness on repeated exports, append a timestamp to the filename in the assembly script.

Why does the export fail with a permission error on a share I can browse from my PC?

Your PC authenticates with your personal credentials. The panel authenticates with the service account configured in Network & Identity. Verify the service account has Modify share permission and Write NTFS permission on the target folder, and that SMB signing / protocol version is compatible between the panel and the server.

Can the PLC trigger the export without a script on the panel?

Yes. The PLC writes the assembled path to the Spath HMI tag and pulses an ExportTrigger Bool. A scheduled task on the panel runs every 200 ms, detects the rising edge, and calls ExportDataRecords with Name bound to the Spath tag. This is the cleanest production pattern.

Back to blog