Transfer ASCII data from 86100D to PC

This program demonstrates using the :DISK:FILE:ASCii:READ? query to transfer ASCII data from a file on the 86100D to the PC. The query takes the filename of the ASCII source file as the argument . The PyVisa query() method is used to return the data. The program then places the data in an ASCii file in the script's folder.

The program transfers the file's data and not the file. The program uses the same filename for the saved file on the PC, but any filename could have been used. To confirm that the data has been correctly transfered, simply open the file in a text editor.

Python strings use a newline character '\n' to indicate the end of a line and the newline character is automatically translated to '\r\n' when written to a text file. Since the returned data includes '\r\n' at the end of every line, these characters become '\r\r\n' in the saved file. To avoid this the program replaces every instance of '\r\n' with '\n'.

Example Script

Copy

DISK_FILE_ASCii_READ.py

""" Example of FlexDCA's ":DISK:FILE:ASCii:READ?" command.
Transfer a text file from an DCA-X to the PC. The file is a mask file
that is in the DCA-X's demo folder. The file is saved in the
script's folder. The returned text file uses the '\r\n' characters to
mark line ends. But because Python strings only use the '\n' character, we
translate '\r\n' to '\n'. The Python fout.write() method automatically
translates the '\n' character back to '\r\n' characters for Windows.
If we did not do the translation on the returned data, line endings
in the file would be '\r\r\n'.
"""

import pyvisa as visa  # import VISA library

ADDRESS = 'TCPIP0::localhost::hislip0,4880::INSTR'
#ADDRESS = 'TCPIP0::K-86100D-00003::hislip0,4880::INSTR'  # DCA-X
MASKNAME = '%DEMO_DIR%\\Masks\\OIF\\006.3750 - OIF_CEI-6G-LR.mskx'

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


FlexDCA = open_flexdca_connection(ADDRESS)
print('\nGetting the ASCII mask file from DCA-X.', flush=True)
data = FlexDCA.query(':DISK:FILE:ASCii:READ? "' + MASKNAME + '"')
data = data.replace('\r\n', '\n')  # Python's line termination character
fout = open('006.3750 - OIF_CEI-6G-LR.mskx', 'wt')
fout.write(data)
fout.close()
print('\nSaved file: 006.3750 - OIF_CEI-6G-LR.mskx')
FlexDCA.write(':SYSTem:GTLocal')
FlexDCA.close()