ProTool Archive: Save with Date/Time Filename Using VBScript

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

ProTool V6.0: Save Archives with Date/Time Filenames via VBScript

ProTool V6.0 (and the ProTool/Pro runtime that ships with later SIMATIC Panels) writes cycled message and tag archives to a fixed file name pattern such as ARCHIV_10.CSV, ARCHIV_11.CSV, and so on. The numeric suffix is rotated by the runtime, but the stem never changes, which makes it impossible to identify a specific dump file by inspection. This article shows how to close the active archive on demand and write a copy to a path that embeds the system date and time, using the built-in CopyLog function from the ProTool V6.0 VBScript library. The technique requires the optional Automation Value Card (AVC) hardware option or an equivalent writable storage path, and is documented in the Siemens support entry 13355716.

Software scope. All paths, dialog labels, and ActiveX object names in this article refer to ProTool V6.0 + SP3 (the last released service pack for the classic ProTool configuration tool) and the corresponding ProTool/Pro RT runtime that ships on OP/MP/TP 170/270/370 panels and WinCC flexible Compact panels. If you are using TIA Portal / WinCC Unified you should migrate to the "Logging" tag model — the CopyLog VBScript API does not exist in TIA Portal V17 and later.

1. Problem Definition

Symptoms observed in the field on ProTool V6.0 projects:

  • Every archive dump ends up at \Storage Card\PROTOOL\Archives\ARCHIV_10.CSV (or 11, 12, … depending on rotation).
  • The runtime overwrites the file on the next dump cycle, so the operator cannot retrieve the previous shift's data without stopping the panel.
  • Auditors and quality engineers require an archive file whose name contains at least the calendar date and, ideally, the time of creation.
  • The default behaviour cannot be changed from the ProTool archive dialog because the file stem is hard-coded in the runtime.

The supported workaround is to leave the ProTool archive mechanism untouched and add a VBScript function that runs on a button press, on a tag change, or on a scheduled event. The script calls CopyLog, which closes the active archive, copies it to a user-defined path that includes Year(Date), Month(Date), Day(Date), Hour(Time), Minute(Time), and then re-opens a fresh archive for the runtime.

2. Prerequisites

Item Requirement
Configuration tool ProTool V6.0 + SP3 (build 6.0.5.13 or later). Earlier SPs lack the VBScript editor toolbar.
Runtime target Any OP 170, OP 270, OP 370, MP 270, MP 370, TP 170, TP 270, TP 370 panel, or the ProTool/Pro RT on a Windows PC.
Storage Automation Value Card (AVC) — 32 MB, 64 MB, or 128 MB — or a writable PCMCIA / CompactFlash path.
Licensing ProTool/Pro V6.0 license; the AVC activates the ProAgent/VBScript option on the panel.
Knowledge Familiarity with the ProTool V6.0 manual, Chapter 5.14 ("Creating VB scripts"), and the SIMATIC HMI ProTool/Pro V6.0 user manual.
Reference Siemens support entry 13355716 for the example project download.
AVC dependency. VBScript functions and the CopyLog method are only available at runtime when the panel detects an authorised AVC. Without a card, the script interpreter loads, but any call into the archive subsystem returns error -1 ("Function not available"). Refer to entry 5155752 for the basic archive setup that must be completed before the script will work.

3. ProTool V6.0 Archive Architecture

Understanding the file layout is essential before you write the renaming script. A ProTool project that archives tags and messages produces the following directory tree on the storage card:

\Storage Card\PROTOOL\
├── PROJECT.PTL              (compiled runtime, binary)
├── Archives\
│   ├── ARCHIV_10.CSV        (current tag archive, ring buffer index = 10)
│   ├── ARCHIV_11.CSV        (rotated predecessor)
│   ├── ARCHIV_12.CSV        (oldest, gets overwritten next)
│   ├── MSGARCH_10.CSV       (message archive)
│   └── MSGARCH_11.CSV
└── Logs\
    └── EVENT.LOG

The numeric suffix is controlled by the "Number of backup files" field in Archive → Settings. ProTool increments the suffix and wraps; it does not embed any date metadata. The CopyLog function is the only supported public API that allows user code to interact with this file set.

According to Siemens FAQ 5155752, archives are created with a double-click on the Archive folder in the project tree. From the resulting dialog you define the storage location, the segment size, the trigger (cyclic, time-of-day, or tag-edge), and the column layout for tag archives. Message archives require a logging message class to be assigned under Messages → Classes.

4. The CopyLog VBScript API

The signature exposed by the ProTool/Pro V6.0 scripting layer is:

Function CopyLog(sSourcePath As String, sDestPath As String) As Long

Behaviour:

  1. The runtime flushes the active archive buffer to sSourcePath.
  2. The closed file is copied byte-for-byte to sDestPath.
  3. A new, empty archive is opened at sSourcePath so the running HMI does not lose any subsequent samples.
  4. The return value is 0 on success or a non-zero error code (see Section 9) on failure.

