Siemens HMI VB Script CSV Export: S7-300 to Panel Setup

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

Overview

Generating dated CSV reports on a Siemens HMI and retrieving them from an engineering station is a recurring requirement on water/wastewater, batching, and OEM machine projects. The most common stumbling block is panel selection: many older 6-inch and 4-inch panels do not execute Visual Basic Script (VBS), and even panels that do run VBS do not expose their file system to inbound SMB/CIFS clients. This article documents the supported platform path: pair three SIMATIC S7-300 controllers with a VBS-capable Comfort or Multi Panel, write the report with FileSystemObject, store the file to a memory card or network share, and retrieve it through the integrated Miniweb file browser or an outbound SMB push to an engineering PC.

Hardware constraint: The 6-inch TP177B (6AV6 642-0BC01-1AX1 / 6AV6 642-0BA01-1AX1) runs WinCC Flexible 2008 SP3 but does not execute VBS. The same restriction applies to the OP77B, TP170B, and the original TP177A. If you need VBS-driven CSV export, you must migrate to a SIMATIC Comfort Panel (TP700 / TP900 / TP1200 / TP1500) or a Multi Panel (MP 277 / MP 377).

HMI Platform Selection Matrix

Panel family VBS support Local file I/O SD/USB Miniweb server Recommended for CSV export
OP77B / OP170B No Limited recipes No No No
TP170B / TP177A No No No No No
TP177B 4" / 6" No Read-only via Miniweb SD on 6" Yes (read-only) No for VBS; use Miniweb retrieval
MP 177 / MP 277 Yes (WinCC Flexible) Yes (Flash, SD, USB) SD + USB Yes (Sm@rtServer option) Yes
MP 377 Yes (WinCC Flexible 2008 SP3+) Yes SD + USB Yes Yes
Comfort TP700 / TP900 / TP1200 / TP1500 / TP1900 / TP2200 Yes (WinCC Comfort / TIA Portal) Yes SD + USB Yes (full file browser) Recommended

For new deployments, target the SIMATIC HMI Comfort Panels (6AV2 124-1MC01-0AX0 family) configured with WinCC Comfort V16 or later inside TIA Portal. These support VBS, ANSI-C, the integrated Miniweb server with an interactive file browser, and a licensed Sm@rtServer option for remote access. See the SIMATIC HMI Comfort Panels operating instructions for the supported feature set per firmware revision.

Prerequisites

  • Engineering workstation: TIA Portal V16 (or V17/V18) with WinCC Comfort / WinCC Advanced installed.
  • HMI runtime license: WinCC Comfort V16 (6AV2 101-0AA06-0AA5) or higher; for Sm@rtServer add-on, license 6AV2 107-1KA00-0AA0.
  • One SIMATIC Comfort Panel (TP900 Comfort or larger recommended for archive space).
  • Three SIMATIC S7-300 CPUs (e.g. CPU 315-2 PN/DP, 6ES7 315-2EH14-0AB0) each with an Ethernet or PROFINET interface.
  • Industrial Ethernet switch (e.g. SCALANCE XB005) and Cat 6 cabling.
  • Memory card: Siemens 2 GB or 32 GB SD (6AV2 181-2AA20-0AA0) for archive storage.
  • Optional: Windows share or FTP server on the engineering PC for outbound file push.

Network Architecture: 3 x S7-300 to One Comfort Panel

Three S7-300 PLCs are connected over industrial Ethernet using the S7 Communication (PUT/GET) or ISO-on-TCP protocol. Each PLC uses one configured HMI connection in TIA Portal under Connections > HMI connections. The Comfort Panel acts as both client (polling tags) and passive server for the Miniweb browser.

Sample address plan for a flat network with no router:

Node IP address Subnet S7 connection name
PLC_1 (CPU 315-2 PN/DP) 192.168.0.10 255.255.255.0 Connection_1
PLC_2 (CPU 315-2 PN/DP) 192.168.0.11 255.255.255.0 Connection_2
PLC_3 (CPU 315-2 PN/DP) 192.168.0.12 255.255.255.0 Connection_3
TP1200 Comfort 192.168.0.20 255.255.255.0 — (HMI master)
Engineering PC 192.168.0.100 255.255.255.0 — (Miniweb client)

