This section controls what happens when the engineer clicks a button.
There are two levels of event handling:
DialogEvents — immediate response to button clicks (runs in the event loop)
CommandEvent — long-running operations triggered by DialogEvents via a "pending command" number
Why two levels?
VBScript running inside Siemens Starter cannot run multiple threads.
If a long operation (like downloading parameters) was run directly inside a button click handler,
the UI would freeze and the window would become unresponsive.
Instead, the click handler just sets PendingCommand = n,
and the main event loop picks it up on the next tick.
Event Flow
Engineer clicks button (e.g. "Config Drives")
│
▼
HTML onclick → VBScript DialogEvents_4() → DialogEvents(4)
│
│ Sets PendingCommand = 101
│ Shows "Please Wait" status
│
▼
EventHandler() main loop detects PendingCommand ≠ 0
│
▼
CommandEvent(101)
│
│ Goes offline (GoOnline(False))
│ Calls ConfigureAllDrives()
│ Saves project
│ Shows "Config Drives - Done" in green
│
▼
PendingCommand = 0 → loop continues waiting for next click
EventHandler
Sub EventHandler( ThisIEDocument )
What it does:
This is the main loop of the program. It runs continuously until the
engineer closes the HTML window.
On every loop iteration (every ~1 second), it checks if a command is pending.
If so, it processes it and clears the pending command.
It also checks if the window has been closed (error reading ReadyState) and exits if so.
Sub EventHandler(ThisIEDocument)
On Error Resume Next
While (Not(boClose)) ' Keep looping until the window is closed (boClose = True)
APP.Time(1) ' Wait 1 second (keeps the script responsive while idle)If PendingCommand <> 0Then' Was a button pressed? Is there a command waiting to run?
CommandEvent(PendingCommand) ' Run the command (see table below)
PendingCommand=0' Clear the pending flag once doneEnd If
Err.Clear
iDummy = ThisIEDocument.ReadyState ' Try to read the window state
boClose = (Err.Number <> 0) ' If this gives an error, the window was closed
Err.Clear
Wend
APP.Workbench.Visible = True' Bring Starter's workbench back into focus after window closes
ThisIEDocument.Quit ' Close the IE window cleanlyEnd Sub
CommandEvent — Long-Running Commands
Private Sub CommandEvent( Number )
Command Number
Triggered by
What it does
100
Step 3 button
Go offline → ConfigureAllCUs() → Save project
101
Step 4 button
Go offline → ConfigureAllDrives() → Save project
200
Step 5 button
Go online → check no drives are enabled → PROJ.Download()
300
Step 8 button
Go online → PostIDAllDrives() → Ram2RomAllDevices()
400
Step 9 button
Go online → Ram2RomAllDevices() → Upload all devices → Save project
500
Step 10 button
(S53 new) ExportHMIFile() — export machine data for HMI
600
Step 11 button
Go online → Ram2RomAllDevices() only (RAM → ROM without upload)
Private Sub CommandEvent(Number)
Select Case Number
Case100' STEP 3: Config Infeed and CUs
PendingCommand=0
StatusLineEcho 3,"Blue","Config CU/Infeed - Going Offline"
GoOnline(False) ' Go offline before writing parameters
StatusLineEcho 3,"Blue","Config CU/Infeed - Configuring"
ConfigureAllCUs ' Run the CU configuration (see file 03)
StatusLineEcho 3,"Blue","Config CU/Infeed - Saving"
APP.Workbench.WBProject.Save() ' Save the Starter project file
StatusLineEcho 3,"Green","Config CU/Infeed - Done"
updatestatusdisplay ' Refresh button statesCase200' STEP 5: Download
PendingCommand=0If GoOnline(True)=True Then' Must be online to downloadIf AnyDeviceEnabled Then' SAFETY CHECK: No drives powered? If drives are spinning,
StatusLineEcho 5,"DarkRed","Drives Enabled - Activate G-stop"' ↑ ABORT — don't download with drives running (dangerous)Else
StatusLineEcho 5,"Blue","Downloading, please wait"
PROJ.Download() ' Send all parameters to all drives (can take several minutes)
StatusLineEcho 5,"Green","Download, complete"End IfElse
StatusLineEcho 5,"DarkRed","Download, error - Unable to go Online"End If' (Cases 100, 300, 400, 500, 600 follow the same pattern)End SelectEnd Sub
DialogEvents — Button Click Handler
Private Sub DialogEvents( Number )
What it does:
Receives button click events from the HTML page. Short operations run immediately here;
long ones just set PendingCommand for CommandEvent to pick up.
Event Number
Button / Source
Action
1
Step 1: Identify Drives
Go online, set ShowDriveIdent=True, call UpdateStatusDisplay to show the drive table
2
Step 2: Edit Machine Data
Set ShowMachineData=True, load and display current machine data form
3
Step 3
Set PendingCommand=100 (Config CUs)
4
Step 4
Set PendingCommand=101 (Config Drives)
5
Step 5
Set PendingCommand=200 (Download)
6
Step 6
Show "exit script and carry-out Safety Integrated config" message
7
Step 7
Show "exit script and carry-out Motor Identification" message
8
Step 8
Set PendingCommand=300 (Post ID Config)
9
Step 9
Set PendingCommand=400 (RAM→ROM + Upload)
10
Step 10
Set PendingCommand=500 (Export HMI file)
1001
"Save" in Machine Data form
Call SaveMachineData, hide machine data form
1002
"Cancel" in Machine Data form
Hide machine data form without saving
2001
"Accept" in Drive Ident
Check no duplicates, rename CUs and drives, go offline, save project
2002
"Cancel" in Drive Ident
Hide drive ident table
How button clicks connect to DialogEvents:
In the HTML builder (file 04), each button gets assigned an onclick handler like:
GetRef("DialogEvents_1") creates a reference to the VBScript sub DialogEvents_1()
which is defined as:
Private Sub DialogEvents_1() : DialogEvents(1) : End Sub
So clicking the HTML button calls DialogEvents_1() → DialogEvents(1).
DialogID — Drive Flash Identification
Sub DialogID( ThisToNumber )
What it does:
Makes a specific drive module "flash" its LED so the engineer can identify which
physical drive module corresponds to which row in the identification table.
Clicking the same "- Identify -" button again turns the flashing off (toggle).
Sub DialogID(ThisToNumber)
Index=1For Each adevice In PROJ.Devices
For Each ato In adevice.TOs
If (aTO.ExternalTypeName="SINAMICS_SERVO_SL"Or ATO.ExternalTypeName="SINAMICS_VECTOR_SVC") ThenIf index=ThisTONumber Then' Found the drive we want to identifyIf ato.Parameters(124,0)=0Then' p124 = LED control. 0 = off, 1 = flash
SetParam aTO, 124, 0, 1' Turn LED FLASHING ON' Change button colour to gold/blue = "flashing active"
MainPage.Document.GetElementbyid("Button_"&ThisToNumber+100).style.backgroundColor="gold"
MainPage.Document.GetElementbyid("Button_"&ThisToNumber+100).style.Color="blue"Else
SetParam aTO, 124, 0, 0' Turn LED FLASHING OFF' Change button back to blue/gold = "not flashing"
MainPage.Document.GetElementbyid("Button_"&ThisToNumber+100).style.backgroundColor="blue"
MainPage.Document.GetElementbyid("Button_"&ThisToNumber+100).style.Color="gold"End IfEnd If
index=index+1
End IfNextNextEnd Sub
UpdateStatusDisplay
Sub UpdateStatusDisplay
What it does:
This is called after almost every action to refresh the entire UI state. It:
Shows or hides the Machine Data form and Drive Ident table based on current flags
Updates the Drive Ident table rows with live data from the online drives
Validates machine data completeness (supply voltage set, all drive data filled in, etc.)
Enables or disables each step button based on prerequisites being met
Button Enable/Disable Logic
Button
Enabled when...
Step 0 (Auto Reset)
Always disabled (reminder only)
Step 1 (Identify)
Drives exist in project (autoconfig was run)
Step 2 (Machine Data)
All drives in project are identified
Step 3 (Config CU)
Drives identified + machine data complete + data valid
Step 4 (Config Drives)
Same as Step 3
Step 5 (Download)
Same as Step 3 + ALL drives have ConfigStatus ≥ 1
Steps 6-9
Always enabled (manual steps or upload)
Sub UpdateStatusDisplay
' ── Show/hide Machine Data form ──────────────────────────────────────────────If ShowMachineData Then
MainPage.Document.GetElementbyid("MachineData").style.Display = "inline"Else
MainPage.Document.GetElementbyid("MachineData").style.Display = "none"
MainPage.Document.GetElementbyid("main_table").style.Display = "inline"End If' ── Show/hide Drive Ident table rows ─────────────────────────────────────────
' Loop through all devices and TOs, fill in the ID table with live dataIf ShowDriveIdent Then
Index=1For Each adevice In PROJ.Devices
For Each ato In adevice.TOs
If (aTO.ExternalTypeName="SINAMICS_SERVO_SL" ...) Then
MainPage.Document.GetElementbyid("DriveIdentLine_"&Index).style.Display = "inline"
MainPage.Document.GetElementbyid("ID1_"&Index).innerHTML = adevice.Name ' CU name
MainPage.Document.GetElementbyid("ID2_"&Index).innerHTML = ato.Name ' Drive name
MainPage.Document.GetElementbyid("ID3_"&Index).innerHTML = ato.Parameters(121,0) ' Drive number (p121)
MainPage.Document.GetElementbyid("ID4_"&Index).innerHTML = ato.Parameters(207,0)&" Amps"' Rated current
MainPage.Document.GetElementbyid("ID5_"&Index).innerHTML = ato.Parameters(307,0)&" kW"' Rated power
MainPage.Document.GetElementbyid("ID6_"&Index).innerHTML = ato.Parameters(311,0)&" rpm"' Rated speed
Index=Index+1
End IfNextNextEnd If' ── Check machine data validity ──────────────────────────────────────────────
' MachineDataComplete = all required fields are filled
' MachineDataValid = no conflicting values
MachineDataComplete=TrueIf (MachineData_SupplyVoltage < 350Or MachineData_SupplyVoltage > 500) Then
MachineDataComplete=False' Voltage must be selected (380-480V range)End If' ... (similar checks for each drive: speed, torque, direction, motor type, encoder)' ── Set button disabled states based on above checks ─────────────────────────
MainPage.Document.GetElementbyid("Button_0").disabled=True' Step 0 always greyed out
MainPage.Document.GetElementbyid("Button_1").disabled = _
ShowMachineData Or Not DrivesExistInProject ' Grey out if no drives autoconfig'd
MainPage.Document.GetElementbyid("Button_2").disabled = _
ShowMachineData Or Not AllDrivesInProjectIdentified ' Grey out if drives not identified
MainPage.Document.GetElementbyid("Button_5").disabled = _
Not (DrivesExistInProject And AllDrivesInProjectIdentified _
And MachineDataComplete And MachineDataValid And LowestConfigStatus>=1)
' ↑ Download button only active when ALL prerequisites are met (p2901 ≥ 1 = configured)End Sub