Transfer CGGS data to/from 86100D

This script demonstrates FlexDCA's :WAVeform:EYE:XML:READ? and :WAVeform:EYE:XML:WRITe? queries. The script first configures FlexDCA so that a color-grade gray-scale waveform is displayed. Then, the internal format waveform data is:

  1. Returned from FlexDCA's Channel 1A.
  2. Written into FlexDCA's color-grade gray-scale memory 2.
  3. Saved to a color-grade gray-scale file (.cgsx) in the script folder. .

Example Script

Copy

WAVeform-EYE-XML-READ-WRITE.py

""" Example of FlexDCA's ":WAVeform:EYE:XML:READ?" and ":WAVeform:EYE:XML:WRITe?"
queries. FlexDCA offline is configured with a waveform.
Waveform data is returned from FlexDCA's channel 1A,
written into FlexDCA's color-grade gray-scale memory 2, and saved
to a waveform file without the definite-length block data
preamble). The PyVisa library does not remove or add the
definite-length block data preamble.
"""

import pyvisa as visa  # import VISA library

ADDRESS = 'TCPIP0::localhost::hislip0,4880::INSTR'
CHANNEL = '1A'


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 waveform. 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 setup(flexdca, channel):
    flexdca.write('*CLS')
    flexdca.query(':SYSTem:DEFault;*OPC?')
    install_simulated_module(flexdca, channel, 'DEM')
    flexdca.query(':SYSTem:MODE EYE;*OPC?')
    flexdca.query(':TRIGger:PLOCk ON;*OPC?')
    flexdca.query(':SYSTem:AUToscale;*OPC?')
    flexdca.write(':ACQuire:EPATtern ON')  # Acquire entire pattern
    flexdca.write(':ACQuire:STOP;:ACQuire:CDISplay')
    flexdca.query(':ACQuire:SINGle;*OPC?')


def get_CGGS_binary_waveform_data(flexdca):
    """ Sends a scpi query to FlexDCA that returns SCPI binary data
    instead of an ASCII string. For example, ':WAVeform:XML:READ? CHAN2A'
    returns binary data.
    datatype
        Set to unsigned bytes for internal format PyVisa's default is
        float. You can change datatype to whatever you need that is
        supported by PyVisa.
    is_big_endian
        FlexDCA's byte order is little-endian by default.
    ieee
        IEEE definite-length block header is automatically stripped
        from returned data.
    """
    global CHANNEL
    flexdca.read_termination = ''
    flexdca.write_termination = ''
    message = ':WAVeform:EYE:XML:READ? CHAN' + CHANNEL
    data = flexdca.query_binary_values(message, datatype='B', is_big_endian=False, container=bytes, delay=None, header_fmt='ieee')
    flexdca.read_termination = '\n'
    flexdca.write_termination = '\n'
    return data


def write_waveform_data_to_CGGS_memory(flexdca, values):
    data = b''  # Python 3 byte string (bytes not unicode)
    flexdca.read_termination = ''
    flexdca.write_termination = ''
    message = ':WAVeform:EYE:XML:WRITe? CGMemory2,'
    flexdca.write_binary_values(message, values, datatype='B', is_big_endian=False, termination=None, encoding=None)
    # to satisfy ':WAVeform:XML:WRITe? WMEMory2,' as a query
    data = flexdca.read_raw()
    flexdca.read_termination = '\n'
    flexdca.write_termination = '\n'
    return


FlexDCA = open_flexdca_connection(ADDRESS)
setup(FlexDCA, CHANNEL)
data = b''  # Python 3 byte string (bytes not unicode)
data = get_CGGS_binary_waveform_data(FlexDCA)
write_waveform_data_to_CGGS_memory(FlexDCA, data)
with open('eye_waveform.cgsx', 'wb') as fout:
    fout.write(data)
FlexDCA.write('DISPlay:WINDow:TIME1:DMODe STILed')  # display channel and CGGS waveforms
FlexDCA.write(':SYSTem:GTLocal')
FlexDCA.close()