DCA-X Self Tests
This Python example performs the N1000A hardware self tests. Self tests are entirely safe to run but should only be needed if the N1000A has a possible error and Keysight support requests a self test. You can also run these self tests from FlexDCA's GUI. Click Tools > Hardware Self Tests. The script runs these pass/fail tests using the *TST?
common command.
Copy
DCA-X-self-test.py
# -*- coding: utf-8 -*-
""" Performs the N1000A Hardware Self Test by sending the *TST? common command.
Self tests are entirely safe to run but should only be needed if the DCA-X has a possible error
and Keysight support requests a self test. You can also run these self tests
from FlexDCA's GUI. Click Tools > Hardware Self Tests. Enter FlexDCA's VISA
address into the script's ADDRESS global CONSTANT that is located near
top of script.
"""
import pyvisa as visa # import VISA library
import time
ADDRESS = 'TCPIP0::K-N1000A-00240::hislip0,4880::INSTR'
def open_flexdca_connection(address):
""" Opens visa connection to FlexFlexDCA. """
print('Connecting to Flexdca ...')
try:
rm = visa.ResourceManager()
connection = rm.open_resource(address)
connection.timeout = 20000 # Set connection timeout to 20s
connection.read_termination = '\n'
connection.write_termination = '\n'
inst_id = connection.query('*IDN?')
print('\nFlexDCA connection established to:\n' + inst_id, flush=True)
connection.write(':SYSTem:DEFault')
connection.query('*OPC?')
except (visa.VisaIOError, visa.InvalidSession):
print('\nVISA ERROR: Cannot open instrument address.\n', flush=True)
return None
except Exception as other:
print('\nVISA ERROR: Cannot connect to instrument:', other, flush=True)
print('\n')
return None
return connection
def discover_modules(FlexDCA):
""" Locates each hardware or extended module by slot.
Returns a list of slots with a module.
"""
slot_list = []
for slot in range(1, 9): # slot numbers
model = FlexDCA.query('SYST:MODel? SLOT' + str(slot))
if model in 'Not Present':
continue
elif model in 'N1010A': # Simulated module or DCAM
emodel = FlexDCA.query('EMODules:SLOT' + str(slot) + ':SELection?')
if (emodel in 'DCAM'): # DCA-M scope found
slot_list.append(str(slot))
else: # standard module
slot_list.append(str(slot))
return slot_list
def select_test(slot_list):
valid_slots = ''
print('-' * 50)
print('Select hardware tests:\n' +
'1. All tests (\u2264 2 minutes)\n' +
'2. Frame tests (\u2264 1 minute)\n' +
'3. SLOT tests (\u2264 30 seconds)')
s = input('When ready, press:\n' +
' 1, 2, or 3 to select a setup.\n' +
' or any other key to exit: ')
FlexDCA.timeout = 180000 # 3 minutes
if (s in '1'):
return 'ALL'
elif (s in '2'):
return 'FRAMe'
elif (s in '3'):
valid_slots = ', '.join(slot_list)
print('Modules found in slots: ', valid_slots)
num = input('Enter one of the following slot\n' +
'numbers to test: ' + valid_slots + ': ')
if num in slot_list:
return 'SLOT' + num
else:
print('Invalid number entered: ', num)
return ''
else:
return ''
FlexDCA = open_flexdca_connection(ADDRESS)
FlexDCA.write(':ACQuire:RUN')
slot_list = discover_modules(FlexDCA)
test = select_test(slot_list)
if test:
print('\nRunning tests. Please wait...', flush=True)
start_time = time.time()
result = FlexDCA.query('*TST? ' + test)
process_time = int(time.time() - start_time)
m, s = divmod(process_time, 60)
print('Time required for test to complete was:' +
'\n\t' + str(m) + ' minutes, ' + str(s) + ' seconds.', flush=True)
if result == '0':
print('\nHardware tests passed.')
elif result == '1':
print('\nHardware tests failed.')
FlexDCA.write(':SYSTem:GTLocal')
FlexDCA.close()