Transfer Eye Diagram Image for JobID
FlexOTO Instance:
Stations
This example script demonstrates how to return the Eye Diagram Image's binary data from a Station's Job Results and save the data to an image file. Before running this script:
- FlexOTO must be running with a Station tab displayed.
- The Station's Job Results panel must have a Job ID that has the Eye Diagram Image column with a "x" in it. The "x" shows that an Eye Diagram Image was selected to be generated for this Job ID.
- In the script, modify the
ADDRESS
constant for the correct Station. The default address is for Station 1. - In the script, modify the
JOBID
constant for the correct value.
Example Script
Copy
python-binary-image-xsfer.py
# -*- coding: utf-8 -*-
""" From FlexOTO, returns binary Eye Diagram image data for Session 1's Job ID #1 and saves the data to an image file.
Session 1's address is "hislip1".
Queries the file name extension to go with the type of image data.
Before running script:
- Run FlexOTO to display the Job Results for Session 1's Job ID 1.
- To change the Job ID, edit the JOBID assignment near top of script.
- Edit the FOLDER variable for the folder where you want the image file saved.
"""
import pyvisa as visa # import VISA library
ADDRESS = 'TCPIP0::localhost::hislip1,4880::INSTR' # Session 1
JOBID = '1'
def get_file_extension(session):
""" Returns ".png", ".jpg", ".bmp", ".gif", or ".tiff"? """
return session.query(':JOBS:RESults:SIMage:EXTension? ' + JOBID).strip('"')
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)
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
def return_eye_image(session):
""" Transfers binary image data to computer. """
print("\nReturning Job ID " + JOBID + "'s Eye Diagram image data.", flush=True)
session.read_termination = ''
session.write_termination = ''
endiansetting = session.query(':SYSTem:BORDER?')
session.write(':SYSTem:BORDER LENDian')
message = ':JOBS:RESults:SIMage? ' + JOBID
img = session.query_binary_values(message,
datatype='B',
container=bytearray,
is_big_endian=False,
header_fmt='ieee')
session.write(':SYSTem:BORDER ' + endiansetting)
session.read_termination = '\n'
session.write_termination = '\n'
return img
session = open_flexdca_connection(ADDRESS)
if 'CORR' in session.query(':JOBS:RESults:SIMage:STATus? ' + JOBID):
extension = get_file_extension(session)
print('Extension: ' + extension, flush=True)
eyedata = return_eye_image(session)
filename = 'JobID-' + JOBID + '-eye-diagram' + extension
fout = open(filename, 'wb')
fout.write(eyedata)
fout.close()
print('Created file: ' + filename)
else:
print('Job Results for Job ID ' + JOBID + ' does not include Eye Diagram Image!')
session.write(':SYSTem:GTLocal')
session.close()