Lock unlock – Remote Processing CAMBASIC User Manual

Page 108

Advertising
background image

Comm ands - 75

LOCK

UNLOCK

Tasking Statements

SYNTAX:

L O C K

U N L O C K [R E T U R N ]

UNL OCK E XIT

PURPOSE:

T o lo c k o u t i nt e rr u p ts fr o m ti m e c r it ic a l p o r ti on s of a pr o g ra m .

REMARK S:

When an interrupt occurs fr om a ON TICK, ON C OM$, etc., the current program is interrupted and
the interrupt subroutine is called.

In some cases, especially where time is critical, it is desirable that the current program not be
interrupted until it is completed. W hen the command LO CK is executed, any interr upts will be
latched, but not executed until the UNLOC K command is executed.

The UN LOC K RETU RN is only used at the end of a GOSUB routine. In this case a previous
LOC K must occur in the subroutine. F or these commands to prevent any par t of a subroutine from
being interrupted, LO CK must be the first line of the subroutine. Therefore, the GOSUB must use a
line numb er, not a label.

UNLO CK EXIT m ay be used to quickly get out of a FOR-NEXT , GO SUB, or other nested routine.

EXAMPLE:

10 GOSUB 500
20 IF PRESSURE > 234 THEN ALARM = 1.
.
500 LOCK
510 PRESSURE = AIN(6) - AIN(0)
520 UNLOCK RETURN

If this construct were not used, an interrupt could occur between lines 500 and 510 and/or between
lines 510 and 520 and delay the alarm flag being set in line 20.

ERROR:

none

Advertising