# :DISK:FILE:ASCii:READ?

:DISK File Transfer Commands

- :DISK:FILE:ASCii:READ?
- :DISK:FILE:EXISts?
- :DISK:FILE:READ?
- :DISK:FILE:SIZE?
- :DISK:FILE:TIMestamp?
- :DISK:FILE:WRITe?

## Query Syntax

    :DISK:FILE:ASCii:READ? "filename"

## Description

Returns the requested text file. The file must be smaller than 256,000 characters. If the file does not contain text, the return string will be terminated at the first zero (0) values byte in the file. To return a binary file, use the `:DISK:FILE:READ?` command. To return the size of a file that is on the system running Infiniium 2026, use the `:DISK:FILE:SIZE?` query.

SCPI commands that perform general file I/O operations are limited to Standard Infiniium File Types and Standard Infiniium Folders.

## Example 1

This program demonstrates transferring ASCII data from a file on the Infiniium system to the host computer. 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 a new ASCii file in the PC's C:\Temp 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 transferred, 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'.

Before running this program, you must:

1. Edit the hislip address the `Infiniium.open_resource()` command to be that of your oscilloscope.
2. The PC folder “C:\Temp” must exist.
3. Keysight's free I/O libraries that includes VISA and Keysight's Connection Expert application must be installed.
4. PyVISA which is a Python front end for the VISA library must be installed.

    import pyvisa  # PyVISA package

    def return_text_file(Infiniium):
        print('Getting an ASCII mask file from oscilloscope.', flush=True)
        path = '%DEMO_DIR%\\Masks\\OIF\\'
        mask = '006.3750 - OIF_CEI-6G-LR.mskx'
        filename = path + mask
        try:
            data = Infiniium.query(f':DISK:FILE:ASCii:READ? "{filename}"')
        except:
            error = Infiniium.query(':SYSTem:ERRor:NEXT?')
            if error[0] != '0': # Error occurred
                print('Error occurred during file read:')
                print(f' ERROR: {error}')
            return
        data = data.replace('\r\n', '\n') # use Python's line termination character
        filename = f'C:\\Temp\\{mask}'
        fout = open(filename, 'wt')
        fout.write(data)
        fout.close()
        print(f'{filename} is saved.')

    rm = pyvisa.ResourceManager() # Create an instance of PyVISA's ResourceManager
    Infiniium = rm.open_resource('TCPIP0::localhost::hislip0,4880::INSTR')
    Infiniium.timeout = 5000 # Set connection timeout to 5s
    s = Infiniium.query('*IDN?')
    print(f'\nConnection established to:\n\t{s}') # Identify Infiniium
    return_text_file(Infiniium)
    Infiniium.write(':SYSTem:GTLocal')
    Infiniium.close()

## Example 2

This Python script (with PyVISA) tests if a specific limit-line file exists and prints the file's contents on the console window. To learn about controlling Infiniium 2026 using Python, see Python Example Scripts.

    """
    Checks if the file exists and returns its size in bytes.
    """
    import pyvisa  # PyVISA package

    rm = pyvisa.ResourceManager()
    Infiniium = rm.open_resource("TCPIP0::localhost::hislip0,4880::INSTR")

    #Set Timeout - 10 seconds
    Infiniium.timeout =  10000
    Infiniium.read_termination = '\n'

    filePath = '"%DEMO_DIR%\\Limit Lines\\Demo\\N1027-63008\\TDR Demo Board Filter S21.lltx"'
    print(filePath)
    if Infiniium.query(f':DISK:FILE:EXISts? {filePath}') == '1':
        print('File exists!')
        contents = Infiniium.query(f':DISK:FILE:ASCii:READ? {filePath}')
        print(f'File contents:\n\n{contents}')
    else:
        print('File not found.')
    Infiniium.write(':SYSTem:GTLocal')
    Infiniium.close()