TOWERLAMP — tower lamp and buzzer
TOWERLAMP is the global object for the machine's tower lamp ( Red · Orange · Green · Blue ) and buzzer.
The lamp colours, blinking and buzzer of each state are defined by state name ( TYPE ) on the Tower Lamp Setup screen,
and a script picks a state with TOWERLAMP.SetLamp("Name"). The buzzer mode is set with Buzzer Mode in the lamp IO setting window
( SINGLE · MULTI DIRECT · MULTI BINARY ).
Example
// TOWERLAMP
TOWERLAMP.SetLamp("INIT"); // switch to the configured "INIT" lamp state
Sleep(1000);
if( TOWERLAMP.CurrentState == "INIT" )
{
TOWERLAMP.SetLamp("STOP"); // switch to the configured "STOP" lamp state
}
else
{
TOWERLAMP.BeepNo();
}Real-world example — switching lamps in system event functions
The QMS core does not change the lamp state itself on start, stop or error. Pick the matching lamp in the event functions of the system Event module.
// System Event module
FUNCTION bool OnSystemStart()
{
TOWERLAMP.SetLamp("RUN");
return true; // returning false cancels the start
}
FUNCTION OnSystemStop()
{
TOWERLAMP.SetLamp("STOP");
}
FUNCTION OnSystemError()
{
// If the ERROR state has a buzzer, do not call a beep function (BeepNo etc.) here
// ( the beep turns the buzzer off when it ends, which also stops the ERROR buzzer until the next SetLamp )
TOWERLAMP.SetLamp("ERROR");
}
FUNCTION OnSystemReset()
{
if( SYS.IsRunning )
{
TOWERLAMP.SetLamp("RUN");
}
else
{
TOWERLAMP.SetLamp("STOP");
}
}Methods
| Method | Description |
|---|---|
bool SetLamp(string state) | Switches the tower lamp to state state. Returns false without switching when the state name does not exist. State names are saved in upper case on the setup screen, so write them in upper case |
bool Contains(string lampState) | True when a state named lampState exists |
void Stop(void) | Stops tower lamp control and turns every lamp and the buzzer off |
bool SetBuzzer(bool on) | Turns the buzzer on or off. In multi-buzzer mode it outputs the Touch Beep Sound number of the lamp IO setting window. Turning it off with false also sets BuzzerEnable to false, so the buzzer of the current lamp state stays silent until the next SetLamp |
bool SetBuzzerSound(int sound) 4.0+ | Outputs a buzzer sound number continuously. 0 stops it ( same as SetBuzzer(false) ). Returns false when the number is out of range or there is no buzzer IO. sound : 0 = OFF, SINGLE 1, MULTI DIRECT 1 ~ 4, MULTI BINARY 1 ~ 15 ( see MaxBuzzerSound ) |
bool PlayBuzzerSound(int sound, int durationMs) 4.0+ | Plays a sound for durationMs ( msec, 1 ~ 60000 ) and then turns it off. It plays in the background, so the caller does not wait; while another beep pattern is playing the request is ignored and it returns false |
void BeepInitCompleteSound(void) | Plays the predefined initialisation-complete beep |
void BeepYes(void) | Plays the predefined YES beep |
void BeepNo(void) | Plays the predefined NO beep |
void Beep(void) | Plays the predefined single beep |
string ToString(void) | In the current version it returns only the object type name, not the tower lamp configuration |
- The beep functions (
BeepInitCompleteSound·BeepYes·BeepNo·Beep) play in the background, so the caller does not wait, and they are ignored while another beep pattern is playing. In multi-buzzer mode they use the Touch Beep Sound number.
Caution The beep functions and
PlayBuzzerSoundturn the buzzer off when they finish (SetBuzzer(false)), so afterwards the buzzer of the current lamp state stays silent until the nextSetLamp. Conversely, while a repeating lamp state such as a blinking one is active andBuzzerEnableis true, that state's buzzer setting is output again on every blink cycle, replacing a sound started withSetBuzzer(true)·SetBuzzerSound().
Properties
| Property | Type | Description |
|---|---|---|
CurrentState | string | The state name last set with SetLamp. Writing a value does not change the lamp — use SetLamp |
Count | int | Number of registered lamp states |
RedOn · OrangeOn · GreenOn · BlueOn | bool | Current output state of each lamp colour ( read-only — change lamps with SetLamp ) |
BuzzerOn | bool | Current output state of the buzzer ( read-only ) |
CurrentBuzzerSound 4.0+ | int | Buzzer sound number being output now, 0 = OFF ( read-only ) |
MaxBuzzerSound 4.0+ | int | Highest sound number of the current buzzer mode — SINGLE = 1 / MULTI DIRECT = 4 / MULTI BINARY = 15 ( read-only ) |
BuzzerEnable | bool | Whether the buzzer of the lamp state sounds. Set it to false to mute only the buzzer. Every SetLamp sets it back to true, and SetBuzzer(false) · SetBuzzerSound(0) set it to false |
IsExistRedLampIO · IsExistOrangeLampIO · IsExistGreenLampIO · IsExistBlueLampIO | bool | Whether each lamp IO is connected |
IsExistBuzzerIO | bool | Whether a buzzer IO is connected ( in multi-buzzer mode, any of K1 ~ K4 ) |
The lamp / buzzer IO names and the buzzer mode are set on the Tower Lamp Setup screen ( they are not script properties ).
See that screen's description for the lamp script format of each state ( R1 · Z0 · D500 · TAG ~ GOTO and so on ).