The function is synchronous; control returns to the script only after the copy completes. Typical copy time for a 1 MB CSV archive on an OP 270 with a 64 MB AVC is between 800 ms and 1.4 s.

5. Step-by-Step: Embed Date and Time in the Archive Name

5.1 Create the script in ProTool

  1. Open the ProTool V6.0 project, expand the project tree, and right-click Functions → Scripts.
  2. Select New → VBScript. Name it, for example, SaveArchiveWithTimestamp.
  3. Paste the code block below into the editor. The format string is built with explicit zero-padding so that file names sort lexicographically.
' ProTool V6.0 — SaveArchiveWithTimestamp.vbs
' Closes the active tag archive and copies it to a date-stamped
' CSV on the Automation Value Card. Requires AVC and ProTool/Pro
' runtime build ≥ 6.0.5.13.

Option Explicit

Const SRC_PATH = "\Storage Card\PROTOOL\Archives\ARCHIV_10.CSV"
Const DST_DIR  = "\Storage Card\PROTOOL\Archives\History\"

Dim rc, fso, ts, sFile

' --- Build filename: 2024-05-17_14-32-07_Stop_42.csv
sFile = DST_DIR _
      & Year(Date) & "-" _
      & Right("0" & Month(Date),  2) & "-" _
      & Right("0" & Day(Date),    2) & "_" _
      & Right("0" & Hour(Time),   2) & "-" _
      & Right("0" & Minute(Time), 2) & "-" _
      & Right("0" & Second(Time), 2) & "_" _
      & "Stop_" & SmartTags("CurrentStopNo") & ".csv"

' --- Ensure target directory exists
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(DST_DIR) Then
    fso.CreateFolder DST_DIR
End If

' --- Flush, copy, reopen (CopyLog does all three)
rc = CopyLog(SRC_PATH, sFile)

' --- Optional: log the result to the system event archive
If rc = 0 Then
    SmartTags("LastArchiveFile") = sFile
    SmartTags("LastArchiveRC")   = 0
Else
    SmartTags("LastArchiveRC")   = rc
End If

Set fso = Nothing

5.2 Wire the script to a trigger

  1. Create a new button on any process screen. Set its Event → Press to Run Script → SaveArchiveWithTimestamp.
  2. Alternatively, add the script as a Scheduled function triggered by a tag edge on ShiftEnd.
  3. For fully automatic daily dumps, add a Time-of-day scheduled function that calls the same script at 23:59:00. The ProTool scheduler is configured under System → Scheduler.

5.3 Configure the archive target first

The script assumes that the primary archive (ARCHIV_10.CSV) is already being written by the ProTool runtime. If no archive is configured, the call to CopyLog returns immediately with an error. Complete the configuration described in Siemens entry 5155752 before deploying the script.

6. Automation Value Card (AVC) — What It Adds

The AVC is a PCMCIA card (or CompactFlash on later panels) that carries a licence key and an optional storage area. Three capacities were offered:

AVC variant Capacity Order number (6AV…) Notes
AVC 32 32 MB 6AV3 672-1CL00-0AA0 Original product, sufficient for ≤ 1 week of CSV archives.
AVC 64 64 MB 6AV3 672-1CM00-0AA0 Most common field installation.
AVC 128 128 MB 6AV3 672-1CN00-0AA0 For projects with multiple ring-buffer archives.

From a script perspective the AVC enables two things:

  1. Activation of the VBScript interpreter inside the runtime. Without an AVC the script objects in the project tree are present but cannot be executed.
  2. Writable storage that survives a power cycle, so a date-stamped copy is available after the panel reboots. Writing to internal RAM is volatile and is not recommended for compliance archives.

For PC-based ProTool/Pro RT installations the AVC is replaced by a software licence (dongle or licence file) and any local disk path can serve as the destination.

7. Date and Time Formatting Reference

VBScript expression Sample output (system clock 2024-05-17 14:32:07) Use case
Year(Date) 2024 Year-only directory bucket
Month(Date) 5 (no zero) Requires manual zero-pad if sort order matters
Right("0" & Month(Date), 2) 05 Preferred for sortable filenames
Hour(Time) … Second(Time) 14 : 32 : 07 Same zero-pad pattern
FormatDateTime(Now, vbGeneralDate) 5/17/2024 Locale-dependent — do not use in filenames
FormatDateTime(Now, vbShortTime) 2:32 PM Locale-dependent — do not use in filenames
Locale warning. FormatDateTime uses the panel's regional setting. On a panel configured for German locale it produces 17.05.2024, which collides with Windows file naming rules because of the dots. Always compose the filename with explicit numeric fields and a safe separator such as - or _.

8. Directory and File Hygiene

The script in Section 5 creates a History sub-folder. Over months of operation this folder can grow past the AVC capacity. Add a cleanup routine, e.g. delete files older than 90 days, by adding the following helper to the same script or a scheduled function:

