EnableInterrupt Procedure

Installs an interrupt.

Syntax

[ lStatus = ] EnableInterrupt ( enInterrupt, lParameter, proc )

The EnableInterrupt procedure syntax has the following parts:

 

Name

Type

Description

lStatus

Long

Return status

enInterrupt

Val enumAInterrupts

An integer specifying the INT_xxx interrupt constant.

lParameter

Val Long

Parameter for interrupt type

proc

Val Procedure

Name of interrupt subroutine, not a string

Where

enumAInterrupts can be one of the following values:

 

Name

Value

Description

INT_TIMER1

10

TIMER1 Interrupt. The interval expired.

INT_TIMER2

11

TIMER2 Interrupt. The interval expired.

INT_COM1

12

COM1 Interrupt. Bytes were received.

INT_COM2

13

COM2 Interrupt. Bytes were received.

INT_COM3

14

COM3 Interrupt. Bytes were received.

INT_COM4

15

COM4 Interrupt. Bytes were received.

INT_COM5

16

COM5 Interrupt. Bytes were received.

INT_COM6

17

COM6 Interrupt. Bytes were received.

INT_COM7

18

COM7 Interrupt. Bytes were received.

INT_COM8

19

COM8 Interrupt. Bytes were received.

INT_COM9

20

COM9 Interrupt. Bytes were received.

INT_GPIB1

22

GPIB1 Interrupt. An SRQ signal was received.

INT_GPIB2

23

GPIB2 Interrupt. An SRQ signal was received.

INT_USER1

24

USER1 Interrupt. A user-defined interrupt. Set a bit in the interrupt mask to high and the interrupt will be called.

INT_USER2

25

USER2 Interrupt. A user-defined interrupt. Set a bit in the interrupt mask to high and the interrupt will be called.

INT_USER3

26

USER3 Interrupt. A user-defined interrupt. Set a bit in the interrupt mask to high and the interrupt will be called.

INT_USER4

27

USER4 Interrupt. A user-defined interrupt. Set a bit in the interrupt mask to high and the interrupt will be called.

INT_USER5

28

USER5 Interrupt. A user-defined interrupt. Set a bit in the interrupt mask to high and the interrupt will be called.

INT_USER6

29

USER6 Interrupt. A user-defined interrupt. Set a bit in the interrupt mask to high and the interrupt will be called.

INT_USER7

30

USER7 Interrupt. A user-defined interrupt. Set a bit in the interrupt mask to high and the interrupt will be called.

INT_USER8

31

USER8 Interrupt. A user-defined interrupt. Set a bit in the interrupt mask to high and the interrupt will be called.

Comments

The EnableInterrupt procedure names a procedure, proc, to be called when a given interrupt is requested. Only requests made after EnableInterrupt is called will result in the interrupt procedure being called.

Returns < 0 if there was an error in lParameter or the interrupt is already enabled. Returns 0 if the status is OK. Returns 1 if software emulation is done to check between commands to implement interrupts.

Some of the GPIB boards or Drivers (GPIBxxx.DLL) do not support interrupts or are not configured to support interrupts.

lParameter is set depending on the type of interrupt specified and should be 0 if not used.

proc should be a user-defined subroutine. The proc parameter used as the interrupt handler should be declared as having either one or no parameter. If one parameter is used, it must be declared as Val Long. The procedure should not return any value (Void). Two sample procedure declarations with this syntax are show below:

Procedure InterruptProc(lParam) : Void

lParam: Val Long

{

}

or

Procedure InterruptProc() : void

{

}

While the interrupt procedure executes, the associated interrupt is temporarily disabled, but other interrupts are unaffected. The interrupt request is cleared when the interrupt procedure returns.

When calling this procedure while executing Doit!/Loopit! a run-time error will occur (interrupts are disabled in Doit! mode).

Calling EnableInterrupt/DisableInterrupt or masking interrupts inside an interrupt subroutine will take place only on return. Re-enabling (Disable and Enable) of the current interrupt number handler during Interrupt sub is not allowed (only Disable is allowed). Re-enabling of other interrupt numbers is allowed.

Interrupts are serviced (called) according to their priority number. The interrupts priorities are:

TIMER1 (highest)

COM ports

GPIB boards

USER

ATEasy subroutines are not re-entrant; if an interrupt occurs inside a subroutine, that interrupt subroutine must not call that subroutine again.

Calling EnableInterrupt clears (zeros) the corresponding enInterrupt bit in the InterruptMask variable. Interrupts can be invoked by using the command:

SetInterruptMask (INT_USER1, True)

This command invokes the interrupt associated with INT_USER1 if enabled.

In general, interrupt procedures should execute quickly. Requests for the same interrupt during execution of the interrupt procedure will be lost. An interrupt procedure should not block itself for large periods of time waiting for user input or on some thread synchronization object.

Example

In the following example, the interrupt subroutine TimeInt is called every second. This program segment terminates 10 seconds after the start if the TimeInt sub contains the statement i=i+1. Otherwise, the While/Endwhile loop is an endless loop.

i=0

EnableInterrupt (INT_TIMER1, 1000, TimeInt)

while i< 10

endwhile

print i

.

.

.

Procedure TimeInt() : Void

{

i=i+1

}

 

See Also

DisableInterrupt, SetInterfaceEvent, SetInterruptMask