Install DCA-M Modules
The DCA-M-install.py script shows how the :EMODules
subsystem commands are used to remove and install DCA-M modules. The script removes all DCA-M and simulated modules, lists all available slots, and then installs two specific DCA-Ms in the first two available slots. If this script is run on a DCA-X, the first four slots are always occupied by the DCA-X. Only slots 5 through 8 are available. If this script is run on N1010A FlexDCA and a Flex-on-Flex connection has not been established, all 8 slots are available. A Flex-on-Flex connection occurs when FlexDCA on a PC is connected to a DCA-X.
Copy
DCA-M-install.py
# -*- coding: utf-8 -*-
""" Remove all simulated or DCA-M modules from slots 5 through 8.
Then connects DCA-M modules that are described in dcam
dictionary. """
import pyvisa as visa # import VISA library
ADDRESS = 'TCPIP0::K-N1000A-QA06::hislip0,4880::INSTR'
# ADDRESS = 'TCPIP0::localhost::hislip0,4880::INSTR'
dcam = ['N1090A-US00000000', 'N1092D-US00000000']
def open_flexdca_connection(address):
""" Opens visa connection to FlexDCA. """
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 remove_all_dcams(flexdca):
""" Disconnects all DCA-M modules and removes any simulated modules. """
availableSlots = list()
for slot in '12345678':
model = flexdca.query(':EMODules:SLOT'+slot+':SELection?')
if model in 'EMPTy':
availableSlots.append(slot)
elif model in ['AWGenerator', 'DCA', 'RTSCope', 'SWITch', 'N4877A']:
continue
elif model in ['DCAM', 'DEMini', 'QEMini', 'OEMini', 'DOMini']:
if 'CONN' in flexdca.query(':EMODules:SLOT'+slot+':STATe?'):
print('Disconnecting module in slot '+slot+' ...', flush=True)
flexdca.query(':EMODules:SLOT'+slot+':DISConnect;*OPC?')
availableSlots.append(slot)
if not availableSlots:
print('No slots are available to install a DCA-M.')
return availableSlots
def connect_dcams(flexdca, dcam, availableSlots):
""" Assigns DCA-Ms to slots. """
i = 0
for hostname in dcam:
n = availableSlots[i]
flexdca.write(':EMODules:SLOT' + n + ':SELection DCAM') # type of module to install in slot
flexdca.write(':EMODules:DCAM' + n + ':DEVice "' + hostname + '"') # identifies module to install
flexdca.query(':EMODules:SLOT' + n + ':CONNect;*OPC?') # installs module in slot
print(hostname + ' connected to slot ' + n, flush=True)
i += 1
FlexDCA = open_flexdca_connection(ADDRESS)
slots = remove_all_dcams(FlexDCA)
print('\nAvailable slots: {}\n'.format(str(slots)))
if len(slots) >= len(dcam):
connect_dcams(FlexDCA, dcam, slots)
else:
print('Not enough available slots to install DCA-Ms!')
FlexDCA.write(':SYSTem:GTLocal')
FlexDCA.close()