Triggering WinCC 7.3 VBS Scripts on Rising Edge of a PLC Tag
WinCC V7.3 (and the entire WinCC V7.x line) exposes only Value Change events on tag triggers, not a true rising-edge or falling-edge event. The same is true for the On Click, Change, and Property Change VBS actions configured in Graphics Designer. The result: a script bound to a tag fires on every change of value - both 0→1 and 1→0. This article documents the canonical Siemens-recommended pattern to make a VBS action fire only on the rising edge (0 → 1) of a binary PLC tag, plus persistence, fault-handling, and verification steps that are required for production systems.
1. Overview of the Rising-Edge Problem in WinCC V7
A tag event in WinCC V7.3 fires whenever the WinCC tag manager receives a new value from the AS (PLC) that differs from the last cached value. There is no polarity check: a change from 0 to 1 and a change from 1 to 0 are indistinguishable to the event dispatcher. This is documented in the WinCC V7.3 Working with WinCC documentation set in the section on Tag Triggers.
When you configure a VBS action on a tag, the configuration dialog in Graphics Designer presents only these triggers for tag-bound events:
- Value Change – fires on any change of the tag value (0→1, 1→0, or any analog value change).
- (On pictures) Open, Close – picture lifecycle events, not tag events.
There is no Rising Edge, On (0→1), or PosEdge option. To restrict the script to a 0→1 transition you must compare the current value against the previous value inside the action. Because VBScript in WinCC V7.3 has no concept of a static local variable that survives between invocations, the previous value must be stored in a WinCC tag.
2. Prerequisites
Before you implement rising-edge detection, verify the following items in the WinCC Explorer on the engineering station and on every runtime station that will run the script:
- WinCC V7.3 SP3 or later installed with the Basic Process Control option (for tag triggers to be available to VBS actions).
- Authorization / License for the runtime station: at minimum a WinCC RT 1024 tag license for tag triggers to fire VBS actions. The V7.3 licensing matrix is in SIMATIC WinCC V7.3 - Working with WinCC.
-
Two WinCC tags:
- One external binary tag from the PLC (e.g.
MyConveyor_StartCmd, datatype Binary tag, length 1 bit). - One internal binary tag used as a latching memory (e.g.
MyConveyor_StartCmd_Old).
- One external binary tag from the PLC (e.g.
- VBScript execution enabled in the project properties: Project Properties > Options > Runtime, Activate VBScript = checked.
- Graphics Designer with edit rights on the target picture.
3. The Latching-Variable Pattern (Siemens-Recommended Method)
The standard Siemens engineering pattern for rising-edge detection in WinCC V7.3 VBS uses one internal tag to remember the previous trigger value. The pattern is documented in the FAQ entries of the WinCC V7.x online help under Global Script > VBScript > Tips and Tricks.
3.1 Create the Latching Tag
In WinCC Explorer open Tag Management, right-click on the Internal Tags group and select New Tag:
| Property | Value |
|---|---|
| Name | EdgeTrig_OldState |
| Data type | Binary tag |
| Length | 1 bit (default) |
| Initial value | 0 |
| Update | On change |
| Persistent | Yes (see §6) |
3.2 Configure the Action Trigger
Open the target picture in Graphics Designer, select the object that hosts the action (commonly the picture itself so the trigger fires regardless of focus), then in Properties > Events > VBS Action configure:
-
Trigger: Tag >
MyConveyor_StartCmd - Event name: Value Change
This is the only available event. The actual filtering happens inside the script body.
3.3 Write the Rising-Edge VBS Action
The canonical implementation looks as follows. It is the same algorithm recommended in the WinCC V7.3 online help for the Edge Detection example:
' ---------------------------------------------------------------
' WinCC V7.3 VBS action - Rising-edge detection
' Trigger: Tag "MyConveyor_StartCmd" (0 → 1)
' Latch: Tag "EdgeTrig_OldState" (persistent internal)
' ---------------------------------------------------------------
Option Explicit
Dim actTrig ' current value from PLC
Dim oldTrig ' last value from previous trigger
Dim objOld ' HMIRuntime tag handle for latching
actTrig = HMIRuntime.Tags("MyConveyor_StartCmd").Read
Set objOld = HMIRuntime.Tags("EdgeTrig_OldState")
oldTrig = objOld.Read
' --- Rising edge: 0 → 1 ---
If (Not CBool(oldTrig)) And CBool(actTrig) Then
' <place your one-shot action here>
HMIRuntime.Trace "Rising edge detected on MyConveyor_StartCmd at " _
& Now & vbCrLf
HMIRuntime.Tags("EdgeTrig_DiagCount").Write _
HMIRuntime.Tags("EdgeTrig_DiagCount").Read + 1
End If
' --- Always update latch to the new state ---
objOld.Write actTrig
Set objOld = Nothing
Three points to note:
- The script reads actTrig and oldTrig on every Value Change. The Boolean expression
(Not oldTrig) And actTrigis true only on the 0→1 transition. - The latch is written after the comparison so that the next event will see the new value as oldTrig.
-
HMIRuntime.Traceoutputs to the WinCC diagnostic file WinCC_Sys_xx.log in \Siemens\Automation\WinCC\Diagnostics. Use it during commissioning.
4. Handling the Initial Scan and Runtime Restart
A subtle but important corner case: when WinCC Runtime starts up, all internal tags are reset to their configured initial value (0 by default). The very first Value Change on the PLC tag after startup may therefore incorrectly register as a rising edge, even if the PLC tag is already 1 at the moment Runtime comes up. The fix is to initialise the latch with the current value of the PLC tag during the Open Picture event or in the project's @Startup action.
4.1 One-Shot Initialisation in a Picture Open Event
Configure a second VBS action on the picture's Open event (no trigger tag, fires once when the picture is loaded):
' Picture-open initialiser: seed the edge latch with the current PLC state
Dim cur
cur = HMIRuntime.Tags("MyConveyor_StartCmd").Read
HMIRuntime.Tags("EdgeTrig_OldState").Write cur
HMIRuntime.Trace "EdgeTrig_OldState seeded with value " & cur & vbCrLf
If the script must run in the background regardless of the active picture, place the same code in a project-wide @Startup global action (WinCC Explorer > Global Script > Project Modules > Actions > @Startup).
5. Tag Persistence: Surviving Runtime Restart
An internal tag in WinCC V7.3 loses its value when the WinCC Runtime is stopped and is restored to the Initial value on next start. For a one-shot rising-edge detector this is acceptable only if you also implement the initialisation in §4. If the action must be triggered across a Runtime restart without the initial-value reset, configure the tag as persistent:
- Open Tag Management and select the internal latching tag (
EdgeTrig_OldState). - In the Properties dialog, switch to the Select tab and set Update to On change.
- Switch to the Limits/Reporting tab (WinCC V7.3 SP2+) and tick Persist tag value. The tag is then written to the project database on every change and restored at the next Runtime start.
- Alternatively, use the WinCC V7.3 API call
HMIRuntime.Tags("EdgeTrig_OldState").Persist = Truefrom a startup action.
SERVER::EdgeTrig_OldState). See WinCC V7.3 - Server-Client Architecture.6. Complete Project Configuration Reference
The following table summarises every tag, trigger, and event needed to deploy rising-edge detection in a typical WinCC V7.3 SCADA project:
| Item | Type | Direction | Persistence | Used by |
|---|---|---|---|---|
MyConveyor_StartCmd |
External, Binary, 1 bit | PLC → WinCC | n/a | Action trigger (Value Change) |
EdgeTrig_OldState |
Internal, Binary, 1 bit | WinCC internal | Yes (recommended) | Latch in rising-edge script |
EdgeTrig_DiagCount |
Internal, Unsigned 32-bit | WinCC internal | Yes | Diagnostic counter incremented on every detected edge |
EdgeTrig_LastTime |
Internal, Text tag, 32 char | WinCC internal | Yes | Timestamp of last detected edge (string form of Now) |
7. C-Script Alternative (WinCC V7 Legacy)
For projects that still use ANSI-C actions (the older scripting language retained for compatibility), the same algorithm is shorter because C has static variables. Configure the trigger as Tag Trigger > On Change and bind a C action with the following body:
// WinCC V7.3 C action - rising edge on binary tag
static DWORD dwOldState = 0;
DWORD dwNewState = GetTagDWord("MyConveyor_StartCmd");
if ((dwOldState == 0) && (dwNewState == 1))
{
// <place one-shot action here>
printf("Rising edge detected\r\n");
}
dwOldState = dwNewState;
For binary tags, use GetTagBit and the type BOOL instead. The C action keeps the latch in static storage, so no persistent internal tag is needed. This is the historical approach and is described in WinCC V7.3 C-Scripting Reference.
8. Edge Detection Inside Faceplates and User Objects
When the rising-edge action is part of a faceplate (WinCC V7.3 faceplate type with the Interface tag exposed as the trigger), the latching tag must be declared internal to the faceplate instance. Steps:
- In the faceplate type, declare an instance tag of type Binary in the Properties > Interface section, name it
FP_EdgeLatch. - Expose the faceplate's main interface tag (the binary coming from the PLC) as a Tag property.
- In the faceplate body, add the VBS action identical to §3.3, but reference the instance tag (
HMIRuntime.Tags("FP_EdgeLatch").Read) and the interface property tag. - Instance tags are automatically scoped to the faceplate instance, so 50 faceplate instances on one picture each have their own latch.
This pattern is documented in WinCC V7.3 - Faceplate Types.
9. Commissioning and Verification Procedure
Follow this sequence in the WinCC Runtime to verify the rising-edge implementation end-to-end:
- Activate the project in WinCC Explorer. The VBS action is compiled at activation; any syntax error is reported in the Scripts Diagnostics window.
- Open the WinCC SysLog at \Siemens\Automation\WinCC\Diagnostics\WinCC_Sys_00.log. Confirm the initialisation line "EdgeTrig_OldState seeded with value ..." appears in the log when the picture opens.
-
Force the PLC tag to 0 from the AS (use the Watch Table in STEP 7 / TIA Portal with the tag
MyConveyor_StartCmd). The action should not trigger - the script logs no "Rising edge detected" entry. -
Set the tag to 1. The script should fire exactly once and the
EdgeTrig_DiagCounttag should increment to 1. -
Set the tag to 0. Nothing should happen.
EdgeTrig_DiagCountremains 1. - Set the tag to 1 a second time. The script fires again; counter goes to 2. This confirms the latch updates correctly on each event.
- Stop and restart WinCC Runtime with the PLC tag at 1. The picture-open initialiser (§4) must seed the latch with 1 so that the next 1→0→1 sequence is required to fire. If the action fires immediately on restart, the seed step was not implemented.
10. Troubleshooting Matrix
| Symptom | Likely Cause | Fix |
|---|---|---|
| Action fires on every change, both edges | Script does not check the latch; only actTrig is used |
Add the If (Not oldTrig) And actTrig guard and write objOld.Write actTrig at the end |
| Action never fires | Trigger tag is configured as a quality code tag or has wrong acquisition cycle; or trigger event is missing | Verify tag acquisition is Cyclic on change in PLC, and the action's Trigger field points to the tag |
| Action fires on first scan after Runtime start | Latch reset to 0 by Runtime startup while PLC tag is already 1 | Implement the picture-open / @Startup seed step from §4 |
| Action fires on 1→0 transition | Boolean inversion in PLC (e.g. active-low signal) or wrong data type conversion | Check Read returns a value compatible with CBool(); if signal is active-low, invert the expression: If oldTrig And (Not actTrig) Then
|
| Multiple faceplate instances all fire on one event | Latch tag is global instead of instance-scoped | Declare the latch as an instance tag inside the faceplate type (§8) |
| Counter increments faster than expected | Action trigger set to Cyclic in addition to On Change; or AS sends repeated values | Use only the Value Change trigger; do not add a cyclic trigger with a small period |
| Script does not run on client | Client cannot see the latch tag | Reference the latching tag with the server prefix (e.g. SERVER::EdgeTrig_OldState) or replicate it as a client internal tag |
| "Object variable not set" runtime error in VBS |
Set objOld = ... missing or tag name misspelled |
Add On Error Resume Next at the top during debugging, log the error number with HMIRuntime.Trace Err.Number & " " & Err.Description
|
11. Performance and Timing Notes
A single Value-Change VBS action with one tag read, one Boolean compare, and one tag write typically completes in under 5 ms on a WinCC V7.3 SP3 single-user station. The pattern scales linearly: a script bound to N tags with N latches runs in approximately N × 5 ms. Beyond ~100 tags, prefer a single global cyclic action (1 s cycle) that scans an array of bits and accumulates edges into a queue, rather than N separate VBS actions. The cyclic approach is documented in the WinCC V7.3 performance guide in SIMATIC WinCC V7.3 - Configuration Manual.
Tag update latency from a Siemens S7 PLC is typically 100-500 ms depending on the configured acquisition mode (Cyclic continuous, Cyclic on change, or On demand). For high-speed edges shorter than the WinCC acquisition cycle, use the PLC's Edge evaluation instruction (e.g. FP in STEP 7 / R_TRIG in TIA Portal) and have the PLC deliver a sustained pulse to WinCC.
12. Migration to WinCC Unified / TIA Portal
If you later migrate the project to WinCC Unified (V16+), the situation improves. In Unified, tag triggers offer the events OnChange, OnRisingEdge, and OnFallingEdge directly on a tag in the HMI tag table, and the same JavaScript action can be attached without a manual latch. The migration is therefore a 1:1 replacement of the latching-tag pattern with a native event. Until that migration is complete, the V7.3 pattern above is the correct implementation.
13. Quick-Reference Checklist
- [ ] Create external binary tag from PLC.
- [ ] Create internal latching tag, persistent = Yes.
- [ ] Attach VBS action to picture, trigger = tag Value Change.
- [ ] Inside the script:
If (Not oldTrig) And actTrig Then…objOld.Write actTrig. - [ ] Add picture-open / @Startup seed of the latch.
- [ ] Verify with PLC forced transitions; confirm counter increments only on 0→1.
- [ ] Check WinCC_Sys_xx.log for trace lines.
Does WinCC 7.3 have a built-in rising-edge event for VBS scripts?
No. WinCC V7.3 tag triggers only expose Value Change. You must implement edge detection in the script body using a latching variable that stores the previous value of the trigger tag.
Why is my rising-edge action also firing on the falling edge?
The trigger event fires on every value change, regardless of direction. The script body must compare the new value against the stored previous value and act only on the 0→1 transition. Use the pattern If (Not oldTrig) And actTrig Then followed by objOld.Write actTrig.
Do I lose the latching variable when I stop WinCC Runtime?
By default, yes - internal tags are reset to the initial value (0) on Runtime stop. Enable the Persist tag value option on the internal latching tag, or implement a picture-open / @Startup VBS action that seeds the latch with the current PLC value.
Can I use this pattern on a WinCC client with tags from the server?
Yes, but the latching tag must be reachable from the runtime where the action executes. Create the latch on the server and reference it with the server prefix (e.g. SERVER::EdgeTrig_OldState), or replicate the latch as a client-side internal tag and initialise it on client startup.
What is the fastest reliable cycle time for a rising-edge VBS action in WinCC V7.3?
The script itself runs in 5-10 ms. The dominant latency is the tag acquisition cycle from the PLC, typically 100-500 ms. For edges shorter than this, have the PLC latch the edge into a sustained flag and clear it from WinCC after the action runs.