Overview
The Siemens SIMATIC MP277 Multi Panel runs Windows CE 5.0 and supports VBScript for runtime automation. Writing text files from the panel — for datalogging, recipe export, alarm archiving, or audit trails — uses the bundled MSCEFile.dll COM library that exposes FileCtl.FileSystem and FileCtl.File automation objects. This reference covers the exact syntax, file open modes, path conventions, error handling, and verification steps required to write reliable text files from an MP277 panel project configured in WinCC flexible 2008 SP3 or TIA Portal V13 SP1+ WinCC Comfort/Advanced.
The MP277 differs from a desktop PC: only the Windows CE file system is accessible through MSCEFile.dll. The same VBScript code will not run on a WinCC Runtime Professional station running Windows 7/10/11, which instead uses the standard FileSystemObject.CreateTextFile model.
Prerequisites
- SIMATIC MP277 panel — 6AV6 643-0CD01-1AX1 (8" Touch), 6AV6 643-0DD01-1AX1 (10" Touch), or 6AV6 643-0BA01-1AX1 (8" Key). All ship with Windows CE 5.0.
- WinCC flexible 2008 SP3 (for legacy projects) or TIA Portal V13 SP1+ with WinCC Comfort/Advanced (for migrated projects).
- Storage media: built-in Flash (~6 MB free after image) or CF card inserted in slot 1. CF cards up to 2 GB formatted FAT16 are supported.
- VBScript familiarity at the WinCC flexible scripting level — runtime scripts support a subset of VBScript 5.x without
Wscript.ShellorWScript.Network. - Panel transfer cable or Ethernet connection for downloading the compiled HMI project.
- Remote-control channel (CEBC) or VNC server enabled on the panel for runtime verification.
\Windows or \Hard Disk; only mounted volumes such as \Flash and \Storage Card are writable at runtime.Understanding the File System on MP277
The MP277's Windows CE image presents a hierarchical file system that differs from desktop Windows. Paths always start with a backslash; forward slashes are accepted interchangeably. The default mounted volumes are:
| Path | Mount Point | Writable at Runtime | Typical Use |
|---|---|---|---|
\Flash |
Internal flash disk | Yes (~6 MB free) | Configuration, recipe defaults, small logs |
\Storage Card |
CF card slot 1 | Yes | Persistent logs, large archives, swap space |
\Storage Card2 |
CF card slot 2 (10" only) | Yes | Backup, redundant logging |
\USB |
USB host port (limited) | Partial | Firmware update; not recommended for runtime I/O |
\Hard Disk |
System root | No (read-only) | OS binaries, MSCEFile.dll location |
\My Documents |
Virtual folder on Flash | Yes | Convenience location for operator-visible files |
Network drives mapped through the control panel appear as \server\share once DNS and the Workgroup are configured; VBScript can read from but cannot always write to UNC paths depending on the user context. See the network-access section below for the supported mechanism.
MSCEFile.dll Architecture
MSCEFile.dll ships in the MP277 image under \Windows\MSCEFile.dll and registers itself as a COM automation server during boot. Two objects are exposed to VBScript:
-
FILECTL.FileSystem — provides file-system queries such as
FileExists,GetFile,GetFolder,CreateFolder, andDeleteFile. -
FILECTL.File — provides sequential text-file I/O including
Open,LinePrint,LineInputString,EOF,Close,Kill, andSeek.
Both objects are created with the standard CreateObject syntax:
' Create FileSystem object for WinCE
Set filesys = CreateObject("FILECTL.FileSystem")
' Create File object for WinCE
Set logFile = CreateObject("FILECTL.File")
The FILECTL.File object is the equivalent of a Visual Basic 6 Scripting.TextStream, but its syntax is older and uses integer mode flags rather than the string constants ForReading/ForAppending used by the desktop FileSystemObject.
Step-by-Step: Creating and Writing a Text File
- Add a script to your HMI project. In WinCC flexible, right-click the screen or scheduler that should trigger the write and select "Properties → Events → Click" (for buttons) or "Value change" (for tag events). Choose VBScript as the action type.
- Declare the object variables. The runtime instance lifetime is per-call; declare inside the subroutine to avoid leaks.
-
Resolve the target path. Use
FILECTL.FileSystem.FileExiststo test before opening if you want conditional logic. - Open the file with the correct mode. See the mode table below; mode 8 (append) is the safest default for datalogging because it never destroys existing data.
- Write the line using LinePrint. The method appends a CRLF automatically.
- Close the file and clear the references. Failing to close will lock the file until the panel reboots.
-
Add an error handler. Wrap the body in
On Error Resume Nextand inspectErr.Numberafterwards; surface the result to a tag so it can be alarm-logged.
Minimal working example for a button click on an MP277 8" Touch panel:
' VBScript - WinCC flexible / TIA Portal WinCC Comfort
' Trigger: Button "Log Event" - Click event
Dim sPath, sFile, sLine
Dim filesys, logFile
' --- Configuration ---
sPath = "\Flash\My Documents\" ' Writable location
sFile = "TestLog.txt"
' --- Build a tab-separated line ---
sLine = Now & vbTab & _
SmartTags("Machine.State") & vbTab & _
SmartTags("Production.Counter")
On Error Resume Next
Set filesys = CreateObject("FILECTL.FileSystem")
Set logFile = CreateObject("FILECTL.File")
' Mode 8 = Open for appending (create if missing)
logFile.Open sPath & sFile, 8
If Err.Number = 0 Then
logFile.LinePrint(sLine)
logFile.Close
SmartTags("Logging.LastStatus") = 1 ' OK
Else
SmartTags("Logging.LastStatus") = Err.Number
SmartTags("Logging.LastError") = Err.Description
End If
Set logFile = Nothing
Set filesys = Nothing
On Error Goto 0
File Open Mode Reference
The integer passed as the second argument to File.Open selects the access mode. The following values are documented in MSCEFile.dll:
| Mode | Behavior | Use Case |
|---|---|---|
| 1 | Open for reading | Read recipe or parameter list |
| 2 | Open for writing (create or truncate) | Overwrite snapshot file each cycle |
| 4 | Open for random reading | Binary file with fixed record length |
| 8 | Open for appending (create if not present) | Datalogging — preferred default |
| 16 | Open for binary random access | Avoid for text; line endings corrupt |
| 32 | Open for output (create or truncate, write-only) | Export reports |
If filesys.FileExists(path) Then filesys.DeleteFile path or use a dated filename pattern to avoid silent data loss.Path Conventions and Storage Options
Always prefer \Storage Card\Logs\ over \Flash\ when the log will exceed ~1 MB, because the internal flash has limited write endurance. Create a dedicated subfolder with FILECTL.FileSystem.CreateFolder on first run:
If Not filesys.FileExists("\Storage Card\Logs\") Then
filesys.CreateFolder "\Storage Card\Logs\"
End If
Use dated filenames to bound file size and simplify operator-side housekeeping:
sFile = "Batch_" & FormatDateTime(Now, vbShortDate) & ".csv"
sFile = Replace(sFile, "/", "-")
Cap each file to 1 MB with a size check before opening; FILECTL.FileSystem exposes GetFile(path).Size for this purpose.
Advanced: PLC-Triggered Datalogging with Timestamps
The most common production use case is logging every time a PLC tag toggles — for example, an "Operation Complete" bit. Combine a WinCC flexible scheduler (1 s polling) or a tag-event trigger with the VBScript above:
' Scheduler "DatalogTick" - runs every 1000 ms
Dim fso, f
Set fso = CreateObject("FILECTL.FileSystem")
Set f = CreateObject("FILECTL.File")
If SmartTags("PLC.NewBatch") = 1 Then
SmartTags("PLC.NewBatch") = 0 ' acknowledge
f.Open "\Storage Card\Logs\Batches.csv", 8
f.LinePrint FormatDateTime(Now, vbShortTime) & "," & _
SmartTags("PLC.BatchID") & "," & _
SmartTags("PLC.ResultCode")
f.Close
End If
Set f = Nothing
Set fso = Nothing
For high-frequency events (>5 Hz), switch the logging to the PLC side using a S7 data block and transfer the block image at end-of-shift via an FTP push; the MP277 VBScript runtime is single-threaded and a 200 ms file write blocks HMI update cycles.
Accessing PC Shared Folders from the Panel
The MP277 cannot browse a Windows network neighborhood by default, but it can access a UNC share if the panel's hostname is registered on the DNS server (often the engineering PC) and the PC's hosts file contains the panel name. Siemens documents this in Siemens Support Entry 13336639 under "How do you access the network drive of a PC from an HMI panel?".
- Configure the PC's network adapter to share the folder with read/write permission for the panel service account.
- Add the panel's hostname-to-IP mapping to
C:\Windows\System32\drivers\etc\hostson the PC (e.g.192.168.0.10 MP277). - On the panel, open Control Panel → Network and configure the DNS server to point at the PC acting as the WINS resolver.
- In VBScript, use the UNC path:
f.Open "\\PC-NAME\SharedLogs\Line01.csv", 8. Computer name, not IP address, is required.
Error Handling and Diagnostics
Failures fall into three categories on the MP277:
| Symptom | Likely Cause | Remedy |
|---|---|---|
Err.Number = 53 "File not found" |
Path misspelled or folder missing | Create folder with FileSystem first |
Err.Number = 70 "Permission denied" |
File still open from previous call | Always close and set to Nothing |
Err.Number = 76 "Path not found" |
CF card removed or full | Monitor free space with FileSystem.GetFolder |
| File appears empty | LinePrint buffered until Close | Always call Close after LinePrint |
| Slow HMI response | Large file written in main thread | Move to scheduler, batch every N records |
Surface Err.Number and Err.Description to HMI tags so they can be archived in the alarm log; this provides an audit trail of logging failures.
Verification
- Compile and download the project to the panel.
- Connect via CEBC: start ProSave, select Ethernet, point at the panel IP, and click "File Browser".
- Navigate to
\Flash\My Documents\or\Storage Card\Logs\and confirm the new file exists. - Transfer the file via ProSave's "Receive" button and inspect with Notepad — line endings must be CRLF and the timestamp must match the panel clock.
- Repeat for the error path: remove the CF card, trigger the script, confirm
Logging.LastStatusshows a non-zero value and the alarm is raised. - Power-cycle the panel and confirm the file persisted. If it disappeared, you wrote to
\Hard Diskinstead of\Storage Card.
Limitations and Best Practices
- Single threading. The WinCC flexible / WinCC Comfort runtime uses one scripting thread; long writes block tag polling. Keep individual writes under 50 ms or batch them.
-
No Unicode in CE 5.0. MSCEFile.dll writes ANSI; for non-ASCII characters (e.g. Cyrillic) use a UNICODE-aware library or escape them as
\uXXXX. -
No transactional safety. A power loss during
LinePrintcorrupts the file. For audit-grade logs, write to a temporary file and rename atomically usingFILECTL.FileSystem. -
CF card format. FAT16 only, max 2 GB. Format with Windows
format X: /FS:FAT /Q; FAT32 cards over 4 GB are not recognized. - Wear leveling. Internal flash supports roughly 100,000 write cycles per sector. For high-frequency logging, rotate files hourly and always use CF.
- Security. Files are world-readable from CEBC. If the data is sensitive, encrypt with a PLC-side AES routine and write the ciphertext only.
-
Migration. Projects moved to TIA Portal V16+ WinCC Unified use JavaScript and the Node.js
fsmodule; the MSCEFile.dll approach applies only to Comfort/Advanced panels on Windows CE.
FAQ
Can I use the same VBScript on a WinCC Runtime PC instead of the MP277?
No. Windows desktop runtime uses standard VBScript with FileSystemObject.CreateTextFile rather than FILECTL.File. The MSCEFile.dll is only registered on Windows CE panels.
Why does my file write succeed but the file is empty on disk?
MSCEFile.dll buffers text until File.Close is called. If the script terminates abnormally (uncaught error, panel reboot), the buffer is lost. Always call Close in the success path and again in an error handler.
What is the maximum file size on the internal flash?
The free space on \Flash after the image loads is roughly 6 MB on an 8" MP277 and slightly less on 10" units. Use a CF card on \Storage Card for logs larger than 1 MB.
How do I avoid hitting the 100,000-write limit on internal flash?
Write to the CF card, rotate to a new filename each hour, and enable the panel's screen saver to suspend unnecessary tag polling. Avoid using the same filename with mode 8 (append) in a tight loop.
Is there a way to write CSV that opens directly in Excel?
Yes. Use vbTab or a comma delimiter, ensure CRLF line endings (the LinePrint default), and write a header row on first creation. Save with a .csv extension; Excel recognizes the separator automatically under most regional settings.