Transfer Binary Data to FlexDCA

This program demonstrates using the :DISK:FILE:WRITe? query to transfer binary data from a file on the PC to a DCA-X. Change the following script variables to match your needs:

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.
filename The name of the file being transferred.
fileToCopy The folder/name of the file being transferred.
newFile The folder/name of the new file.

This script reduces the size of the write 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_WRITe.py

import pyvisa as visa
# Address of N1010A FlexDCA on PC
ADDRESS = 'TCPIP0::localhost::hislip0,4880::INSTR'
# Example address of N1000A DCA-X
#ADDRESS = 'TCPIP0::N1000A-12345::hislip0,4880::INSTR'
filename = 'GraphicsFile.jpg'
fileToCopy = 'C:\\TEMP\\' + filename
# newFile includes double quotes required by :DISK:FILE:WRITE
newFile = '"C:\\Users\\kentb\\OneDrive - Keysight Technologies\
\\Documents\\Keysight\\FlexDCA\\Screen Images\\' + filename + '"'
# Connect and configure FlexDCA
rm = visa.ResourceManager()
FlexDCA = rm.open_resource(ADDRESS)
FlexDCA.timeout = 20000  # Set connection timeout to 20s
FlexDCA.read_termination = '\n'
FlexDCA.write_termination = '\n'
FlexDCA.chunk_size = 1024
data = b''  # Python 3 byte string (bytes not unicode)
with open(fileToCopy, 'rb') as fin:
    data = fin.read()
print('Graphics file read:\n\t{}'.format(fileToCopy), flush=True)
message = ':DISK:FILE:WRITe? {}, '.format(newFile)
bytes_sent = FlexDCA.write_binary_values(message,
                                         data,
                                         datatype='s',
                                         is_big_endian=False
print('Command sent:\n\t{}'.format(message))
print('File is on FlexDCA:\n\t{}'.format(newFile))
print('Bytes in file: {}\n\t'.format(bytes_sent))
FlexDCA.write(':SYSTem:GTLocal')
FlexDCA.close()