S7-1200 Recipe Data Import: HMI, SD Card, USB, and OPC Methods
Production environments with high SKU counts require deterministic, repeatable data import. For a SIMATIC S7-1200 CPU (e.g., CPU 1214C DC/DC/DC) paired with a SIMATIC Basic Panel HMI and TIA Portal, four engineering patterns cover the majority of use cases: PLC-resident recipe arrays, HMI recipe archives, SD card file operations (firmware V4.0+), and Ethernet-based host integration via OPC UA or TCP. This reference consolidates field-proven methods for a 300-record dataset of ten numeric fields per record, including commissioning steps, SCL code, file formats, and a fault matrix.
1. Problem Definition and Data Model
A typical "panel" data record carries one reference code plus four geometry parameters and five hole positions. The data is sourced from an ERP or production-planning system and must be loaded onto the shop floor without manual re-keying of every record.
| Index | Tag | Data Type | Range | Notes |
|---|---|---|---|---|
| 0 | PanelRef | STRING[10] | 10 ASCII chars | Master reference, e.g., "A123456789" |
| 1 | Quantity | UINT | 1 to 65535 | Lot quantity |
| 2 | Width_mm | UINT | 0 to 3000 | Panel width in mm |
| 3 | Height_mm | UINT | 0 to 3000 | Panel height in mm |
| 4 | Hole1 | UINT | 0 to 3000 | Hole 1 position |
| 5 | Hole2 | UINT | 0 to 3000 | Hole 2 position |
| 6 | Hole3 | UINT | 0 to 3000 | Hole 3 position |
| 7 | Hole1A | UINT | 0 to 3000 | Hole 1A position |
| 8 | Hole2A | UINT | 0 to 3000 | Hole 2A position |
| 9 | Hole3A | UINT | 0 to 3000 | Hole 3A position |
For 300 records the resident footprint is 300 x 26 bytes = 7,800 bytes, well within the work memory and load memory budget of any CPU 1214C variant. The two-byte overhead of each STRING[10] field (max-length header plus ten bytes of data) is included in the 26-byte per-record calculation.
2. Engineering Options Overview
Four storage topologies are available on a SIMATIC S7-1200 + Basic Panel architecture. Each has a different trade-off curve across commissioning time, runtime performance, backup convenience, and engineering effort.
| # | Method | Storage Location | Backup | Import Mechanism | Min Firmware |
|---|---|---|---|---|---|
| 1 | PLC array (DB of UDTs) | CPU work memory + load memory | Project upload (TIA) / SD card | Initial download; runtime edits via HMI | V1.0+ |
| 2 | HMI recipe archive | Internal HMI flash or USB | CSV export to USB stick | CSV import via HMI | Basic 2nd gen |
| 3 | SD card recipe files | S7-1200 SD card file system | Card swap or FTP | File instructions (SCL) | CPU V4.0 |
| 4 | Host system (OPC UA / TCP) | PC / MES database | Database backup | Custom SCL client or OPC UA server | CPU V4.2+ (OPC UA server) |
Refer to the Siemens Industry Online Support portal for the latest S7-1200 system manual and TIA Portal help documents. Specific firmware notes are published under each CPU article number in the support database.
3. Method 1 — PLC Array of UDTs (Preferred for Tightly Coupled Recipes)
This pattern is the simplest to debug, the fastest at runtime, and integrates with the S7-1200 standard firmware from V1.0 onward. You define a User-Defined Type (UDT) and instantiate an array of 300 elements in a global DB.
3.1 UDT Definition
TYPE "RECIPE_PANEL"
VERSION : 0.1
STRUCT
PanelRef : STRING[10]; // 12 bytes
Quantity : UINT; // 2 bytes
Width_mm : UINT; // 2 bytes
Height_mm : UINT; // 2 bytes
Hole1 : UINT; // 2 bytes
Hole2 : UINT; // 2 bytes
Hole3 : UINT; // 2 bytes
Hole1A : UINT; // 2 bytes
Hole2A : UINT; // 2 bytes
Hole3A : UINT; // 2 bytes
END_STRUCT;
END_TYPE;
3.2 Global Data Block
Create DB "RecipeDB" with optimized access disabled if you intend to expose the data through PUT/GET or older OPC DA drivers. Declare Recipes : ARRAY[0..299] OF "RECIPE_PANEL"; plus an index register ActiveIndex : INT; and the currently active record Active : "RECIPE_PANEL";. Enable the retain attribute on the array so the data survives a power cycle.
3.3 Lookup SCL Function Block
The following SCL implements a reference lookup, scanning the array linearly. For 300 records the scan completes in well under 1 ms on a CPU 1214C.
FUNCTION_BLOCK "FB_RecipeLookup"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR_INPUT
iSearchRef : STRING[10];
iExecute : BOOL;
END_VAR
VAR_OUTPUT
oFound : BOOL;
oIndex : INT;
oRecipe : "RECIPE_PANEL";
oError : WORD;
END_VAR
VAR
sTempRef : STRING[10];
i : INT;
END_VAR
BEGIN
oFound := FALSE;
oError := 0;
IF iExecute THEN
FOR i := 0 TO 299 DO
sTempRef := "RecipeDB".Recipes[i].PanelRef;
IF sTempRef = iSearchRef THEN
oIndex := i;
oRecipe := "RecipeDB".Recipes[i];
oFound := TRUE;
RETURN;
END_IF;
END_FOR;
oError := 16#0001; // W#16#0001 = reference not found
END_IF;
END_FUNCTION_BLOCK;
iSearchRef is right-padded automatically. If the panel reference can be shorter than 10 characters, always compare the full STRING[10] against the full STRING[10] field. A LEFT()-based partial compare is more expensive and not required.For 300 records a linear scan is acceptable. If the dataset grows beyond roughly 5,000 records, build a hash index in a separate INT array that maps a hashed reference to the recipe slot.
4. Method 2 — HMI Recipe Archive (Basic Panel 2nd Generation)
The SIMATIC Basic Panel 2nd generation family (KTP400 Basic 2nd Gen, KTP700 Basic 2nd Gen, KTP900 Basic 2nd Gen, KTP1200 Basic 2nd Gen) provides a recipe view that holds data records in the panel's internal flash. The TIA Portal "Recipes" editor publishes a CSV file that can be exported to and imported from a USB stick plugged into the panel's front USB port.
4.1 HMI Tag Wiring
Each recipe element is bound to an HMI tag whose PLC address is a single INT, DINT, or STRING. For STRING tags the HMI recipe element type "Text" maps to a STRING of declared length. The TIA Portal HMI recipe editor generates a recipe view screen that the operator uses to select, edit, save, and load data records.
4.2 File Format
The export file is plain text with a UTF-8 BOM, comma-separated values, and CRLF line endings. A sample row for one record with ten elements is:
"Record","PanelRef","Quantity","Width_mm","Height_mm","Hole1","Hole2","Hole3","Hole1A","Hole2A","Hole3A"
"REC_001","A123456789",100,1200,600,200,250,350,200,250,350
"REC_002","A987654321",50,800,400,150,200,250,150,200,250
Edit this file with any tooling that can emit UTF-8 CSV — Excel, a custom MES export, or a Python script. Save the file as Recipes.csv on the root of a FAT32-formatted USB stick.
4.3 Import Procedure
- Insert the USB stick into the panel's front USB port.
- Open the recipe view on the panel.
- Press the "Import" softkey. The panel walks the directory
/<storage>/simatic/HMI/Recipes/and lists available files. - Select
Recipes.csv. The panel parses the file, validates types, and prompts to overwrite existing records or save as new. - Press "OK" to commit. The panel writes the records to internal flash and notifies the PLC of the active data set on the next "Transfer to PLC" event.
/<USB label>/simatic/HMI/Recipes/ directory. Sub-directories are ignored. The USB label must be 11 characters or fewer; the panel mounts the first FAT32 partition it finds.The advantage of this method is a fully documented, operator-friendly interface. The disadvantage is that the storage lives on the HMI: the panel's flash is the only persistent location unless you re-export the file to the USB stick after every change.
5. Method 3 — SD Card File Recipes (CPU Firmware V4.0 and Higher)
CPU 1214C firmware V4.0 introduced a POSIX-like file system on the SD card. Recipes can be stored as files, read into a DB at startup, and written back at runtime using the extended instructions FileReadC and FileWriteC from the "Recipes and data logging" extended instruction library. The S7-1200 system manual documents the instruction set and the file system rules.
5.1 File Layout on the SD Card
The file system path is /RecipeDB/Panels.csv. The same CSV format as Method 2 applies, but the file is accessed directly by the PLC, not by the HMI. The directory must be created manually on a freshly formatted SD card using a PC and a USB card reader.
5.2 Recipe Load at Startup (SCL)
FUNCTION_BLOCK "FB_RecipeLoadAll"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR_INPUT
iExecute : BOOL;
END_VAR
VAR_OUTPUT
oDone : BOOL;
oBusy : BOOL;
oError : WORD;
END_VAR
VAR
sFileName : STRING;
instFileRead : FileReadC;
END_VAR
BEGIN
IF iExecute AND NOT oBusy THEN
oBusy := TRUE;
sFileName := '/RecipeDB/Panels.csv';
instFileRead(REQ := TRUE,
FILE_NAME := sFileName,
DONE => oDone,
BUSY => oBusy,
ERROR => oError);
END_IF;
END_FUNCTION_BLOCK;
The CSV body is parsed into the Recipes array by a sequential scan: read each line into a STRING[256] buffer, split on commas using StrgTok, convert each token to UINT with StrgToInt, and write into the matching field. The first line of the file is the header and is skipped.
5.3 Recipe Save at Runtime (SCL)
FUNCTION_BLOCK "FB_RecipeSaveAll"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR_INPUT
iExecute : BOOL;
END_VAR
VAR_OUTPUT
oDone : BOOL;
oError : WORD;
END_VAR
VAR
instFileWrite : FileWriteC;
sFileName : STRING;
sLine : STRING[256];
END_VAR
BEGIN
IF iExecute AND NOT oDone THEN
sFileName := '/RecipeDB/Panels.csv';
instFileWrite(REQ := TRUE,
FILE_NAME := sFileName,
WRITE_DATA := sLine,
DONE => oDone,
ERROR => oError);
END_IF;
END_FUNCTION_BLOCK;
For 300 records the save completes in 50-150 ms on a 1214C. Do not invoke the save inside a fast OB (e.g., OB35 at 100 ms) because the file system write blocks execution. Trigger the save from a one-shot button via the HMI or a debounced input in OB1.
6. Method 4 — Host System Integration via OPC UA or TCP
When recipes originate from an MES or ERP system, the cleanest pattern is to expose the recipe DB as an OPC UA server on the S7-1200 (firmware V4.2 and higher). The host system connects to opc.tcp://<plc-ip>:4840 and reads or writes the recipe array.
6.1 OPC UA Server Activation on S7-1200
- In TIA Portal, open the CPU's Properties then OPC UA.
- Enable the OPC UA server.
- Define a security policy. For an isolated shop-floor LAN, "None" is acceptable. For mixed networks, select "Sign" or "SignAndEncrypt" with a 2048-bit self-signed certificate.
- Expose the
RecipeDBas a node set with read/write access. - Compile and download. The OPC UA server is now available on port 4840.
A reference .NET 6 client that pulls the entire recipe table in one call is straightforward with the OPCFoundation.NetStandard.Opc.Ua.Client library. The code is outside the scope of the S7-1200 firmware but uses the standard browse-then-read pattern.
6.2 Custom TCP Fallback (Firmware V1.0+)
If OPC UA is not available, the S7-1200's TSEND_C and TRCV_C instructions implement a TCP client/server on a configurable port. A host application sends a 4-byte index, the PLC responds with the binary record. This pattern is fully supported but requires custom application code on the host side. Use this path only if OPC UA licensing is unavailable and the dataset is small enough to absorb the engineering overhead.
7. Architecture Comparison and Selection Guide
| Criterion | PLC Array | HMI Recipe | SD Card | OPC UA / TCP |
|---|---|---|---|---|
| Operator UX | Poor (numeric entry) | Excellent (recipe view) | Poor (no direct view) | Host-dependent |
| Backup convenience | Project archive | USB export | SD swap / FTP | Database backup |
| Import mechanism | Download only | USB CSV import | SD card file | Network push |
| Engineering effort | Low | Low | Medium | High |
| Read latency at runtime | Sub-ms | 10 to 50 ms | 10 to 50 ms (file I/O) | Network-dependent |
| Data integrity | CRC32 optional | Panel-managed | Application-managed | TLS-secured |
| Scalability (records) | Up to 5,000 | Up to 1,000 | Up to 100,000 (SD size) | Unlimited |
| Min firmware | V1.0 | Basic 2nd gen | CPU V4.0 | CPU V4.2 (OPC UA) |
For the original use case — 300 records, 10 fields each, basic operator panel, and the need for a fast USB import — the best balance is the SD card file method (Method 3) with a CSV file generated by the shop's existing ERP or MES export. The HMI recipe view (Method 2) is the second-best alternative if the operators want point-and-click access and a Basic Panel 2nd generation is in stock. PLC array storage (Method 1) is the right pick if recipes are static and downloaded with the project. OPC UA (Method 4) is the right pick if recipes are dynamically managed by a host system.
8. Commissioning Procedure
The following sequence verifies a Method 3 (SD card) implementation on a CPU 1214C with firmware V4.4:
- Insert a blank Siemens-formatted SD card into the CPU's card slot and format it via TIA Portal (online > card functions > format).
- Create the directory
/RecipeDB/on the SD card using a PC and a USB card reader. - Export a 2-row test CSV from the TIA Portal HMI recipe editor to validate the column order, then save the file as
/RecipeDB/Panels.csv. - Download the project, including the
FB_RecipeLoadAllinstance DB, to the CPU. - Force
iExecute = TRUEon the load FB in the watch table and verify thatoDone = TRUEandoError = 0within 5 seconds. - Open the recipe DB online and confirm that
Recipes[0]andRecipes[1]match the test CSV values exactly. - Trigger the lookup FB with a valid reference and confirm
oFound = TRUEand the active record matches. - Trigger the lookup FB with an invalid reference and confirm
oFound = FALSEandoError = 16#0001. - Export the full recipe set from the SD card via FTP (S7-1200 FTP server is enabled by default in V4.0+) and diff against the source CSV.
- Remove the SD card, power-cycle the CPU, and confirm that
RecipeDBre-loads from the SD card automatically on next boot.
9. Field-Proven Caveats
The following issues are observed repeatedly in field installations and should be addressed during design review.
- STRING length mismatch on HMI tags. The HMI recipe element "Text" type has a length property that defaults to 8 characters. A 10-character panel reference in the PLC and an 8-character HMI tag truncates the import silently and writes a corrupted record. Always size the HMI tag to the PLC STRING length.
- Optimized block access on OPC UA. The OPC UA server (V4.2+) requires symbolic access on the exposed DB. Optimized access is the default for new DBs in TIA Portal V17 and later. If you set optimized access OFF, you must also confirm that PUT/GET is enabled for cross-CPU visibility.
-
CSV line ending. Notepad on Windows writes CRLF, the standard TIA Portal importer expects CRLF. Some Linux export tools emit LF only and the parser fails on the first long line. Always emit CRLF on the export side or post-process with
unix2dos. -
File system write latency.
FileWriteCon a 300-record CSV takes 50-150 ms on a 1214C. Do not call it inside a fast OB (e.g., OB35 at 100 ms); instead trigger it from a one-shot button via the HMI or a slow OB (OB1 with a debounced input). - Recipe consistency across PLC and HMI. If both Method 2 (HMI) and Method 3 (PLC) are deployed in parallel, the operator can desync the two stores. Choose one path or implement a master-slave refresh that always reads from the master after every save.
- Retain on the recipe DB. The Recipes array must have the retain attribute set on the DB properties, otherwise all data is lost on power cycle and re-loaded from the SD card on next boot only if the SD card file path is correct.
10. Troubleshooting Matrix
| Symptom | Likely Cause | Diagnostic | Resolution |
|---|---|---|---|
| Lookup returns oFound=FALSE for a known reference | Hidden whitespace in STRING | Watch table on sTempRef; verify length | TRIM reference before compare; use STRING[10] on both sides |
| HMI recipe view shows "Invalid file" | UTF-8 BOM missing or file in wrong directory | Hex-dump the first 3 bytes of the CSV | Save with UTF-8 BOM; place in /simatic/HMI/Recipes/
|
| FileReadC returns ERROR = 16#8090 | File does not exist on SD card | FTP to PLC IP and list /RecipeDB/
|
Re-create the file; ensure SD card is properly formatted |
| FileReadC returns ERROR = 16#80A1 | File is locked or being written | Check for concurrent write FB instances | Sequence read/write with a single semaphore bit |
| OPC UA client cannot browse nodes | Security policy mismatch or license missing | CPU diagnostic buffer and OPC UA events | Match security policy; verify license installation |
| PLC array data lost after power cycle | Recipe DB set to "non-retentive" | DB properties and Retain attribute | Enable retain on the Recipes array |
| Import succeeds but values are 0 | Optimized access blocks symbolic write from HMI | Watch table: forced read of DB element | Disable optimized access on the recipe DB or enable symbolic access |
| CSV line truncated at 80 chars | Parser buffer too small | Watch table on sLine length | Increase buffer to STRING[256] or larger |
11. Frequently Asked Questions
Can I import a 300-record recipe file directly into a CPU 1214C from a USB stick without using the HMI?
Yes, with CPU firmware V4.0 or higher the SD card slot accepts a FAT32 file system. Place the CSV in /RecipeDB/ and load it on startup with the FileReadC extended instruction. No HMI involvement is required for the import itself.
How many recipe records can a 1st generation KTP700 Basic panel store in its internal flash?
The recipe storage capacity depends on the element count and type. As a working figure, 200 records with ten INT elements and one STRING[10] fit within a Basic panel's recipe partition. For larger sets, use a 2nd generation panel or move the storage to the PLC's SD card.
What is the minimum firmware for OPC UA server on the S7-1200?
OPC UA server support is enabled in firmware V4.2 with broader capability added in V4.4. The OPC UA server requires a separately purchased SIMATIC OPC UA S7-1200 license activated in TIA Portal. Refer to the Siemens OPC UA S7-1200 application note for the security policy options.
Why does my Basic Panel 2nd generation import silently truncate my STRING[10] to 8 characters?
The HMI tag for the recipe element has a length property that defaults to 8 characters for the "Text" element type. Open the recipe editor, select the element, and set the length to 10 to match the PLC STRING[10] declaration.
Can a single S7-1200 host both an HMI recipe archive and an SD card recipe file?
Technically yes, but the operator can desync the two stores. Pick one as the source of truth and implement a refresh that re-reads the master after every save event. In production environments the SD card method is preferred because the storage is hot-swappable and survives a panel replacement.
Does a recipe DB in optimized access block PUT/GET from another S7 CPU?
Yes. PUT/GET access requires the DB to have optimized access disabled or symbolic access enabled. For new projects, TIA Portal defaults to optimized access; toggle it off in the DB properties if PUT/GET is part of the integration plan.