Event driven programming – Industrial Data Systems IDS Scale Basic User Manual
Page 10

Scale Basic 4.2E
Tutorial
Event Driven Programming
Event Driven programming is useful for ‘real time’ applications. Real time applications are 
those which depend on real events that happen when they happen. For example, a start switch 
closure, setpoint trip level, process monitoring, are real events that the computer monitors but the 
timing of the events are not controlled by the computer. 
The most widely available programming model is the ‘sequential programming’ method. 
Sequential programs work best in applications where actions take place in a step by step manner. 
The next step in the process follows from the previous step. 
In sequential programs for real time systems, the program structure starts with a main loop 
which scans for selected events. An event then activates a subroutine. The subroutine will 
execute while scanning for events that may occur while the subroutine is active. If an event 
occurs in a subroutine, then another subroutine is activated and whatever events that need 
scanning are scanned. 
In an Event Driven Programming environment, events are automatically scanned for by the 
operating system. When an event is detected it triggers a program function. For example: part of 
the indicator’s event loop is to scan the keyboard. Each key is assigned a Scale Basic function to 
execute when the event scanner detects a key-press. Each Scale Basic function is short and 
executes quickly. Thus, the structure of an event driven program is: event - action, event - 
action, event - action, …. 
In event driven program design, the program structure is centered around event-action pairs. The 
event scanning is taken care of in the operating systems event scanner. 
The tutorial that follows uses the techniques described above for program design, and then 
completes the programs, using techniques of program implementation. 
Program Implementation Steps:
1. Identify events and select the functions that they will activate.
2. Write program functions.
3. Test program.
4. Modify program as needed.
5. Repeat steps 3 & 4 as needed.
