Here's an example of how a tricky problem can be solved by breaking it down into smaller pieces, in this case by using a separate MultiTrack task.
Rab has a MultiTrack program where any one of several independent tasks may generate an alarm The alarm results in a siren sounding. What Rab wants is for the alarm to have a Clear button, and when the button is pressed the siren will be muted for 20 minutes. How can this be programmed?
Rab has a MultiTrack program where any one of several independent tasks may generate an alarm The alarm results in a siren sounding. What Rab wants is for the alarm to have a Clear button, and when the button is pressed the siren will be muted for 20 minutes. How can this be programmed?
Providing it's OK for the siren to always remain on until manually cleared, the function can be implemented very simply with a separate task to control the siren. This siren task gets sent alarm requests by other tasks. Here's the code. It should be simple enough for anyone with FastTrack plus MultiTrack exposure to analyze.
This example also illustrates using a semaphore to communicate between MultiTrack tasks, as well as using GoSubs (subroutines) to "hide" the internal workings of the siren function.
;===== Siren manager ==========
;A GoSub SIR_Alarm will start the siren on output oSIR_en.
;The siren will run until the clear button iSIR_Clear is pressed.
;Thereafter it will ignore any further requests (GoSub SIR_Alarm)
;for 20 minutes.
;Uses a semaphore and one MultiTrack task.
;Do a GoSub SIR_Init at the start of your program to initialise.
oSIR_en oEQU 8 ;(say)
iSIR_Clear iEQU 9 ;(say)
sSIR_Request defSEM
SIR_Init:
ClrS sSIR_Request
LaunchTask SIR_Task
Return
SIR_Alarm:
SetS sSIR_Request
Return
SIR_Task:
WaitForST sSIR_Request
On oSIR_en
WaitForInK iSIR_Clear
Off oSIR_en
Pause 120000 ;20 minutes
ClrS sSIR_Request
GoTo SIR_Task
This example also illustrates using a semaphore to communicate between MultiTrack tasks, as well as using GoSubs (subroutines) to "hide" the internal workings of the siren function.
