Fact 5. How to Perform a Measurement
How can you return reliable scalar measurements? The simple answer is to always check the status of a measurement before reading the measurement. All measurements have a :STATus?
child query that you can use for this task, as demonstrated in the script Example of :STATus? query included in this topic. For example, to check the readiness of an JTF Response Bandwidth measurement (:MEASure:RESPonse:BANDwidth?
), first send the :MEASure:RESPonse:BANDwidth:STATus?
query. The :STATus?
query returns CORR
(correct) if the measurement is ready to return, INV
(invalid) if the measurement not ready to be returned, and QUES
(questionable) if the measurement may not be valid.
The following Python script is an example of using the :STATus?
query to return a measurement. A valid JTF waveform is assumed to be displayed on FlexPLL. The return_scalar()
function returns an bandwidth measurement. If the measurement takes longer than this timeout value, the script throws an exception which is defined at the top of the function. If your script is timing out, increase the IO timeout.
Scalar Measurement
import time
import visa # import VISA library
def return_scalar(FlexPLL, query):
class ScalarMeasQuestionableException(Exception):
""" A scalar measurement result is questionable. """
pass
class ScalarMeasTimeOutException(Exception):
""" A scalar measurement has timed out. """
pass
timeout = FlexPLL.timeout / 1000 # convert ms to s
query = query.strip('?')
start_time = time.time() # time in seconds
while(True):
time.sleep(0.2)
status = FlexPLL.query(query + ':STATus?')
if 'CORR' in status: # valid measurement result
return FlexPLL.query(query + '?')
elif 'QUES' in status:
s = query + '\nReason: ' + FlexPLL.query(query + ':STATus:REASon?')
raise ScalarMeasQuestionableException(s)
elif (int(time.time() - start_time)) > timeout:
s = query + '\nReason: ' + FlexPLL.query(query + ':STATus:REASon?')
raise ScalarMeasTimeOutException(s)
rm = visa.ResourceManager()
FlexPLL = rm.open_resource('TCPIP0::localhost::hislip0,4880::INSTR')
FlexPLL.timeout = 20000 # in milliseconds
FlexPLL.read_termination = '\n'
FlexPLL.write_termination = '\n'
FlexPLL.write(':MEAS:RESP:BAND') # Bandwidth measurement
print('Bandwidth: ', return_scalar(FlexPLL, ':MEAS:RESP:BAND?'))
FlexPLL.write(':SYSTem:GTLocal')
FlexPLL.close()