The following code illustrates the use of the ibwait and ibrsp functions in a typical SRQ servicing situation when Automatic Serial Polling is disabled. ibwait suspends program execution until certain conditions on the GPIB are met.
REM $include: 'qbdecl.bas'
REM For this example, assume that two devices are connected REM to the GPIB. Either device has the ability to assert SRQ. REM One of the devices is an oscilloscope (referred to as scope) REM and the other is a digital multimeter (referred to as dmm).
REM The first task is to wait for the SRQ line to assert. This REM can be done by an ibwait for SRQI or by a looping structure REM using ibwait 0 or iblines function. For this illustration, REM we use the ibwait function to wait for either the SRQI bit to REM be set or a timeout.
CALL ibfind ("gpib0", brd0%) CALL ibfind ("dev1", scope%) CALL ibfind ("dev2", dmm%)
CALL ibwait (brd0%, SRQI|TIMO)
REM If ibwait terminated because of SRQI being set, poll the REM devices and interpret returned status bytes to see which, if REM not both, requested service.
IF (ibsta% AND SRQI) THEN
REM In this case, because Autopolling is not active, ibrsp REM uses the gpib bus to get the status byte from the scope. CALL ibrsp(scope%, spr.scope%) IF (spr.scope% AND &H40) THEN PRINT "Scope asserted SRQ."
REM Here you would analyze the serial poll status byte, REM spr.scope%, to determine the cause of the SRQ.
CALL ibrsp(dmm%, spr.meter%)
IF (spr.meter% AND &H40) THEN PRINT "DMM asserted SRQ."
REM Analyze the rest of the serial poll status byte, REM spr.meter%, to determine the cause of the SRQ.
If Autopolling is active, the RQS bit of ibsta for the device in question must be used to determine if the device has requested service. Note that ibrsp is again used to return the Status Byte, but this time we already know Bit 6 is set because the RQS bit is checked on a single device basis. Furthermore, ibrsp only accesses the Status Byte that was obtained and stored previously by the Autopolling routine.
REM When Autopolling is active, the following code excerpt can be REM used as a subroutine to check if a particular device is REM requesting service.
CALL ibwait (device%, 0) IF (ibsta% AND RQS) THEN
PRINT "Device asserted SRQ."
REM In this case, ibrsp does not poll the device but REM simply returns the response byte from memory. REM The status byte will be used to determine how to REM service the device.
CALL ibrsp (device%, spr.device%)