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:
The Listener is addressed to talk and the Serial Poll Enable (SPE) command byte is sent.
The ATN line is set high and the Listener returns the status byte.
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.
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:
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);
Configure property values — Configure both objects to time out after 1 second.
g1.Timeout = 1; g2.Timeout = 1;
fprintf(g1,'*CLS'); fprintf(g1,'*ESE 32'); fprintf(g1,'*SRE 32');
Configure the oscilloscope to request service when a command error occurs.
fprintf(g2,'*CLS') 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]);
an invalid command for the oscilloscope, it is requesting service.
out == [g1 g2] ans = 0 1
a valid command for the function generator, the value is read back
volt1 = fscanf(g1) volt1 = +1.00000E-01
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 = ''
and clean up — When you no longer need
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