On each CPU 315-2 PN/DP enable PUT/GET under Properties > Communication > Access via PUT/GET communication. Without this flag the HMI connection establishes but tag reads return quality bad. See the S7-300 CPU 31xC and CPU 31x system manual for details.

Configuring the HMI Connections in TIA Portal

  1. Open the TIA Portal project and add a TP1200 Comfort device.
  2. In the project tree navigate to Devices & Networks > Networks view. Drag each S7-300 CPU and the Comfort Panel onto the same subnet.
  3. Select the Comfort Panel and open Connections. Add three HMI connections, one to each CPU. Set the Partner interface to the CPU's PROFINET interface and the Connection type to S7 connection.
  4. For each connection, on the partner (CPU) side enable Establish active connection only on the HMI side; the S7-300 CPU stays passive.
  5. Define a tag prefix per connection: PLC1_Tag, PLC2_Tag, PLC3_Tag. Use DB1 / DB2 / DB3 in each CPU to host the process values that will be exported.
  6. Compile and download the HMI configuration.

VB Script Architecture for the Daily CSV Export

The daily export is driven by a scheduler tag that pulses once every 24 hours. A simple implementation in the S7-300 uses a TON timer with PT = 86 400 000 ms (24 h) and a self-resetting counter; the DO output latches a BOOL bit in DB100.DBX0.0 that the HMI maps as DailyExportTrigger. The VBS routine attached to a value-change event on this tag performs the write.

Storage paths on a Comfort Panel

Logical drive Path prefix in VBS Notes
Internal flash \Flash\ ≈ 24 MB free on TP1200; survives reboot
Memory card (SD) \Storage Card SD\ Recommended for archives > 100 MB
USB (front) \USB Storage1\ Limited write cycles; not for permanent log
Network share \\server\share\ SMB/CIFS push from HMI

Sample VBS Procedure for CSV Generation

Place the following routine on a global VBS module. It reads 12 process tags from each of the three PLCs, prefixes a UTC timestamp, and appends one row to a daily file on the SD card.

' --- Module: modDailyExport ------------------------------------------
Option Explicit

Const FOLDER As String = "\Storage Card SD\Reports\"
Const SEP    As String = ";"   ' use semicolon for Excel locale-safe CSV

Sub GenerateDailyCSV()
    Dim oFSO, oFile, oTS
    Dim sPath, sLine, sDate
    Dim i As Integer

    sDate = FormatDateTime(Now, vbShortDate)            ' e.g. 2024-05-14
    sDate = Replace(sDate, "/", "-")
    sPath = FOLDER & "Report_" & sDate & ".csv"

    Set oFSO = CreateObject("Scripting.FileSystemObject")

    ' --- ensure target directory exists ---------------------------------
    If Not oFSO.FolderExists(FOLDER) Then
        oFSO.CreateFolder FOLDER
    End If

    ' --- create file if it does not yet exist; append otherwise ---------
    If oFSO.FileExists(sPath) Then
        Set oFile = oFSO.GetFile(sPath)
        Set oTS   = oFile.OpenAsTextStream(8, -2)        ' ForAppending, Unicode
    Else
        Set oFile = oFSO.CreateTextFile(sPath, True, True) ' overwrite=False, Unicode
        Set oTS   = oFile
        oTS.WriteLine "Timestamp" & SEP & _
            "PLC1_Temp" & SEP & "PLC1_Press" & SEP & "PLC1_Flow" & SEP & _
            "PLC2_Temp" & SEP & "PLC2_Press" & SEP & "PLC2_Flow" & SEP & _
            "PLC3_Temp" & SEP & "PLC3_Press" & SEP & "PLC3_Flow" & SEP & _
            "PLC1_OpHrs" & SEP & "PLC2_OpHrs" & SEP & "PLC3_OpHrs"
    End If

    ' --- build data row -------------------------------------------------
    sLine = FormatDateTime(Now, vbLongTime) & SEP & _
            SmartTags("PLC1_Temp")    & SEP & SmartTags("PLC1_Press") & SEP & SmartTags("PLC1_Flow") & SEP & _
            SmartTags("PLC2_Temp")    & SEP & SmartTags("PLC2_Press") & SEP & SmartTags("PLC2_Flow") & SEP & _
            SmartTags("PLC3_Temp")    & SEP & SmartTags("PLC3_Press") & SEP & SmartTags("PLC3_Flow") & SEP & _
            SmartTags("PLC1_OpHrs")   & SEP & SmartTags("PLC2_OpHrs")  & SEP & SmartTags("PLC3_OpHrs")
    sLine = Replace(sLine, ".", ",")          ' European decimal comma

    oTS.WriteLine sLine
    oTS.Close

    SmartTags("LastExport_Status") = "OK @ " & Now
