Overview
Barcode-driven pairing validation on an S7-1200 station requires a reference table that the PLC can compare scanned values against. The most common shop-floor approach loads this table from a CSV file held on a USB stick inserted into a SIMATIC Comfort Panel (TP700 / TP900 / TP1200 / TP1500 / TP1900 / TP2200), parses the data on the panel, and writes the parsed rows into an S7-1200 data block (DB) over the HMI tag interface. This article documents the production-tested procedure for TIA Portal V14 and later, including the VBScript implementation, tag multiplexing for string arrays, network-share fallback, and the FileReadC alternative for native PLC-side loading from a SIMATIC Memory Card.
The reference architecture is:
- Operator scans barcode A with a USB-connected scanner on the Comfort Panel.
- Operator scans barcode B.
- PLC compares both values against rows loaded from the CSV reference table.
- PLC allows the cycle to start only if the row exists and the two columns are a valid pair.
Prerequisites
| Component | Specification |
|---|---|
| CPU | S7-1200 (any firmware V4.0 or higher recommended for full DB-of-strings support) |
| HMI | SIMATIC Comfort Panel (WinCC Comfort / Advanced V14 SP1 or later on the engineering station) |
| Engineering | TIA Portal V14 / V15 / V16 / V17 — same project for PLC and HMI |
| Storage | USB stick formatted FAT32, ≤32 GB. NTFS sticks are not visible to WinCE-based panels. |
| PLC data types | DB with Array of String[254] for raw lines, plus a parsed Array of "STRUCT pairing" for production use |
| CSV layout | Header row optional. One pairing per row. Comma or semicolon separator, ASCII or UTF-8. |
Confirm the panel's USB port is the type-A host port on the rear/bottom edge. The mini-USB on the front is a programming port only and will not enumerate a mass-storage device.
CSV Structure Planning
Lock the file layout before you write any code. A consistent, header-driven layout lets the VBScript parser stay simple and lets the PLC DB map 1:1 onto the rows.
| Column | Sample Value | PLC Type | DB Tag Name |
|---|---|---|---|
| partA | BC-3344-AA | String[20] | recipeData.partA[i] |
| partB | BC-7711-BB | String[20] | recipeData.partB[i] |
| allowed | 1 | Bool | recipeData.allowed[i] |
Recommended limits for a single file on a Comfort Panel:
- Row count: 2000 rows maximum (empirically tested with VBScript line-by-line read on TP1200).
- Per-line length: 254 characters maximum (S7 string limit, see S7-1200 System Manual).
- File size: ≤4 MB to keep VBS execution time below 1 s on TP700.
Solution Architecture
The panel is the data mover, the PLC is the authority. Keep it that way: the panel pushes raw rows, the PLC validates pairings against a checksum or row-count tag written at the end of the load.
HMI Tag and PLC DB Configuration
PLC data block
Create a global DB named recipeDB with the following structure (TIA Portal V14, S7-1200 firmware 4.2+):
DATA_BLOCK "recipeDB"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
NON_RETAIN
STRUCT
lineCount : Int; // number of valid rows actually loaded
rows : Array[0..1999] of Struct
partA : String[20];
partB : String[20];
allowed : Bool;
END_STRUCT;
END_STRUCT;
END_DATA_BLOCK
DB123.DBX0.0.HMI tag plan
| HMI Tag Name | Type | Connection | Purpose |
|---|---|---|---|
| fromCsv_line | WString[254] | Local / Internal | Holds the current line buffer for parsing |
| fromCsv_partA | WString[20] | Local / Internal | Token A after split |
| fromCsv_partB | WString[20] | Local / Internal | Token B after split |
| index | Int | Internal | Loop counter 0..N-1 |
| recipeDB_rows_partA_idx | String[20] | HMI → PLC (symbolic) | Indexed write — needs multiplexing |
String Multiplexing for Indexed Array Access
Comfort Panels do not allow a single HMI tag to address any index of a PLC string array through normal configuration. The supported workaround is string multiplexing: declare one HMI tag per array element that you need to write, then route the active tag in code by toggling the multiplex index.
Procedure in TIA Portal V14:
- Open HMI Tags → Add the same number of
String[20]tags as your array size. A practical limit on a TP700 is 200 multiplex tags before the tag list becomes unmanageable; for larger sets, batch-load in chunks of 200. - For each tag, set the PLC address to a unique absolute byte area, e.g.
%DB2000.DBB0through%DB2000.DBB219(20 bytes each). - In the PLC, create a second DB
multiplexBufferwith aString[20]array matching the HMI tags. - In a cyclic OB, copy
multiplexBuffer[index] := fromCsv_partAonly — TIA will only allow you to read individual elements if you also have the corresponding multiplex buffer; you cannot symbolically addressrecipeDB.rows[i].partAfrom an HMI tag.
String types because HMI tags cannot subscript a string array symbolically.VBScript Implementation on the Comfort Panel
Attach the following script to a button's Click event. The script is written for WinCC Comfort V14's VBScript runtime. It reads \Storage Card USB\pairings.csv, splits on the configured separator, and pushes each token to HMI tags that the PLC has been configured to poll.
' --- CSV loader for SIMATIC Comfort Panel ---
' Trigger: button "Load pairings"
Const SEPARATOR = ";" ' change to "," for comma-separated
Const BASE_PATH = "\Storage Card USB\pairings.csv"
Dim fso, file, dataString, lines, i, parts
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(BASE_PATH) Then
ShowSystemAlarm "CSV not found at " & BASE_PATH
Exit Sub
End If
Set file = fso.OpenTextFile(BASE_PATH, 1, False, -1) ' -1 = Unicode, 0 = ASCII
i = 0
Do While Not file.AtEndOfStream
dataString = file.ReadLine
If Len(dataString) > 0 Then
parts = Split(dataString, SEPARATOR)
If UBound(parts) >= 2 Then
SmartTags("fromCsv_partA") = parts(0)
SmartTags("fromCsv_partB") = parts(1)
' write to PLC through HMI tag at index i
SmartTags("multiplex_index") = i
SmartTags("commit_row") = 1 ' one-shot pulse; PLC OB1 reads it
End If
End If
i = i + 1
If i > 1999 Then Exit Do
Loop
file.Close
Set file = Nothing
Set fso = Nothing
SmartTags("recipeDB_lineCount") = i
ShowSystemAlarm "Loaded " & i & " pairings"
On the PLC side, an OB1 segment watches the commit_row pulse and copies fromCsv_partA / fromCsv_partB from the HMI tag buffer into recipeDB.rows[multiplex_index]. Pulse length is one OB1 cycle; the panel sets it back to 0 from a corresponding HMI tag the PLC toggles after copying.
Why this pattern works
-
Unicode-safe:
OpenTextFile(..., -1)reads UTF-16. For UTF-8 CSVs, useOpenAsTextStreamwithTristateTrueon the Adodb.Stream object — covered in the persistent data white paper. -
Bounded memory: Each iteration overwrites the same
dataString; the script never holds the full file. VBS limit is multi-million characters, but per-line S7 string is 254. -
Failure visibility:
ShowSystemAlarmwrites to the panel's alarm buffer; the PLC can also subscribe to a status word that mirrors the last error code.
Network Share Fallback (No USB)
For installations where the panel cannot accept a USB stick — sealed cabinets, clean rooms, GMP-locked enclosures — the same script reads from a Windows SMB share:
Const BASE_PATH = "\\PLC-ENG-PC\pairings\pairings.csv"
Two preconditions must be satisfied:
- The shared folder is accessible to
Everyonewith read rights (or to a specific user whose credentials are stored on the panel). - The panel has been configured with the network credentials: Control Panel → Network and Dial-up Connections → LAN → Authentication on the Comfort Panel itself, OR through TIA Portal project settings under Runtime settings → User administration → Network ID.
Alternative: FileReadC on the PLC Memory Card
If the CSV must live on the SIMATIC Memory Card in the S7-1200's CPU slot, the FileReadC library block reads it directly. This is documented in the S7-1200 System Manual, section "Data logs and recipes", and in the persistent data application note.
Advantages over the panel-side approach:
- No VBScript, no WinCE path quirks.
- Reads the file with a single block call from OB1.
- Survives panel reboot and CPU replacement (file is on the MMC).
Disadvantages:
- CPU is busy while reading; OB1 latency increases proportionally with file size.
- MMC must remain seated; field operators cannot swap it without a power cycle.
- File size is constrained by the MMC capacity and the CPU's transfer buffer (typically 512 bytes per call, so a 1 MB file takes 2000+ OB1 calls).
Verification Procedure
- Insert a USB stick with a 5-row
pairings.csv. Trigger the load button on the panel. - On the PLC side, force Watch table → recipeDB and confirm
lineCount = 5and the first 5rows[]elements match the source file character-for-character. - Scan barcode A = first
partA, barcode B = firstpartB. Verify the cycle starts. - Scan a barcode not present in the file. Verify the cycle is blocked and a fault code (recommended: 16#7101 — "invalid pairing") is raised on the PLC.
- Pull the USB stick mid-cycle. Verify the PLC continues to use the previously loaded data; the load button should fail cleanly with the alarm "CSV not found".
Edge Cases and Field-Proven Caveats
| Symptom | Root Cause | Remediation |
|---|---|---|
| Script runs but DB stays empty | HMI tag is not symbolically bound to the PLC | Reconnect tag, use symbolic path recipeDB.rows[0].partA
|
| File visible in Windows, not on panel | Stick is NTFS or exFAT | Reformat as FAT32 with 32 KB cluster size |
| String shows only first character | Comfort Panel uses WString (2 bytes/char); PLC uses String (1 byte/char) — character-by-character mapping is required, or use the conversion FC1055 from the Siemens toolkit | Switch HMI tag to String[20] (without W) and use ASCII encoding |
| Network share path errors out | Panel cannot resolve the UNC or the credentials are wrong | Ping the share from a PC first; configure the panel's network ID with the same user |
| Multiplexing overwrites wrong index | Race between index update and value write | Use the commit_row pulse: PLC only latches the value when the pulse transitions from 0→1 |
| Header row treated as a pairing | Parser is positional, not named | Add If i = 0 Then Skip in the VBScript loop |
| Non-ASCII part numbers show as ? | OpenTextFile encoding mismatch | Use the Adodb.Stream with charset "utf-8" |
Safety and Operational Notes
CSV data is reference data, not safety data. Pairings from a USB stick are convenient for a build-to-order line, but they are not a substitute for a hardwired safety interlock. If the validation gates a safety-relevant function (e.g. welding, press actuation), the pairing result must be re-checked by a fail-safe PLC, e.g. an S7-1200F with the F-CPU safety program, before the actuator is released. Reference S7-1200 System Manual for F-CPU configuration.
FAQ
Can the Comfort Panel read a CSV directly into a PLC DB without VBScript?
No. Comfort Panels cannot bind an HMI tag to a variable index of a string array, and there is no built-in CSV parser. VBScript or the FileReadC block on the PLC is required to move the data.
Why does my string show garbled characters on the PLC?
The Comfort Panel uses WString (UTF-16) by default, while the S7-1200 uses String (ASCII). Set the HMI tag to plain String[20], open the CSV with ASCII encoding, or insert an explicit conversion block on the PLC.
How many rows can a Comfort Panel load in one VBScript pass?
Empirically 2000 rows on a TP1200 in under 2 seconds. The hard limit is the 254-character S7 string ceiling per line. For larger files, split the CSV or switch to the FileReadC PLC-side approach.
Can I read the CSV from a network share instead of USB?
Yes. Replace the path with \\servername\sharename\pairings.csv and configure the panel's SMB credentials in the Control Panel network adapter authentication dialog. The script itself does not need to change.
Is NTFS or exFAT supported on the Comfort Panel USB port?
No. Comfort Panels run a Windows Embedded CE / Windows IoT image that only enumerates FAT32 volumes. Reformat the USB stick as FAT32 with 32 KB cluster size before use.