FlexPLL Binary Transfer
This Python example, binary_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.
As shown in the following code, the query_binary_values() method is used to return the x and then the y data. After the data is returned, the data is zipped into x and y "point" tupples.
Copy
return FlexPLL.query_binary_values(command, datatype='d', container=list, is_big_endian=False, header_fmt='ieee')
Example Script
Copy
FlexPLL-binary-transfer.py
# -*- coding: utf-8 -*-
""" This script transfers Memory 1 (Model) binary JTF dat from the FlexPLL
application. The data is returned in binary format using
':DATA:PLLModel:DOUBle:XDATa?' and ':DATA:PLLModel:DOUBle:XDATa?'.
Requires that JTF plots for Response Memory 1 must be displayed before
script is run. """
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():
""" Returns binary x and y data for response memory. """
global FlexPLL
xdata = []
ydata = []
FlexPLL.write(':DATA:PLLModel:SOURce JTF1')
points = int(FlexPLL.query(':DATA:PLLModel:POINts?'))
endiansetting = FlexPLL.query(':SYSTem:BORDER?')
FlexPLL.write(':SYSTem:BORDER LENDian')
FlexPLL.read_termination = ''
FlexPLL.write_termination = ''
command = ':DATA:PLLModel:DOUBle:XDATa?'
xdata = FlexPLL.query_binary_values(command, datatype='d', container=list, is_big_endian=False, header_fmt='ieee')
command = ':DATA:PLLModel:DOUBle:YDATa?'
ydata = FlexPLL.query_binary_values(command, datatype='d', container=list, is_big_endian=False, header_fmt='ieee')
FlexPLL.read_termination = '\n'
FlexPLL.write_termination = '\n'
FlexPLL.write(':SYSTem:BORDER ' + endiansetting)
xypoints = list(zip(xdata, ydata))
return points, xypoints
FlexPLL = open_flexpll_connection(ADDRESS)
points, xypoints = get_data_points()
print('\n\nLength of JTF Response data: {0:d} points.\n'.format(points))
for i, point in enumerate(xypoints, 1):
print('{0:d}. x = {1:e} Hz, y = {2:f} dB'.format(i, point[0], point[1]))
FlexPLL.write(':SYSTem:GTLocal')
FlexPLL.close()