' --- Prune files older than 90 days
Dim folder, file, dtCutoff
dtCutoff = DateAdd("d", -90, Date)
Set folder = fso.GetFolder(DST_DIR)
For Each file In folder.Files
    If file.DateLastModified < dtCutoff Then file.Delete True
Next
Set folder = Nothing

Test the cleanup at commissioning on a development card first — once a .Delete True runs, the CSV is unrecoverable.

9. Common Errors and Troubleshooting Matrix

Return code from CopyLog Likely cause Corrective action
0 Success No action.
-1 Function not available — no AVC inserted or licence missing Insert AVC; verify licence under Start → Control Panel → HMI License.
2 Source path does not exist or no archive configured Confirm archive setup per entry 5155752.
3 Destination path not writable Check write-protect tab on PCMCIA card; verify the path exists.
5 Disk full on AVC Reduce segment size, enable the 90-day cleanup, or move to AVC 128.
53 Invalid characters in destination filename Re-check that locale separators (dots, colons) are not used.
70 Permission denied Another ProTool process or FTP session holds the file open. Stop FTP transfer before triggering the script.

Surface the return code to a tag (LastArchiveRC) and to a status field on the operator screen so the cause is visible without attaching a ProTool debugger.

10. Verification

After the project is downloaded to the panel, perform the following acceptance test:

  1. Insert the AVC and start the runtime. Wait for at least one archive cycle so ARCHIV_10.CSV contains real data.
  2. Press the button wired to SaveArchiveWithTimestamp. The button event should return within 2 s on an OP 270.
  3. Open the History folder on the AVC over Ethernet (ProSave → Filebrowser) or by removing the card. Confirm a single file of the form 2024-05-17_14-32-07_Stop_42.csv exists.
  4. Open the CSV in Excel. The header row must match the columns configured under Archive → Column Layout.
  5. Verify that ARCHIV_10.CSV still exists and is being written to. The header is retained, and new samples appear at the bottom.
  6. Force a date rollover by changing the panel's system clock and re-trigger the script. The new file must sort after the previous one when listed alphabetically.
  7. Stop the FTP server (if used) and re-trigger the script to confirm the error path returns 0 once the lock is released.

11. Migration Notes to TIA Portal / WinCC Unified

The CopyLog VBScript function is not available in TIA Portal V13 or later. The supported replacement is the Logging subsystem in WinCC Unified / WinCC Comfort, where the runtime writes time-stamped .CSV or .SQLite files by default. The migration steps are:

  1. Export the ProTool tag list with Project → Export → Tag list (CSV) and import it into a TIA Portal HMI tag table.
  2. Create a WinCC Unified Data logger with the same cycle and storage path. The filename pattern is configurable directly — no scripting is required.
  3. Replace the VBScript button with a Scheduled task that triggers a "Close and rename log" job on the same trigger tag.

For shops that must stay on ProTool V6.0 indefinitely, the script-based approach described above is the only Siemens-supported method to obtain a date/time stamped archive filename.

12. FAQ

Does CopyLog work without an Automation Value Card?

No. On panel-based runtimes the VBScript interpreter and the CopyLog method are gated by a valid AVC licence. Without an AVC, the function returns -1 ("Function not available"). PC-based ProTool/Pro RT installations use a software licence and any writable local path is accepted as destination.

Can the script trigger a dump automatically at end of shift?

Yes. Add the script as a Scheduled function under System → Scheduler in ProTool V6.0 and set the trigger to a time-of-day value (e.g. 23:59:00) or to a tag edge on ShiftEnd. The dump runs without operator intervention and the resulting CSV is named with the current system date and time.

Why does the script return error 2 even though ARCHIV_10.CSV exists?

Error 2 means the source path passed to CopyLog does not match an active archive handle. The most common causes are (a) the archive has not been configured under Archive → Settings per entry 5155752, (b) the path string in the script uses forward slashes instead of backslashes, or (c) the runtime has not yet written the first segment, so the file does not exist when the script runs. Verify each of the three points and re-test.

Is the renamed CSV readable by Excel and by ProTool again?

Yes, the copy is a byte-for-byte duplicate of the source archive and conforms to the standard ProTool CSV format, so it can be opened in Excel, imported into a historian, or even renamed back to ARCHIV_10.CSV and re-loaded into a development project for offline analysis.

What is the maximum number of historical archives the AVC 64 can hold?

An AVC 64 has roughly 60 MB usable space. A typical 1 kHz tag archive with 16 tags produces about 350 kB per shift, so a 64 MB card holds about 170 shift dumps before the cleanup routine is required. For multi-year retention, switch to the AVC 128, attach a USB stick (OP 277 / MP 277 with the -USB option) or use the FTP push method described in the ProTool V6.0 manual, Chapter 5.14.

Back to blog