Math Function

This Python example installs a simulated module, creates a math function in Eye/Mask mode to remove an S2P response for a device in the test setup, performs a limit test to acquire waveforms data, and saves the pattern waveform along with a screen capture.

Copy

math-function.py

# -*- coding: utf-8 -*-
""" Demonstrates a math function in Eye/Mask mode to remove S2P.
Installs a simulated module in slot 5. Performs a limit test to
acquire and save a pattern waveform, and save a screen capture.
"""

import time
import pyvisa as visa  # import VISA library

CHANNEL = '5A'
SPARAMETER_FILE = '"%DEMO_DIR%\\S-Parameter Data\\Demo\\TDRDemoBoard\
_ET55780\\' + 'ET55780_Impedance_Profile.s2p"'
ADDRESS = 'TCPIP0::localhost::hislip0,4880::INSTR'
#ADDRESS = 'TCPIP0::K-86100D-00003::hislip0,4880::INSTR'  # DCA-X


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)
    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 install_simulated_module(flexdca, channel, model, signal='NRZ'):
    """ Simplified installation of a simulated FlexDCA module.
    model
        Type of simulated module. "DEM" is a dual-electrical module.
        "QEM" is a quad-electrical module. "DOM" is a dual-optical
        module. "QEM" is a electrical-optical module.
    signal
        Format of signal. NRZ or PAM4.
    """
    slot = channel[0]
    flexdca.write(':EMODules:SLOT' + slot + ':SELection ' + model)
    if signal in 'NRZ':
        flexdca.write(':SOURce' + channel + ':FORMat NRZ')
    else:
        flexdca.write(':SOURce' + channel + ':FORMat PAM4')
    flexdca.write(':SOURce' + channel + ':DRATe 9.95328E+9')
    flexdca.write(':SOURce' + channel + ':WTYPe DATA')
    flexdca.write(':SOURce' + channel + ':PLENgth 127')
    flexdca.write(':SOURce' + channel + ':AMPLitude 90E-3')
    flexdca.write(':SOURce' + channel + ':NOISe:RN 3.0E-6')
    flexdca.write(':SOURce' + channel + ':JITTer:RJ 4.0E-12')
    flexdca.write(':CHANnel' + channel + ':DISPlay ON')


def configure_FlexDCA(flexdca, channel):
    """ Installs a simulated module and prepares FlexDCA for
    measurements.
    """
    flexdca.write('*CLS')
    flexdca.query(':SYSTem:DEFault;*OPC?')
    install_simulated_module(flexdca, channel, 'DEM')
    flexdca.write(':CHAN' + channel + ':DISPlay ON')
    # Make waveform in screen capture easier to see
    flexdca.write(':CHAN'+channel+':COLor TCOLor16')
    flexdca.write(':DISPlay:PINTensity MEDium')
    flexdca.query(':SYSTem:MODE EYE;*OPC?')
    flexdca.query(':SYSTem:AUToscale;*OPC?')


def pattern_lock(flexdca):
    """Turns on pattern lock. """
    flexdca.query(':TRIGger:PLOCk ON;*OPC?')
    flexdca.write(':ACQuire:WRAPping ON')


def define_math_operator(flexdca, channel, s2pfile):  # Function Apply S2P
    """ Creates an "Apply s2p" waveform signal processing function.
    The required s2p file is selected from the demo folder as it is
    always available for this example. You can substitute your own file.
    """
    flexdca.write(':DISPlay:SPPanel ON')
    flexdca.write(':FUNCtion1:FOPerator CONVolve')
    flexdca.write(':SPRocess1:CONVolve:FNAMe ' + s2pfile)
    s = flexdca.query(':SPRocess1:CONVolve:FNAMe?')
    print('\nImported s2p file is\n' + s, flush=True)
    flexdca.write(':FUNCtion1:OPERand1 CHAN' + channel)
    flexdca.write(':FUNCtion1:COLor TCOLor1')
    flexdca.write(':FUNCtion1:DISPlay ON')  # Turn on Function 1
    time.sleep(1.0)
    flexdca.write(':DISPlay:SPPanel OFF')
    flexdca.write(':DISPlay:WINDow:TIME1:DMODe STILed')
    flexdca.query(':SYSTem:AUToscale;*OPC?')


def define_limit_test_files(flexdca):
    """ Configures the name and type of file saved upon completion of
    the acquisition limit test in the default folders.
    """
    flexdca.write(':LTESt:ACQuire:SIMage:STATe ON')
    flexdca.write(':LTESt:ACQuire:SIMage:WINDow TIMe1')


def run_acquisition_limit_test(flexdca):
    """ Configures and runs acquisition limit test.
    One pattern is acquired which results in a saved pattern waveform in
    internal format and a saved screen capture. For pattern smoothing,
    patterns acquired equal patterns smoothed.
    """
    PatternCount = '100'
    flexdca.write(':LTESt:ACQuire:CTYPe:PATTerns ' + PatternCount)
    if int(PatternCount) > 1:
        flexdca.write(':ACQuire:ECOunt ' + PatternCount)
    flexdca.write('ACQuire:STOP')
    flexdca.write(':ACQuire:CDISplay')  # Clear acquired data
    flexdca.query(':LTESt:ACQuire:STATe ON;*OPC?')
    flexdca.timeout = 60000  # 60 seconds
    flexdca.query(':ACQuire:RUN;*OPC?')
    flexdca.write(':LTESt:ACQuire:STATe OFF')
    flexdca.timeout = 30000
    print('\nFile saved:')
    print(flexdca.query(':LTESt:ACQuire:SIMage:FNAMe?'))


FlexDCA = open_flexdca_connection(ADDRESS)
configure_FlexDCA(FlexDCA, CHANNEL)
pattern_lock(FlexDCA)
define_math_operator(FlexDCA, CHANNEL, SPARAMETER_FILE)
define_limit_test_files(FlexDCA)
run_acquisition_limit_test(FlexDCA)
FlexDCA.write(':SYSTem:GTLocal')
FlexDCA.close()