End Sub

Sub PushDailyCSV_ToShare()
    Dim oFSO, oFile, oTS_local, oTS_remote
    Dim sLocal As String, sRemote As String, sDate As String

    sDate   = Replace(FormatDateTime(Now, vbShortDate), "/", "-")
    sLocal  = "\Storage Card SD\Reports\Report_" & sDate & ".csv"
    sRemote = "\\192.168.0.100\HMIReports\Report_" & sDate & ".csv"

    Set oFSO = CreateObject("Scripting.FileSystemObject")
    If Not oFSO.FileExists(sLocal) Then Exit Sub

    Set oTS_local  = oFSO.OpenTextFile(sLocal, 1, False, -2)
    Set oTS_remote = oFSO.CreateTextFile(sRemote, True, True)

    Do While Not oTS_local.AtEndOfStream
        oTS_remote.WriteLine oTS_local.ReadLine
    Loop

    oTS_local.Close
    oTS_remote.Close
End Sub

Bind GenerateDailyCSV to a value-change event on DailyExportTrigger. Bind PushDailyCSV_ToShare to a screen button or to a second tag that pulses five minutes after the export trigger.

Encoding note: Open the text file in Unicode mode (-2) so that non-ASCII tag values are preserved. If the receiving Excel uses ANSI, open the file with the Windows code-page-1252 import filter.

Remote File Access Options

The TP177B and the Comfort Panels differ significantly in how they expose the local file system to the engineering PC.

Method TP177B (no VBS) Comfort Panel (VBS) Direction
Miniweb file browser (HTTP) Read-only listing Read/write in firmware ≥ V14 PC -> Panel (pull)
SMB/CIFS share from panel Not supported Via VBS / FileSystemObject Panel -> PC (push)
FTP server Not supported Not native; use 3rd-party VBS / OPC PC -> Panel (pull)
Sm@rtServer option No Yes (licensed) PC -> Panel (remote view/operate)

Configuring the Miniweb Server on a Comfort Panel

  1. In the TIA Portal device view, open the Comfort Panel Properties > Web server (Miniweb) > General.
  2. Tick Enable web server and select Enable file browser. The file browser exposes \Flash\, \Storage Card SD\ and any inserted USB storage to authenticated HTTP clients.
  3. Define at least one user under Web server > User administration. The default user admin with password admin must be changed per SIMATIC security guidelines.
  4. Under Runtime settings > Services > Web server confirm that the service starts automatically.
  5. Download the project to the panel and restart runtime.
  6. From the engineering PC, browse to http://192.168.0.20/. Login, then click File browser. CSV files appear under Storage Card SD\Reports\. Right-click any file to download.

Automatic Push to a Windows Share

If pulling files interactively is impractical, schedule the panel to push the CSV to a Windows share:

  1. On the engineering PC create the folder D:\HMIReports and share it as HMIReports with read/write permission for the HMI service account.
  2. Allow the SMB service through Windows Firewall (File and Printer Sharing (SMB-In) rules).
  3. On the Comfort Panel, the VBS code in PushDailyCSV_ToShare above performs the copy using standard UNC paths. Authenticate using stored credentials if the share requires them: from WinCC V16 onward store credentials in the panel's User management > Passwords and reference them via Network.Connect.
  4. Schedule the push on a second 24-hour timer offset by five minutes from the export trigger.
SMB1 limitation: WinCC Comfort Panels connect to SMB shares using SMB 1.0/CIFS. Disable SMBv1 on the Windows host only after confirming the panel firmware supports SMB2/3. Comfort Panels with firmware V16 or later can be configured for SMB2 through the registry tag SMB2Enable = 1. See the firmware release notes at SIMATIC Customer Support.

