The following functions are included in the LabVIEW GPIB 488 subpalette and are essential for performing serial polling in LabVIEW:
GPIB Serial Poll (
ibrsp in NI-488) performs a serial poll and returns the value of the Status Byte from a single device. The program must manually check the RQS bit in the Status Byte value to determine whether that device requested service.
GPIB Wait (
ibwait in NI-488) waits for the state indicated by a specified Status Word mask in a particular GPIB bus. The Status Word is a global variable (16 bit) that contains, among other GPIB information, the state of the SRQ line (bit 12, SRQI), and whether a device has requested service (bit 11, RQS). If the vector that is passed in equals 0, it does not wait for any specified case and will update
ibsta or the Status Word. However, if the mask is set to check for bit 12 (SRQI), the function will wait until that particular line gets asserted for a particular GPIB board, the address of which is specified in GPIB Wait.
Wait for GPIB RQS (
ibwait in NI-488, with mask for bit 11) is similar to using the GPIB Wait function with a mask for bit 11, but using the GPIB address of the particular device address instead of the address of the GPIB board (when waiting for bit 12). This function waits for a particular device to request service, and not for a board (to which several devices could be connected) to receive a service request. This function will wait until either the RQS bit is asserted or the time-out is exceeded.
The following examples show how to service SRQs and serial poll the devices using LabVIEW GPIB functions.
In LabVIEW Example 1 (Figure 3), a command is written to an NI Instrument Simulator. The command includes instructions for the instrument to generate a Service Request (SRQ) if an Operation Completed event is registered in the Event Status Register (ESR). The first two commands write these instructions to the Service Request Enable Register and the Event Status Enable Register (IEEE-488.2 specification). The third command asks the instrument simulator to generate a sine wave; the last command generates an Operation Completed event. The following section of the code waits for the SRQ to be generated by checking bit 12 of the Status Word. Once it has been generated, a serial poll is performed on the device simulator to read the Status Byte and learn the reason it generated an SRQ. If bit 5 is set (from the Event Status Register having the Operation Complete bit set) and bit 6 is set (RQS, the device has requested service), then the Controller goes ahead and reads the data back from the device simulator. Notice that the ESR register must be cleared. This prevents the instrument from generating unwanted service requests.
Figure 3. LabVIEW Example 1
LabVIEW Example 2 (Figure 4) shows another way of waiting for the device to request service. However, in this last example, the processor stops and waits without performing any other operations. In the first example, other operations could have been executed in parallel while waiting for the device to request service.
Figure 4. LabVIEW Example 2