FLexPLL ASCII Transfer

This Python example, ascii_response_transfer.py, gets the JTF Response plot data for Response Memory 1 in ASCII. You can easily modify the program to return the data from the any other Response Memory or from the primary Response.

Example Script

Copy

FlexPLL-ascii-transfer.py

# -*- coding: utf-8 -*-
""" This script transfers Memory 1 (Model) ASCII JTF data from the FlexPLL
application. The source is response memory 1.
The data is returned in binary format using ':DATA:PLLModel:ASCii:XDATa?' and
':DATAPLLModel:ASCii:XDATa?'. """

import pyvisa as visa  # import VISA library

ADDRESS = 'TCPIP0::localhost::hislip1,4880::INSTR'


def open_flexpll_connection(address):
    """ Opens visa connection to FlexPLL. """
    print('Connecting to FlexPLL ...')
    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('\nFlexPLL 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 get_data_points(FlexPLL):
    """ Returns ASCii x and y data for response memory.
    """
    xdata = []
    ydata = []
    FlexPLL.write(':DATA:PLLModel:SOURce JTF1')
    points = FlexPLL.query(':DATA:PLLModel:POINts?')
    xdata = FlexPLL.query(':DATA:PLLModel:ASCii:XDATa?').split(',')
    ydata = FlexPLL.query(':DATA:PLLModel:ASCii:YDATa?').split(',')
    xypoints = list(zip(xdata, ydata))
    return points, xypoints


FlexPLL = open_flexpll_connection(ADDRESS)
points, xypoints = get_data_points(FlexPLL)
print('\n\nLength of JTF Response data: {0:s} points.\n'.format(points))
for i, point in enumerate(xypoints, 1):
    print('{0:d}. x = {1:s} Hz, y = {2:s} dB'.format(i, point[0], point[1]))
FlexPLL.write(':SYSTem:GTLocal')
FlexPLL.close()