Transfer Text File Data From FlexDCA

This example script demonstrates using the :DISK:FILE:READ? binary query to transfer data from a text file (Y-data waveform) on the PC's N1010A FlexDCA or from an N1000A DCA-X. The program transfers the file's data and not the file. The script installs a simulated module in FlexDCA's slot 5. Reads contents of saved Y-values waveform text file and saves the contents to a text file on the PC. You can manually import the new text file into FlexDCA's waveform memory and compare it to original waveform. This example script uses the PyVisa query_binary_values() method, to return the binary data from the captured waveform file.

Script Variables
Variable Description
ADDRESS Provides the hislip address of N1010A FlexDCA on the PC. A commented out version of the variable show of an address example for an N1000A DCA-X. This allows you to easily test the script on both environments.
WaveformFileName The name (including path) of the file being read. FlexDCA's :DISK:WAVeform:SAVE command creates and names the source file.
newFile The name (including path) of the new file to be saved on the PC. The name of the new file is the same as the read file with the exception of the path.

This script reduces the size of the read buffer to 1024 bytes with Pyvisa's ResourceManager object's chunk_size attribute. Larger sizes may result in intermittent data transfer failures. This may or may not occur in your setup. The default setting is 20,480 (20 * 1024) bytes.

Example Script

Copy

DISK_FILE_READ_text.py

import pyvisa as visa
#ADDRESS = 'TCPIP0::localhost::hislip0,4880::INSTR'
ADDRESS = 'TCPIP0::N1000A-12345::hislip0,4880::INSTR'
destinationFolder = 'C:\\TEMP'
# Connect and configure FlexDCA
rm = visa.ResourceManager()
FlexDCA = rm.open_resource(ADDRESS)
FlexDCA.timeout = 10000  # Set connection timeout to 10s
FlexDCA.read_termination = '\n'
FlexDCA.write_termination = '\n'
FlexDCA.chunk_size = 1024
# Setup FlexDCA
print('Configuring FlexDCA\n')
FlexDCA.query(':SYSTem:DEFault;*OPC?')
for slot in '12345678':
    for letter in 'ABCD':
        channel = slot + letter
        FlexDCA.write(':CHANnel' + channel + ':DISPlay OFF')
FlexDCA.write(':EMODules:SLOT5:SELection QEM')
FlexDCA.write(':SOURce5A:FORMat NRZ')
FlexDCA.write(':SOURce5A:DRATe 9.95328E+9')
FlexDCA.write(':SOURce5A:WTYPe DATA')
FlexDCA.write(':SOURce5A:PLENgth 127')
FlexDCA.write(':CHANnel5A:DISPlay ON')
FlexDCA.query(':SYSTem:MODE OSCilloscope;*OPC?')
FlexDCA.query(':TRIGger:PLOCk ON;*OPC?')
FlexDCA.query(':SYSTem:AUToscale;*OPC?')
FlexDCA.write(':ACQuire:STOP')
FlexDCA.write(':ACQuire:CDISplay')
FlexDCA.query(':ACQuire:SINGle;*OPC?')
FlexDCA.write(':DISK:WAVeform:FNAMe:USTandard')
FlexDCA.write(':DISK:WAVeform:FNAMe:AUPDate')
FlexDCA.write(':DISK:WAVeform:SAVE:SOURce CHAN5A')
FlexDCA.write(':DISK:WAVeform:SAVE:FTYPe WYValues')
FlexDCA.write(':DISK:WAVeform:SAVE')
WaveformFileName = FlexDCA.query(':DISK:WAVeform:FNAMe?').replace('"','')
print('FlexDCAs waveform:\n\t{}'.format(WaveformFileName))
# Get file's waveform data
message = ':DISK:FILE:READ? "' + WaveformFileName + '"'
print('\nCommand sent to FlexDCA:\n\t{}'.format(message))
data = b''
data = FlexDCA.query_binary_values(message,
                                   datatype='s',
                                   header_fmt='ieee',
                                   container=bytes)
i = WaveformFileName.rfind('\\')
newfile = destinationFolder + WaveformFileName[i:]
if data:
    with open(newfile, 'wb') as fout:
        fout.write(data)
    print('\nNew file on PC:\n\t{}\n'.format(newfile))
else:
    print(':DISK:FILE:READ? failed!')
FlexDCA.write(':SYSTem:GTLocal')
FlexDCA.close()