:DISK:FILE:ASCii:READ?
Query Syntax
:DISK:FILE:ASCii:READ? "filename"
Description
Returns the requested text file. The file must be smaller than 65,536 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 DCA-X, use the :DISK:FILE:SIZE?
query.
Requires FlexDCA revision A.05.30 and above.
Example 1
This program demonstrates transferring ASCII data from a file on the N1000A 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 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 file name for the saved file on the PC, but any file name 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:
- Edit the hislip address the
FlexDCA.open_resource()
command to be that of your N1000A. - The PC folder “C:\Temp” must exist.
- Keysight's free I/O libraries that includes VISA and Keysight's Connection Expert application must be installed.
- PyVISA which is a Python front end for the VISA library must be installed.
import visa # import VISA library def return_text_file(FlexDCA): print('Getting an ASCII mask file from N1000A.', flush=True) path = 'C:\\Program Files\\Keysight\\FlexDCA\\Demo\\Masks\\OIF\\' mask = '006.3750 - OIF_CEI-6G-LR.mskx' filename = path + mask try: data = FlexDCA.query(':DISK:FILE:ASCii:READ? "' + filename + '"') except: error = FlexDCA.query(':SYSTem:ERRor:NEXT?') if error[0] != '0': # Error occurred print('Error occurred during file read:') print(' ERROR: ' + error) return data = data.replace('\r\n', '\n') # use Python's line termination character filename = 'C:\\Temp\\' + mask fout = open(filename, 'wt') fout.write(data) fout.close() print(filename, ' is saved.') rm = visa.ResourceManager() # Create an instance of PyVISA's ResourceManager FlexDCA=rm.open_resource('TCPIP0::K-N1000A-20108::hislip0,4880::INSTR') FlexDCA.timeout = 5000 # Set connection timeout to 5s s = FlexDCA.query('*IDN?') print('\nConnection established to:\n\t' + s) # Identify FlexDCA return_text_file(FlexDCA) FlexDCA.write(':SYSTem:GTLocal') FlexDCA.close() print('Connection closed.')
Example 2
This Python script (with PyVISA) tests if a specific limit-line file exists and prints the files contents on the console window. Click here to learn about controlling FlexDCA using Python.
# -*- coding: utf-8 -*- """ Checks is file exists and returns its size in bytes. """ import visa rm = visa.ResourceManager() FlexDCA = rm.open_resource("TCPIP0::localhost::hislip0::INSTR") #Set Timeout - 10 seconds FlexDCA.timeout = 10000 FlexDCA.read_termination = '\n' filePath = '"%USER_DATA_DIR%\\Limit Lines\\TDR Filter S21.lltx"' if FlexDCA.query(':DISK:FILE:EXISts? ' + filePath) == '1': print('File exists!') contents = FlexDCA.query(':DISK:FILE:ASCii:READ? ' + filePath) print('File contents:\n\n', contents) else: print('File not found.') FlexDCA.write(':SYSTem:GTLocal') FlexDCA.close()