Verification and Commissioning

After download to the panel, validate the chain end-to-end:

  1. Force the DailyExportTrigger tag from the PLC watch table and confirm one new row is appended to \Storage Card SD\Reports\Report_yyyy-mm-dd.csv.
  2. From the engineering PC browse http://192.168.0.20/, log in, and download the CSV. Open in Excel with delimiter = ;.
  3. Trigger the push routine and confirm the file appears in \\192.168.0.100\HMIReports\.
  4. Verify the integrity checksum: the file size on the share must equal the file size on the SD card within 1 KB.
  5. Check the panel diagnostic buffer for VBS runtime errors under Control Panel > System > System Information > Runtime diagnostics.

Troubleshooting Matrix

Symptom Likely cause Remediation
VBS does not run on TP177B Hardware does not support VBS Migrate to TP700 Comfort or larger; CPU 1515 PC or MP 377.
File created but rows are empty Tag quality bad; PUT/GET disabled on S7-300 Enable Access via PUT/GET on each CPU; check connection status in HMI diagnostics.
Permission denied writing to SD card Card write-protected or folder missing Unlock SD; verify \Storage Card SD\ exists with read/write.
Miniweb returns 404 for file browser Web server started without Enable file browser Re-enable in TIA Portal project and re-download.
SMB push fails with error 53 / 1326 UNC path not reachable; credentials missing Ping share from PC; configure stored credentials; ensure SMB2 enabled on host.
Unicode characters appear as ??? File opened in ANSI mode Open with OpenTextStream(ForAppending, TristateTrue) or convert with iconv.
CSV row uses dot decimal in EU locale No locale conversion in VBS Apply Replace(sLine, ".", ",") as in sample above.
Timer triggers multiple exports per day S7-300 TON not reset; double-edge event Reset DailyExportTrigger in OB100 / startup; use rising edge event filter.

Performance and Sizing Notes

A Comfort Panel TP1200 with one daily CSV append executes in under 250 ms. Sustained logging (1 row per minute) produces ≈ 1.5 MB per month; the 2 GB SD card holds ≈ 11 years of daily files, or 8 years of 5-minute files at the same size. SMB push to a Windows 10 share over a 100 Mbit/s link typically sustains 8-10 MB/s for sequential writes; the daily push is therefore dominated by SMB session setup (≈ 800 ms) rather than data transfer.

Migration Path from TP177B

Existing projects written in WinCC Flexible 2008 SP3 can be migrated to TIA Portal V16 using the Migrate project wizard. VBS survives the migration with the following caveats:

  • References to HMIRuntime remain compatible.
  • References to SmartTags require a project recompile; tag names must match exactly.
  • WinCC Flexible archives (CSV with header lines) must be converted to Comfort Panel Logs via the wizard or re-implemented with the VBS pattern above.

FAQ

Can the TP177B run VB scripts at all?

No. The TP177B 4" and 6" panels run WinCC Flexible 2008 SP3 with a script engine limited to the predefined Functions tab. VBS requires a Comfort Panel (TP700+) or a Multi Panel (MP 277/377). For a full feature matrix, see the SIMATIC HMI operator panel comparison.

Which Siemens HMI is best for daily CSV export from three S7-300 PLCs?

The TP1200 Comfort (6AV2 124-1MC01-0AX0) with a 32 GB SD card is the standard pick. It supports VBS, the Miniweb file browser, and three concurrent S7 connections out of the box.

How do I retrieve CSV files from the Comfort Panel remotely?

Two supported ways: open http://<panel-ip>/ in a browser, log in, and download via the integrated file browser; or push the file automatically to a Windows SMB share using a VBS routine as shown in the sample above.

Can the engineering PC read the panel's file system without a browser?

No. The Comfort Panel does not run an inbound SMB or FTP server. File access from the PC must go through the Miniweb HTTP file browser or be initiated by a VBS push from the panel itself.

How do I trigger the export once per day from the S7-300?

Use a TON timer with PT = 86 400 000 ms and a self-resetting counter, or use the CPU's time-of-day interrupt OB10 to set a bit in DB100 at a configured hour. Map that bit to an HMI tag and bind it as a rising-edge value-change event to the export VBS routine.

Back to blog