Main Content

Serial Polls

Using the spoll Function

You can execute a serial poll with the spoll function. In a serial poll, the Controller asks (polls) each addressed Listener to send back a status byte that indicates whether it has asserted the SRQ line and needs servicing. The seventh bit of this byte (the RQS bit) is set if the instrument is requesting service.

The Controller performs the following steps for every addressed Listener:

  1. The Listener is addressed to talk and the Serial Poll Enable (SPE) command byte is sent.

  2. The ATN line is set high and the Listener returns the status byte.

  3. The ATN line is set low and the Serial Poll Disable (SPD) command byte is sent to end the poll sequence.

Refer to Status and Event Reporting for more information on the GPIB bus lines and the RQS bit.

Executing a Serial Poll

This example shows you how to execute a serial poll for a Keysight™ 33120A function generator and a Tektronix® TDS 210 oscilloscope. In doing so, the example shows you how to configure many of the status bits described in Standard Event Status Register:

  1. Create instrument objects — Create a GPIB object associated with a Keysight 33120A function generator at primary address 1.

    g1 = gpib('ni',0,1);

    Create a GPIB object associated with a Tektronix TDS 210 oscilloscope at primary address 2.

    g2 = gpib('ni',0,2);
  2. Connect to the instrument — Connect g1 to the function generator and connect g2 to the oscilloscope.

    fopen([g1 g2])
  3. Configure property values — Configure both objects to time out after 1 second.

    g1.Timeout = 1;
    g2.Timeout = 1;
  4. Write and read data — Configure the function generator to request service when a command error occurs.

    fprintf(g1,'*ESE 32'); 
    fprintf(g1,'*SRE 32');

    Configure the oscilloscope to request service when a command error occurs.

    fprintf(g2,'*PSC 0') 
    fprintf(g2,'*ESE 32') 
    fprintf(g2,'DESE 32') 
    fprintf(g2,'*SRE 32')

    Determine if any instrument needs servicing.

    spoll([g1 g2])
    ans =

    Query the voltage value for each instrument.


    Determine if either instrument produced an error due to the preceding query.

    out = spoll([g1 g2]);

    Because Volt? is an invalid command for the oscilloscope, it is requesting service.

    out == [g1 g2]
    ans =
    0 1

    Because Volt? is a valid command for the function generator, the value is read back successfully.

    volt1 = fscanf(g1)
    volt1 =

    However, the oscilloscope read operation times out after 1 second.

    volt2 = fscanf(g2) 
    Warning: GPIB: NI: An I/O operation has been canceled, most likely 
    due to a timeout.
    volt2 =
  5. Disconnect and clean up — When you no longer need g1 and g2, you should disconnect them from the instruments, and remove them from memory and from the MATLAB® workspace.

    fclose([g1 g2])
    delete([g1 g2])
    clear g1 g2