Overview: The Trace Data Lock-In Problem
The SIMATIC S7-1500 trace function (and the equivalent trace object on the S7-1200 G2 controller) records cyclic CPU signals against a configurable trigger, sampling tag values, edge counters, and computed expressions into an internal ring buffer. By default, that measurement buffer is exposed only inside the TIA Portal project tree (Project Navigation → Traces → <trace_name> → Measurement) and cannot be opened as a standalone file format (.csv, .csvz, .xml) by any third-party tooling.
Siemens' official documentation states that the trace measurement data is available only within the TIA Portal project and is not available for processing by other tools (see the SIMATIC S7-1200 G2 Tracing and Recording CPU Data entry in the Fail-Safe Modules Manual Collection). This forces every engineer who needs to perform post-mortem diagnostics on a machine that does not have TIA installed to either install the engineering suite or build a side-channel data acquisition path. The remainder of this reference covers the supported, semi-supported, and field-proven workarounds for that scenario, including the constraints, register/parameter settings, and verification steps required for each path.
Prerequisites and Required Firmware
Workarounds below assume an S7-1500 CPU (or ET 200SP CPU, S7-1500 Software Controller) with the minimum firmware levels shown in the table. Trace functionality and the web server page structure have evolved across firmware versions; verify the CPU's firmware before committing to a method.
| Feature | Minimum Firmware (S7-1500) | Notes |
|---|---|---|
| Trace function (basic) | V1.5 (FW 1.5.x) | Up to 16 signals per trace on early versions |
| Trace recording to memory card | V2.0 (FW 2.0.x) | Required for the memory-card export path |
| Web server: trace view | V2.0 (FW 2.0.x) | HTML pages expose the trace buffer in JSON-compatible form |
| OPC UA server (CPU-side) | V1.7+ | Compact server on ET200SP; full server on S7-1515/1516+ |
| Open User Communication (OUC) TSEND/TRCV | V1.0 | Always available on S7-1500 |
| DataLog (file-based logging) | V2.0+ | Persistent .csv on SIMATIC memory card |
curl against the page will not return numeric samples; you must use a headless browser, a session-aware HTTP client, or a SCADA/HMI that can read the trace JSON. Treat the web server as a *view*, not a clean data export.Method 1: Web Server Memory-Card Storage + Session Scraping
The only Siemens-shipped path that gives you a persistent, *file-system* copy of a trace is the combination of "Save trace to memory card" (configured in the trace object properties under Recording → Storage) plus the CPU's integrated web server. Once both are configured and a recording has completed, the trace is stored in the binary file /card/user/sinumerik/.../trace/ on the SIMATIC memory card and mirrored in the web server's diagnostic pages.
- Enable the web server in TIA Portal: Properties → CPU → Web server → Activate web server on this module. Set a username/password and the access level to Diagnostics or higher. The minimum access level for trace viewing is Diagnostics; writing trace configurations via the web requires Administration (HMI access level 1+).
- In the trace configuration, open Properties → Recording → Storage location and select Memory card (CPU storage). Set the maximum number of recordings to retain (1-10) and the recording mode (single, cyclic, or appending).
- Trigger the recording from a test function or a real process event. After the recording is complete, the trace appears at the bottom of the web server navigation under Diagnostics → Trace.
- Browse to
http://<cpu-ip>/Portal/Portal.mwsl?Pri=diag&trc=1(or the equivalent/Trace/Trace_1URL exposed by the firmware). Use a headless browser to capture the rendered DOM. Chromium-based tools (Puppeteer, Playwright, Selenium) handle the JavaScript-rendered chart automatically. - Parse the JSON record embedded in the page source. The S7-1500 web server typically renders the trace as a structured object under a key such as
window.s7TraceDataor a WebSocket subscription; inspect the page in DevTools first to confirm the key, then extract. - Write the resulting array to a
.csvwith one column per signal and ats_mstime column derived from the trace's sample period.
Verification (Web Server Method)
After the recording has been triggered and the trace is complete:
- Confirm the trace is present via the web UI: Diagnostics → Trace → <trace_name> should show a non-empty chart.
- Confirm the memory card file exists by logging into the CPU via SFTP/FTP (CPU FW 2.6+) or by exporting the trace from the SD card reader in TIA Portal — the binary file should match the SHA-256 hash shown in the web UI's Properties dialog.
- Cross-check the first and last sample values against the live tag values in the HMI to confirm the time base is correct.
Method 2: DataLog File-Based Logging (Closest Native Substitute)
If you control the program (rather than the diagnostic environment), the cleanest alternative to a TIA trace is a DataLog. A DataLog writes a cyclic set of tag values to a .csv-style binary file on the memory card that any PC application can read directly. It does not require the CPU to be online with TIA at all — the file is accessible by removing the memory card or by mounting the card over the web server's file browser (CPU FW 2.6+).
- Insert a
DataLogCreateinstruction in the program. TheREQinput should pulse on first scan or on a restart event. TheNAMEparameter is the file name (e.g.,'MOTOR_RAIL_LOG');IDmust be a unique handle per data log. - Define the data structure:
DataLogCreateaccepts anRECORDinput of type_DLOG_DATAwith up to 254 elements. Each element is a tag name, data type, and a column header string. Use a PLC data type (UDT) for repeatability. - Call
DataLogWriteon the cyclic task (e.g., the same OB1 cycle the trace would have sampled at). SetWRITE_LENto the number of records per write, typically 1. - Trigger the data log to close on a fault:
DataLogCloseis called from an error OB, a watchdog trigger, or a manual HMI button. - Read the resulting file from the memory card. The file is located at
/DataLogs/<NAME>.csvon the SIMATIC memory card and is plain ASCII/UTF-8.
DataLog Parameter Reference
| Parameter | Type | Description |
|---|---|---|
REQ |
BOOL | Create request; pulse only on rising edge to avoid overwriting. |
NAME |
STRING[128] | File name without extension. Becomes the file's stem on the memory card. |
ID |
DWORD | Internal handle. Must be unique per DataLog; track in a global array. |
RECORD |
Variant / UDT | Pointer to the data record whose tags will be logged. |
HEADER |
STRING[] | Optional human-readable header. Visible in the .csv row 1. |
STATUS |
WORD | Return code. 0x0000 on success, 0x801E on out-of-memory. |
Method 3: Open User Communication (OUC) Streaming via TCP
When the data is required *in real time* on a PC that has no TIA Portal, Open User Communication (OUC) on the S7-1500 side plus a lightweight TCP listener on the PC is the most flexible path. OUC supports TCP, UDP, and ISO-on-TCP. For periodic encoder or signal data, TCP with a fixed receive buffer is the simplest protocol to implement on both ends.
- Configure the
TSEND_Cinstruction in the program. SetCONNECTto a TCON_Param variant populated with the PC's IP address, remote port (e.g.,2500), and the local connection ID. - On the PC, open a TCP listener — for example a Python
socket.socket(socket.AF_INET, socket.SOCK_STREAM)bound to0.0.0.0:2500. Accept the connection and read frames until EOF or a sentinel. - Use a pre-agreed framing protocol. A 4-byte little-endian length prefix followed by the payload is robust and easy to parse in any language. The S7-side sender packages the data into a fixed layout:
LEN (4 bytes) | TIMESTAMP (8 bytes, ms since CPU start) | SIGNAL_0 (4 bytes) | SIGNAL_1 (4 bytes) | ... | CRC16 (2 bytes). - On the S7 side, send the data from a cyclic OB (OB30 at 100 ms is a common choice for fault diagnostics). Be aware of cycle-time impact: each
TSEND_Ccall is non-blocking whenCONT=1and will reuse the same connection for subsequent sends. - On the PC, write received frames to a SQLite database or a flat file. SQLite is preferred for fast query over long recordings:
CREATE TABLE samples (ts_ms INTEGER, s0 REAL, s1 REAL, ...);
Sample SCL Snippet (OUC Sender)
// S7-1500 SCL: send a fixed-layout frame on a 100 ms cyclic task
#iTSendBusy := FALSE;
IF #tCON.Established THEN
"dataBlock".frame := #iLengthPrefix + #iTimestamp + "dataBlock".signals;
TSEND_C(
REQ := TRUE,
CONT := TRUE,
LEN := "dataBlock".frameLength,
DATA := "dataBlock".frame,
CONNECT := "dataBlock".connection,
BUSY => #iTSendBusy,
DONE => #iTSendDone,
ERROR => #iTSendError,
STATUS => #iTSendStatus
);
END_IF;
Verification (OUC)
- Confirm the TCP socket is open:
ss -tnp | grep 2500on the PC. - Confirm the S7 connection is established in Online & Diagnostics → Diagnostics → Connection statistics; the
TSEND_C.STATUSshould report0x0000. - Confirm the sample rate matches the cyclic OB period: 100 ms of data should produce exactly 10 samples per second per signal; verify with a one-minute test recording and a histogram of the deltas.
Method 4: OPC UA Subscribe-and-Dump
The S7-1500 OPC UA server (FW 1.7+ ships a Compact server on most CPU variants, FW 2.5+ ships the full server) exposes the same tags that the trace would sample. Any OPC UA client — open62541, Prosys, the open-source asyncua Python library — can subscribe to the tags, store the values in a local database, and emulate the trace's behavior without the trace object at all.
- Activate the OPC UA server in TIA Portal: Properties → CPU → OPC UA → Activate OPC UA Server. Set the security policy (None is acceptable for a local diagnostic VLAN; Basic128Rsa15 or Basic256Sha256 is required for production).
- Apply the PLC tag access rights so the required tags are readable. Drag the tags to the OPC UA Server Interface list in the project tree.
- On the PC, install an OPC UA client. The Python library
asyncuais the lowest-friction option; the C# OPC Foundation SDK is the highest-performance option. - Subscribe to the tag set with a publishing interval of 100 ms (or the same sample period the trace would have used). Set
monitoredItemCountto the number of signals. Store each notification tuple in a local file. - At the end of the recording session, dump the file to a
.csv. The CSV layout will match the structure used by the trace's Export → CSV menu in TIA Portal, allowing downstream tools that expect a TIA-trace format to read the file with no further conversion.
Method Comparison Matrix
| Method | Real-time | Post-mortem | Requires TIA for config | Sample rate | File format | Effort |
|---|---|---|---|---|---|---|
| Web server + scraper | No | Yes | Yes (initial) | Trace rate | JS DOM → CSV | High |
| DataLog (file) | No | Yes | Yes (program) | Cyclic task rate | .csv (native) | Low |
| OUC / TCP streaming | Yes | Yes | Yes (program) | OUC call rate | Custom frame | Medium |
| OPC UA subscribe | Yes | Yes | Yes (config) | Publish interval | Custom → CSV | Medium |
Workaround Matrix for the "Trace Only in TIA" Constraint
| Scenario | Recommended workaround | Why |
|---|---|---|
| Customer refuses TIA installation; diagnostic only | Web server scraper (Method 1) | No new program code; only post-event analysis. |
| New project; you control the program | DataLog (Method 2) | Cleanest output; native .csv; no third-party tooling. |
| Existing program, real-time visualization needed | OPC UA (Method 4) | Standardized protocol; works with any SCADA/HMI. |
| Custom protocol, high-rate encoder data, no TIA at site | OUC / TCP (Method 3) | Lowest latency; full control of the frame layout. |
| Field service, no network, no TIA | DataLog + memory card swap | Pull the SD card; read .csv on a laptop. |
Limitations, Edge Cases, and Safety
- Web server session lifetime: TIA Portal logs the web user out after 15 minutes of inactivity by default. Headless browser scripts must keep the session alive (poll a non-mutating endpoint every < 15 min) or re-authenticate before each scrape.
- Memory card wear: Cyclic DataLog writes on a 10 ms task will wear out consumer-grade SD cards in weeks. Specify a Siemens SIMATIC Memory Card (S7-1500 ships 24 MB and up) and use a Write-protected setting if the application is read-only.
-
Time stamping consistency: The S7-1500 internal time is the
CPU clock; for cross-controller correlation, use the Time synchronization function (NTP) and a 1 ms-resolution time source. Avoid the legacy "Time-of-day" tags from S7-300/400 era code. - OPC UA security: Never ship a production CPU with the Security Policy: None setting; the field workarounds above are for diagnostic VLANs. Force Basic256Sha256 and an X.509 cert signed by a CA that the PC client trusts.
- Fail-safe interaction: If the trace is configured on a F-CPU (e.g., S7-1516F), the web server is read-only on safety tags and the trace cannot include F-related DBs without an F-authorized user. Plan a separate F-tag access concept before any of the methods above.
Field Commissioning Checklist
- Confirm CPU firmware is on the supported list for the chosen method (see Prerequisites table).
- Confirm web server is reachable from the diagnostic laptop:
ping <cpu-ip>andcurl -k -u user:pwd https://<cpu-ip>/should return HTTP 200. - Trigger a known process event; confirm one full recording cycle completes without a 0x0001 STATUS report on the trace object.
- Run the export script; confirm the first and last sample match a live reading from the HMI to within one sample period.
- Document the file naming convention and the retention policy in the project's Functional Specification so a future engineer does not have to repeat this discovery.
FAQ
Can I open a TIA Portal trace file in Excel or another tool without TIA?
No. The S7-1500 trace file is a TIA-internal format (.csvz is a zipped container, not a plain CSV). You must either re-export the trace as CSV from TIA Portal, or use one of the workarounds above (DataLog, OUC, OPC UA, or web server scraper) to capture the data in a tool-agnostic format from the start.
Which method works when the customer has no TIA installed and no network connection?
DataLog is the most reliable option. Configure the DataLog in TIA, then deploy the project. The .csv file is written to the SIMATIC memory card; the service engineer can pull the card and read the file on any laptop, no TIA required.
Does the S7-1500 web server allow downloading the trace as a file?
Not directly. The web server renders the trace as a JavaScript chart. A headless browser, an HTTP scraper, or a SCADA with a custom URL handler is required to extract the numeric data. The CPU's SFTP/FTP service (FW 2.6+) provides direct file-system access and is the only file-download path that does not require browser automation.
What is the minimum cycle time for an OUC TCP-based data logger?
Can I use OPC UA on a CPU that does not have the OPC UA license?
The Compact OPC UA server is enabled by default on most S7-1500 CPU variants and supports basic tag read/write and subscriptions. The full server with method calls, alarms, and historical access requires a SIMATIC OPC UA S7-1500 runtime license (6ES7822-0AA00-0YA0) and CPU firmware 2.5 or higher.