Basic Flex-on-Flex

This Python script demonstrates making and then disconnecting a Flex-on-Flex connection. The following diagram shows a Flex-on-Flex connection. N1010A FlexDCA on a PC connects to a DCA-X. In this configuration:

  • The version for both the PC's N1010A FlexDCA and the DCA-X's FlexDCA must be the same.
  • The DCA-X's display is shown on N1010A.
  • Simulated modules cannot be installed on the DCA-X in a Flex-on-Flex configuration. Simulated modules already installed on the DCA-X cannot be used.
  • Any DCA-M module must be connected to the PC before it can be controlled. DCA-M modules connected to the DCA-X cannot be seen.

Example Script

Copy

basic-flex-on-flex.py

""" Script on PC controls a DCA-X by establishing a Flex-on-Flex
connection. The script connects to N1010A FlexDCA on the PC. Then the
script connects N1010A FlexDCA to FlexDCA on a remote DCA-X instrument
via LAN. The connections are then broken.
"""

import pyvisa as visa  # import VISA library

FLEX_ADDRESS = 'TCPIP0::localhost::hislip0,4880::INSTR'
HOSTNAME_N1000A = 'K-N1000A-00240'
CHANNEL = '5A'
TIMEOUT = 30000


def print_message():
    """ Prints short confirmation that a Flex-on-Flex connection
    has been made.
    """
    s = 'FlexDCA on the PC is now connected to FlexDCA on the \
DCA-X (86100D or N1000A). FlexDCA on your PC should now be \
showing the DCA-X\'s screen.\n\nNote: In this mode, if you install \
a simulated module, it will be installed on FlexDCA on the PC not \
on the DCA-X.\
\n\nTo disconnect from the DCA-X \
instrument, click here and press the Enter key:'
    input(s)


def connect_FlexDCA_to_N1000A(FlexDCA, hostname):
    """Opens connections from FlexDCA on PC to DCA-X's FlexDCA. """
    print('\nConnecting to 86100D. Please wait...', flush=True)
    FlexDCA.write(':RDCA:CONNect:METhod LAN')
    FlexDCA.write(':RDCA:CONNect:MODE STANdard')
    FlexDCA.write(':RDCA:CONNect:ACTion TBSettings')
    # Pull state upon connect
    FlexDCA.write(':RDCA:CONNect:TSETtings ON')
    # Push state upon disconnect
    FlexDCA.write(':RDCA:DISConnect:TSETtings ON')
    FlexDCA.write(':RDCA:CONNect:HOST "' + hostname + '"')
    if FlexDCA.query(':RDCA:CONNect;*OPC?'):
        print(FlexDCA.query('*IDN?'))


def open_flexdca_connection(address):
    """ Opens visa connection to FlexFlexDCA. """
    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


FlexDCA = open_flexdca_connection(FLEX_ADDRESS)
FlexDCA.query(':SYSTem:DEFault;*OPC?')
connect_FlexDCA_to_N1000A(FlexDCA, HOSTNAME_N1000A)
print_message()
print('Please wait.')
print('Disconnecting from DCA-X.')
FlexDCA.query(':RDCA:DISConnect;*OPC?')
print('Disconnecting from PC\'s FlexDCA.')
FlexDCA.write(':SYSTem:GTLocal')
FlexDCA.close()