Transfer Binary Data From FlexDCA
This example script demonstrates using the :DISK:FILE:READ?
query to transfer binary data from a graphics file on the PC's N1010A FlexDCA or from an N1000A DCA-X. The program transfers the file's data and not the file. This example script uses the PyVisa query_binary_values()
method, to return the binary data from the captured screen image file.
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. |
GraphicsFileName | The name of the file being transferred. FlexDCA's :DISK:SIMage:SAVE command creates and names the source file. |
newFile | The folder/name of the new file to be saved on the PC. |
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.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'
newfile = 'C:\\TEMP\\NewGraphicsFile.png'
# 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
# Setup FlexDCA
print('Configuring FlexDCA\n')
result = FlexDCA.query(':SYSTem:DEFault;*OPC?')
FlexDCA.write(':DISK:SIMage:FNAMe:USTandard')
FlexDCA.write(':DISK:SIMage:FNAMe:AUPDate')
filetype = FlexDCA.query(':DISK:SIMage:FTYPe?').lower()
result = FlexDCA.query(':DISK:SIMage:SAVE;*OPC?')
GraphicsFileName = FlexDCA.query(':DISK:SIMage:FNAMe?')
print('FlexDCAs image file:\n\t{}'.format(GraphicsFileName), flush=True)
message = ':DISK:FILE:SIZE? {}'.format(GraphicsFileName)
filesize = FlexDCA.query(message)
print('FlexDCAs image size:\n\t{}'.format(filesize), flush=True)
# Get file's image data
message = ':DISK:FILE:READ? ' + GraphicsFileName
print('\nCommand sent to FlexDCA:\n\t{}'.format(message), flush=True)
data = b''
data = FlexDCA.query_binary_values(message,
datatype='s',
header_fmt='ieee',
container=bytes)
if data:
newfile = newfile.replace('png', filetype)
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()