Overview
Siemens S7-1500 CPUs include a native DataLog instruction set in TIA Portal that writes structured records to comma-separated value (CSV) files on the SIMATIC Memory Card (SMC). For higher-level historians or relational databases (Microsoft SQL Server, MySQL, PostgreSQL, MariaDB, Oracle), the on-board CSV can be moved off the PLC over the integrated web server, via OPC UA Historical Access, or pushed directly with an ODBC/CSV bridge application running on a PC or edge gateway.
This reference covers the complete engineering workflow: enabling the DataLog function block family (DataLogCreate, DataLogOpen, DataLogWrite, DataLogClose, DataLogDelete, DataLogNewFile), configuring the SIMATIC memory card, exposing the files through the CPU web server, and forwarding the records to an external SQL database. The procedures are valid for S7-1500, S7-1500F, ET 200SP CPU, and the software controller S7-1500S starting with TIA Portal V14 SP1 and CPU firmware V2.0. Subsequent features (such as DataLogNewFile for runtime file rotation) require firmware V2.5 or later.
Prerequisites and Supported Hardware
| Component | Minimum Requirement | Notes |
|---|---|---|
| TIA Portal | V14 SP1 (basic DataLog) / V15.1+ (extended instructions) | V17 / V18 recommended for current firmware |
| S7-1500 CPU | Firmware V2.0 or higher | CPU 1511-1 PN through CPU 1518-4 PN/DP, plus ET 200SP CPU 1510SP-1 PN / 1512SP-1 PN / 1515SP-2 PN |
| SIMATIC Memory Card | 4 MB minimum, 32 GB maximum | Siemens SMC catalog numbers: 6ES7954-8LF02-0AA0 (4 MB), 6ES7954-8LE03-0AA0 (12 MB), 6ES7954-8LL02-0AA0 (24 MB), 6ES7954-8LP02-0AA0 (256 MB), 6ES7954-8LT03-0AA0 (2 GB), 6ES7954-8LX02-0AA0 (32 GB) |
| File system | FAT16 / FAT32 | NTFS not supported on SMC; S7-1500 reformats cards to its own structure |
| Number of DataLogs per CPU | Up to 50 DataLog files (data blocks of type DataLog) |
Limitation applies to user-defined instance DBs |
| Record size | Maximum 512 bytes per record (including 2-byte header) | Approx. 256 standard tags of 2 bytes each |
| DataLog file size | Up to 1 048 576 records per file | File wraps or closes per configuration |
Confirm the SIMATIC Memory Card is inserted and formatted. If the PLC has been running without a card, perform a memory reset and insert the card before powering up so the S7-1500 can claim the card as boot medium. For projects that require program persistence on card removal, configure the CPU in Card operation mode (CPU properties > Card operation).
Architecture: CSV-on-Card vs. External SQL
Two distinct topologies apply. Engineers should pick the one that matches the historian, retention policy, and network boundary.
| Aspect | CSV on SMC + Web Server | External SQL via OPC UA / ODBC bridge |
|---|---|---|
| Storage medium | SIMATIC Memory Card in the CPU | PC, edge gateway, or cloud database |
| Data transport | HTTP download through CPU web server or SFTP/FTP (V2.6+) | OPC UA Pub/Sub, OPC DA-HDA, MQTT, or CSV flat-file polling into ODBC |
| Latency | One PLC cycle per write; download is polled | Sub-second to several seconds depending on broker |
| Capacity | Bounded by SMC size (32 GB ceiling) | Effectively unlimited with rolling retention |
| Typical use | Local audit trail, batch evidence, fast offline analysis | Plant-wide historian (PI, Wonderware, Ignition), MES/ERP integration |
| Security | Web server user rights, HTTPS, IP allowlist | OPC UA certificate + user auth, TLS on SQL |
Most plants deploy both. The on-card CSV acts as a forensic buffer; the external SQL sink provides queryable, time-indexed history for SCADA, analytics, and regulatory reporting.
Step 1: Configure the SIMATIC Memory Card
- Open the device view of the S7-1500 CPU in TIA Portal.
- Select Properties > General > Memory and confirm the card type matches the inserted SMC.
- Enable the file-system browser access rights under Web server > User management (covered in Step 4).
- Download the project to the CPU. The DataLog instructions will only execute when the CPU is in RUN and the SMC is present and write-enabled.
Step 2: Create the DataLog in TIA Portal
- In the project tree, expand Instructions > Extended instructions > Recipe and DataLogging > DataLogging.
- Drag the
DataLogCreateinstruction into a new function block (e.g.,FB_Datalogger). - Declare an instance DB; TIA Portal will create a DataLog reference DB automatically on first download.
- Wire the inputs as shown in the table below.
| Input | Type | Example | Description |
|---|---|---|---|
REQ |
BOOL | StartTrigger |
Rising edge creates the file |
ID |
DWORD | DW#16#00000001 |
Unique data log ID within the CPU |
NAME |
WSTRING / STRING | 'BatchLog_2024' |
File name without extension (max 22 chars) |
HEADER |
WSTRING / STRING | 'Timestamp;Temp;Pressure;Flow' |
First line of the CSV; column names separated by configured delimiter |
RECORDS |
UDInt | 100000 |
Maximum records before auto-close (max 1 048 576) |
DATA |
VARIANT | P#DB_ProcessData.DBX0.0 BYTE 32 |
Source DB; size = total record length in bytes |
TIMESTAMP |
BOOL | TRUE |
Adds 8-byte CPU time stamp as first column |
FORMAT |
BYTE |
16#01 (CSV) / 16#02 (TXT tab) |
Default CSV with ; delimiter (Germany locale); for English locale use 16#03 for comma delimiter |
STATUS |
WORD | W#16#0000 | Return code; 0000 = OK |
On the first rising edge of REQ, the CPU creates a CSV file under /DataLogs/<NAME>.csv on the SMC and returns STATUS = 0. Repeat the call after a power cycle to re-open the same log via DataLogOpen with the matching ID.
Step 3: Program the DataLog Instructions
A typical OB1 cycle (or a time-of-day OB, e.g., OB10, OB30..OB38) chains the instructions as follows:
// FB_Datalogger — instance DB: iDB_DataLog
// 1) Create on first call
IF bFirstRun THEN
DataLogCreate(REQ := bFirstRun,
ID := 1,
NAME := 'BatchLog_2024',
HEADER := 'Timestamp;Temp_C;Pressure_bar;Flow_lpm',
RECORDS := 500000,
DATA := iDB_ProcessData.ProcessData,
TIMESTAMP := TRUE,
FORMAT := 16#01,
STATUS => wCreateStatus);
bFirstRun := FALSE;
END_IF;
// 2) Write one record per cycle (1 s OB1 or 100 ms OB35)
DataLogWrite(REQ := bWriteTrig,
ID := 1,
DATA := iDB_ProcessData.ProcessData,
STATUS => wWriteStatus);
// 3) Optional: rotate file daily
IF (dtNow > dtNextRollover) THEN
DataLogNewFile(REQ := TRUE,
ID := 1,
NAME := CONCAT('BatchLog_', STRING_FROM_DT(dtNow)),
STATUS => wNewStatus);
END_IF;
The DATA parameter on DataLogWrite must point to a data area whose byte length matches the original DataLogCreate declaration. Mismatches return STATUS = 16#80C0 (record length error). The maximum data block size for a single record is 512 bytes; bundle small tags into a global DB to keep the layout contiguous and avoid fragmentation faults.
Step 4: Activate the Web Server for CSV Retrieval
- CPU properties > Web server > check Activate web server on this module.
- Select Permit access only with HTTPS for production.
- Under User management, create at least one user with the right Filebrowser — read files. Note: download rights require firmware V2.6+ for HTTPS file access on standard CPUs.
- Compile and download. Open a browser to
https://<CPU-IP>and log in. - Navigate to Filebrowser > DataLogs > BatchLog_2024.csv. Right-click → Save target as to download.
Step 5: Push Data to SQL / ODBC Databases
The S7-1500 does not embed an SQL client. To land records into a relational database, choose one of three industrial-grade paths.
5.1 ODBC DataLogger bridge (CSV-flat-file polling)
Many plants have legacy instruments that emit CSV rather than OPC. An ODBC DataLogger plug-in polls the on-card CSV over the web server, transforms each row, and writes it into any ODBC-compliant database (SQL Server, MySQL, PostgreSQL, Oracle, SQLite). Configure the polling interval, the delimiter, and a parameterized INSERT statement. See the TOP Server ODBC DataLogger plug-in reference architecture for an example driver-agnostic bridge.
5.2 OPC UA Historical Access into Ignition, WinCC, iFIX, or PI
- Enable the S7-1500 OPC UA server (CPU properties > OPC UA > Activate).
- Create a Historical Access node in the S7-1500 OPC UA address space. The CPU can store up to 10 000 events per HDA node by default (firmware V2.9+).
- Connect your SCADA / historian. For example, Ignition's OPC-HDA Module reads the HDA nodes and inserts into MySQL/MSSQL using the Store and Forward engine.
5.3 MQTT or REST push from an edge gateway
An industrial edge node (e.g., SIMATIC IOT2050, MIPC, Node-RED on a Click Plus, or any Linux gateway) can curl the CSV from the web server on a schedule, parse it, and POST JSON to an SQL REST endpoint. This is a common pattern for batch evidence where the SQL row is generated only at end-of-batch, not every scan.
Verification and Commissioning
- Watch the
STATUSoutputs of every DataLog call in an online watch table. A healthy system showsW#16#0000. - Force a
DataLogWriteand confirm the SMC file size grows by the configured record length (2 + record bytes). - Download the CSV via web server, open in Excel or LibreOffice, and confirm the time-stamp column matches the PLC clock. The default format is
YYYY-MM-DD HH:MM:SS.sssin UTC (or local time if the CPU time is set to local). - Cycle power and confirm that
DataLogOpenreattaches to the same file (STATUS = 0); if it returns16#80B0, the file does not exist and a freshDataLogCreateis required. - If the SQL path is enabled, confirm the bridge inserts rows by running a
SELECT COUNT(*)on the destination table and watching the count increment by the expected polled rows.
Troubleshooting Matrix
| Symptom | STATUS (hex) | Likely Root Cause | Corrective Action |
|---|---|---|---|
| Create returns error, file not visible | 16#80A1 |
Memory card missing, full, or write-protected | Unlock card slide switch, replace with larger SMC, or run DataLogDelete on stale files |
| Create returns error, name in use | 16#80A2 |
A file with the same NAME already exists |
Use DataLogDelete first, or append a date suffix |
| Create: invalid header | 16#80B1 |
Header string > 256 bytes or contains illegal characters | Shorten column names; avoid ; , in header unless escaped |
| Write: wrong record length | 16#80C0 |
DATA variant size mismatch with original Create |
Repoint DATA to same DB / same byte count as Create |
| Write: file not open | 16#80B0 |
Power cycle or file deletion without re-opening | Call DataLogOpen on cold start |
| Web server: filebrowser greyed out | n/a | User lacks Filebrowser — read right | Edit user in CPU Web server > User management |
| Web server: 404 on .csv download | n/a | Firmware < V2.6 and CSV access requires HTTPS user rights; older builds only support download via FTP/SFTP | Upgrade firmware or use SFTP client against the CPU |
| SQL rows missing or duplicated | n/a | Bridge polling partial files during a write | Use DataLogClose → bridge download → DataLogOpen cycle, or use HDA end-of-record events |
| PLC goes STOP with SF LED | n/a | Faulty / counterfeit SD card | Replace with Siemens SMC catalog number; check diagnostics buffer for Event ID 16#4562 (memory card fault) |
| Web server download slow / stalls | n/a | File > 200 MB; S7-1500 web server streams at 1-3 MB/s | Lower RECORDS or implement DataLogNewFile rotation |
Performance and Sizing
DataLog write time scales linearly with record length. A typical 32-byte record on a CPU 1515-2 PN takes ~600 µs to commit. At 100 ms scan, that is well under 1% CPU load. At 1 ms scan with 100-byte records, expect 2-4% CPU load; do not exceed 8 ms scans with large records or scan jitter will dominate.
For ring-buffer behavior, set RECORDS to the desired depth, enable DataLogNewFile on rollover, and archive the closed file to SQL through the bridge. This pattern holds the on-card footprint constant and gives the SQL side a clean, time-bounded batch to ingest.
For high-availability retention, deploy redundant S7-1500R/H CPUs with two SMCs in parallel; the standby CPU also receives DataLog commands if the user program is identical, providing a hot mirror.
Reference: Status Code Summary
| STATUS (hex) | Meaning | Where Returned |
|---|---|---|
0000 |
No error | All DataLog FB outputs |
7000 |
No job active | All DataLog FB outputs (idle) |
80A1 |
Memory error / card missing | DataLogCreate, DataLogOpen, DataLogWrite |
80A2 |
Name conflict / file exists | DataLogCreate |
80B0 |
File not open | DataLogWrite, DataLogClose |
80B1 |
Header invalid | DataLogCreate |
80C0 |
Record length mismatch | DataLogWrite |
80C1 |
File full (RECORDS reached) | DataLogWrite |
80C2 |
Wrong ID | DataLogOpen, DataLogClose |
80C3 |
Max number of DataLogs reached (50) | DataLogCreate |
Which Siemens SMC size should I pick for continuous logging?
For 1 s logging of 32 bytes (~40 bytes on disk), 1 million records consume ~40 MB. A 256 MB SMC (6ES7954-8LP02-0AA0) holds roughly 6 million records — about 70 days at 1 s. Step up to 2 GB (6ES7954-8LT03-0AA0) for year-long retention and rotate with DataLogNewFile.
Can the S7-1500 write directly to SQL Server without a PC?
No. The CPU has no native SQL client. The supported method is to log to CSV on the SMC and use an external bridge (ODBC DataLogger, OPC UA HDA, or an edge gateway with REST/MQTT) to move rows into SQL Server, MySQL, PostgreSQL, or Oracle.
Why does my CSV open with all data in column A?
The default FORMAT uses ; as the delimiter (Germany locale). Excel in English locales expects ,. Either set FORMAT := 16#03 in DataLogCreate to use a comma, or open the file with the Text Import Wizard and specify the semicolon delimiter manually.
How do I read the CSV on a PC if I don't want to enable the web server?
Power down the PLC, remove the SIMATIC Memory Card, mount it in a USB card reader, and copy the file from the \DataLogs\ directory. The card is FAT32; no special reader is required. Reinsert the card before powering the CPU back up.
What is the difference between DataLog and Recipe instructions?
RecipeExport / RecipeImport move DB contents between the SMC and a file for parameter set transfer (operator download of a new batch formula). DataLogCreate / DataLogWrite append timestamped records for traceability. They share the same \DataLogs\ folder but serve different purposes.