Overview
Siemens MP277 operator panels running Windows CE 5.0 and engineered with WinCC Flexible 2008 (SP2 through SP5) provide a VBScript runtime that allows the HMI application to write tag values directly to comma-separated value (CSV) files. The most common field request is to give each saved file a time-stamped name so that successive runs of the same script produce an independent log file rather than overwriting a single hard-coded path. The challenge is that the panel's local VBScript Now function returns a value containing the : separator (e.g., 10:22:55), which is illegal in Windows file systems.
This reference covers the full path from the original problem statement (a panel script writing three tags A, B, C to \flash\AA.csv) through the corrected implementation, including the official Siemens support references for the FileCtl.File object, time/date masking, network path redirection, and a clean migration path into TIA Portal WinCC scripting for the SIMATIC Comfort Panel successors.
Prerequisites
- SIMATIC MP277 (8" or 10") operator panel, or equivalent 270/277 series panel, firmware V12.02.00 or later (Windows CE 5.0 image).
- WinCC Flexible 2008 SP5 (the final service pack that supports the MP277) or WinCC Flexible 2008 SP3/SP4 with the corresponding HSPs installed.
- A configured HMI project with at least three tags (
A,B,Cin the example) declared in the tag table of typeInt,Real, orString. - VBScript editor access within the project: Project > Scripts > VB Scripts.
- For network export, an Ethernet connection from the MP277 to a Windows PC sharing a folder, with read/write permission for the user account under which the panel is logging on. The MP277 does not support username/password authentication against the share without an additional configuration entry (see the Siemens FAQ 26106418 referenced for legacy panel scripting).
- For TIA Portal migration: TIA Portal V15.1 or later with WinCC Comfort/Advanced, and the migration tool Project > Migrate project if the existing WinCC Flexible project is being converted.
The Original Script and Why It Overwrites
The starting script posted in the source is functional but stores every sample in a single fixed path. The body of the script runs in the WinCC Flexible Runtime's VBScript host; the panel's SmartTags collection is the gateway to tag values, and the FileCtl.File ActiveX is the gateway to the local file system on the CE 5.0 image.
' Original script - fixed filename, no timestamp
Dim L1, L2, L3
L1 = HmiRuntime.SmartTags("A")
L2 = HmiRuntime.SmartTags("B")
L3 = HmiRuntime.SmartTags("C")
Dim fso, path
path = "\flash\AA.csv"
Set fso = CreateObject("FileCtl.File")
fso.Open path, 2 ' 2 = modeWrite (append is modeAppend = 8)
fso.WriteFields L1
fso.WriteFields L2
fso.WriteFields L3
fso.Close
Set fso = Nothing
On every execution the file at \flash\AA.csv is opened in write mode. FileCtl.Open on the MP277 resets the file pointer to the beginning of the file and replaces any existing content; only modeAppend = 8 preserves prior records. This is the first correction to apply whenever the goal is archival logging rather than a single live snapshot.
Naming Files with Time Components
VBScript exposes a number of date/time functions through its runtime. On Windows CE 5.0 the panel returns the current local time in the regional format configured under Control Panel > Regional Settings. The three most reliable techniques for the MP277 are documented below.
Method 1 - Direct concatenation of the Now string
path = "\flash\" & Now & ".csv"
This returns a string such as \flash\2/14/2025 10:22:55 AM.csv. It works inside the CE 5.0 file system because the \flash\ mount does not enforce the Windows reserved-character rules that apply to FAT, NTFS, or SMB shares. The drawback is that the resulting file name contains slashes and spaces, which complicates later parsing on a PC.
Method 2 - Mask the trailing eight characters
path = "\flash\" & Right(Now, 8) & ".csv"
Because Now is formatted as MM/DD/YYYY HH:MM:SS (24 characters) on the default US locale, Right(Now, 8) extracts the trailing HH:MM:SS portion. This produces a usable file name on the panel, but the colon is still present, which is the root cause of the source question: Windows XP/Vista/7/10 file systems reject the colon when the file is later copied to a PC share.
Method 3 - Build the time from individual parts (recommended)
path = "\flash\" & Hour(Now) & "_" & Minute(Now) & "_" & Second(Now) & ".csv"
The output for an execution at 10:22:55 is \flash\10_22_55.csv. This satisfies both the panel's file system and any subsequent Windows file system that the file may be copied to. The underscore separator is preferred over the dot because Windows relies on the final dot to detect the file extension.
Method 4 - Combine date and time for unique daily names
Dim ts
ts = Year(Now) & "-" & _
Right("0" & Month(Now), 2) & "-" & _
Right("0" & Day(Now), 2) & "_" & _
Right("0" & Hour(Now), 2) & "-" & _
Right("0" & Minute(Now), 2) & "-" & _
Right("0" & Second(Now), 2)
path = "\flash\" & ts & ".csv"
This generates an ISO-style sortable name such as 2025-02-14_10-22-55.csv. Leading zeros are forced by the Right("0" & x, 2) pattern because Month(Now) returns a non-padded integer on CE 5.0. ISO 8601 ordering means directory listings sort chronologically on the Windows side without renaming.
Method 5 - FormatDateTime with named constants
path = "\flash\" & FormatDateTime(Now, vbShortTime) & ".csv"
On a CE 5.0 panel the result is 10:22; combined with a second pass on the seconds field you can rebuild an un-punctuated name. Note that FormatDateTime is locale-sensitive and may produce unexpected punctuation on a panel configured for a non-US regional setting - this is why Method 3 is the safest production choice.
Fixing the Windows File-System Restriction
The Windows file systems (FAT16/FAT32 on storage cards, NTFS on the destination PC, SMB on the network share) reserve the following characters and reject them inside a file name: < > : " / \ | ? *. ASCII codepoints 0-31 are also prohibited. The colon in particular is reserved by the DOS file system dating from the original IBM PC, and is reinforced by the Win32 layer on every supported Windows version.
The corrected full script that produces Windows-safe files is shown below. The path uses \flash\ (the internal persistent storage of the MP277). For archival volumes use \Storage Card\ when an SD card is fitted, but be aware that the CE 5.0 image only mounts the first FAT16 partition and limits the path length to 256 characters including the file name.
' Time-stamped CSV write - Windows-safe filename, append mode
Dim L1, L2, L3
L1 = HmiRuntime.SmartTags("A")
L2 = HmiRuntime.SmartTags("B")
L3 = HmiRuntime.SmartTags("C")
Dim fso, path
Dim h, m, s
h = Right("0" & Hour(Now), 2)
m = Right("0" & Minute(Now), 2)
s = Right("0" & Second(Now), 2)
path = "\flash\" & h & "_" & m & "_" & s & ".csv"
Set fso = CreateObject("FileCtl.File")
fso.LineSeparator = ";" ' CSV field separator (WinCC default on MP277)
' 8 = modeAppend (preserve prior records), 2 = modeWrite (overwrite)
' For continuous logging use 8; for snapshot-per-file use 2
fso.Open path, 8
fso.WriteFields L1
fso.WriteFields L2
fso.WriteFields L3
fso.Close
Set fso = Nothing
Sending the CSV to a PC over Ethernet
The panel's CE 5.0 image can reach SMB shares on a PC, but the implementation does not support a credentialed logon dialog. The standard Siemens-documented procedure is to keep the file on the panel under \flash\ and use the panel's own services to copy it out at the end of a shift.
Option A - Sm@rtService / Sm@rtServer file transfer
Enable Sm@rtService in the panel properties and connect from a PC using Internet Explorer or the Sm@rtClient. The operator can browse the \flash\ tree and download the CSVs. The service uses HTTP on port 80 (or 1024+ as configured) and does not require a username; restrict access by IP allow-list in Control Panel > Network > Sm@rtService.
Option B - Network share with anonymous mapping
Configure the PC share to allow Everyone: Full Control with NTFS permissions mirroring that, then use the FileCtl copy function on the panel. Siemens' WinCC Flexible FAQ 26106418 documents the exact object invocation. The path syntax for a UNC target from the panel is:
path = "\\SERVER\share\" & h & "_" & m & "_" & s & ".csv"
Note the doubled backslashes; the first pair escapes the literal backslash, the second pair is the UNC path separator. If the share requires a credential, you must use the Configure_NetShare dialog on the panel (English CE 5.0 image only) or set the registry key HKEY_LOCAL_MACHINE\Services\SMB\Parameters\UseDefaultUser on the panel to inject a fixed account.
Option C - FTP push
Run a small FTP server on the PC (e.g., FileZilla Server) and have the panel push the CSV via the FTP OCX. The colon is rejected by NTFS, so the panel-side name masking is still required before the push.
Option D - Scheduled copy using the panel scheduler
Siemens' FAQ 13336639 covers a script-based scheduler that copies files from \flash\ to an SD card or to a network target every N minutes. Combine it with a 10-minute Schedule in WinCC Flexible that triggers the script and you reproduce the "save every 10 min, named by time" workflow asked in the source.
FileCtl.File Method Reference
The FileCtl.File object exposed by WinCC Flexible on the MP277 is a thin wrapper around the CE 5.0 file APIs. The following table documents the members that the source script and its variants depend on.
| Member | Type | Description |
|---|---|---|
Open(path, mode) |
Method | Opens a file. mode values: 1=modeRead, 2=modeWrite (truncate), 8=modeAppend. 32=modeCreate (fail if exists). |
Close |
Method | Closes the file handle and flushes buffers. |
WriteFields value [, value ...] |
Method | Writes a CSV record. Each value is separated by the current LineSeparator value followed by the separator configured in Project > Runtime Settings > Files. |
LineSeparator |
Property | Field separator string. Default is ";" on most locales. Change to "," for true CSV output. |
FileName |
Property | Read-only string returning the currently open path. Useful for diagnostic logging. |
EOF |
Property | Boolean, true when read pointer is at end of file. Used by reader scripts. |
InputString |
Property | Reads next record when the file was opened with modeRead. |
Length |
Property | Long, size in bytes of the open file. |
The full property/method set is enumerated in the WinCC Flexible 2008 SP5 online help under Programming > Reference > VBScript Reference > Objects > FileCtl.
Scheduled Logging Every 10 Minutes
To reproduce the "save every 10 minutes, name the file by time" requirement:
- Open the WinCC Flexible project and select Schedules.
- Add a new schedule named
LogEvery10Minwith trigger Periodic at00:10:00. - Bind the schedule's On Trigger event to the script that contains the corrected body above.
- For the example tags
A,B,C, ensure they are Continuous acquisition tags with a 1 s update so that every 10-minute sample is meaningful. - To avoid duplicate file names when the trigger fires at the same wall-clock minute twice, append the schedule's ID using
FormatandDay(Now)so the file name includes the day:\flash\<YYYYMMDD>_<HHMMSS>.csv. - Stop the schedule with the HMI tag
StopLoggingif you need a clean run-up/shut-down at shift change.
Reading the Logged CSV Back from the Panel
Once a CSV is on the panel, the same FileCtl.File object reads it back into tag values for display. A typical reading script mirrors the writer:
Dim fso, path
path = "\flash\last.csv"
Set fso = CreateObject("FileCtl.File")
fso.LineSeparator = ";"
If fso.FileName = "" Then
fso.Open path, 1 ' modeRead
End If
If Not fso.EOF Then
Dim rec
rec = fso.InputString
SmartTags("LastA") = Split(rec, ";")(0)
SmartTags("LastB") = Split(rec, ";")(1)
SmartTags("LastC") = Split(rec, ";")(2)
End If
fso.Close
Set fso = Nothing
Migrating the Script to TIA Portal WinCC
Newer SIMATIC Comfort Panels (TP700/900/1200/1500, KP1500) run the same VBScript dialect under TIA Portal WinCC. The Siemens support entry 106501825 titled "How do you store data with a script in a file with WinCC (TIA Portal) PC Runtime?" documents the modern API and the relevant runtime settings. The key adaptations are:
- The ActiveX object is still
FileCtl.File; the syntax shown above is portable. The path root for the internal storage is\flash\on a Comfort Panel andC:\ProgramData\Siemens\Automation\WinCCRT\on a PC Runtime. - Tag access is the same:
SmartTags("A")still resolves, but the newer runtime also supportsHmiRuntime.SmartTags("A")interchangeably. - The line separator defaults to
;in most regional builds. To produce strict RFC 4180 CSV output, setfso.LineSeparator = ","and add a manualfso.Writefor the line terminator. - For TIA Portal V18 and later the panel's Recipes & Logging object can be used as a higher-level alternative to
FileCtl; it adds structured columns, auto-indexing, and integrated viewer controls.
Troubleshooting Matrix
| Symptom | Likely Cause | Fix |
|---|---|---|
| File is empty after script run |
fso.Open called in modeWrite and the script halted before WriteFields
|
Switch to modeAppend = 8 and verify WriteFields arguments are scalar values, not arrays |
File name contains : on the PC |
Using Right(Now, 8) without masking |
Use Hour/Minute/Second with the underscore separator pattern |
| "Path not found" on UNC copy | CE 5.0 has no SMB credential for the share | Map an anonymous share, or use Sm@rtService for the transfer |
| Script does not run at the scheduled time | Panel project is in Stop or RT is closed | Check Project > Runtime > Scheduler > Status; the Status tag @ServerState should be 4 (running) |
CreateObject("FileCtl.File") returns error |
VBScript runtime is not enabled in the project | Project > Runtime Settings > Services > enable VBScript |
CSV has ; as the separator, third-party tool fails |
WinCC default is ; in the EU regional build |
Set fso.LineSeparator = "," at the top of the script |
| Duplicate file name across runs | Schedule fires twice in the same second | Add Millisecond (CE 5.0 returns ticks, convert with Right("00" & Timer Mod 1000, 3)) or change the schedule to 11 minutes |
| Slow file open with thousands of records | Append mode is re-reading the directory entry on each open | Open once, write multiple lines, then close. Use a single WriteFields L1, L2, L3 with comma args for batch writes |
Verification Procedure
After deploying the script, run the following checks before going to production:
- Trigger the schedule manually via the panel's Service > Trigger Schedule and confirm a new file appears in
\flash\within one polling cycle of the runtime. - Open the resulting file with Notepad and confirm the time stamp in the file name matches the panel's Control Panel > Date/Time at the moment of trigger.
- Copy the file to a Windows share using Sm@rtService. The transfer must succeed without renaming, proving the colon is no longer in the name.
- Open the file in Excel using the comma separator; the values of
A,B,Cmust appear in three distinct columns. - Re-trigger the schedule ten minutes later; a second file with a different time stamp must appear, and the first file must be unchanged (proving append semantics for other loggers in the same project).
- Force a power-cycle of the panel. After reboot the files must still be present in
\flash\and the schedule must resume within the configured runtime recovery window (default 30 s).
FAQ
Why does my MP277 script create a file with a colon in the name on the panel but fail to copy to a Windows PC?
The MP277's internal flash uses a Windows CE 5.0 file system that tolerates the colon, but the destination PC's NTFS, FAT, or SMB file system rejects the reserved character. Always mask the timestamp with Hour(Now), Minute(Now), Second(Now) joined by an underscore before the file leaves the panel.
How do I make every execution of the script produce a different file name?
Build the file name from the current time components instead of a literal string. The recommended pattern is "\flash\" & Hour(Now) & "_" & Minute(Now) & "_" & Second(Now) & ".csv". Add the day or millisecond suffix if your schedule fires faster than once per second.
Can I save the CSV directly to a network share from the panel?
Yes, using a UNC path such as \\server\share\<name>.csv, but the MP277's CE 5.0 image does not support a credentialed logon dialog. The share must allow anonymous write access, or you must push the credentials through the registry. Refer to Siemens FAQ 26106418 for the full procedure and the older 13336639 for the script-driven copy scheduler.
What is the difference between FileCtl.File on WinCC Flexible and on TIA Portal WinCC?
The object and its methods are essentially the same on both runtimes. The differences are the storage path root (\flash\ on a panel, C:\ProgramData\Siemens\Automation\WinCCRT\ on a PC Runtime) and the line-separator default. The official Siemens support entry 106501825 documents the modern API and the additional structured logging options available in TIA Portal V18 and later.
How do I run the CSV save script every 10 minutes automatically?
Create a Schedule in WinCC Flexible with a periodic trigger of 10 minutes, then bind the schedule's On Trigger event to your script. For a PC Runtime, use the Windows Task Scheduler calling a launcher that triggers the script via the WinCC OLE interface. Always include a millisecond or day suffix in the file name to prevent collisions if the trigger is fired manually in addition to the schedule.