Transfer Files using SCPI


The following Python examples transfer files to and from a remote PC using the MMEM:TRANsfer command.

 

import pyvisa as visa

# Change this variable to the address of your instrument
VISA_ADDRESS = 'TCPIP0::localhost::inst0::INSTR'

# Create a connection (session) to the instrument
resourceManager = visa.ResourceManager()
session = resourceManager.open_resource(VISA_ADDRESS)


# Make sure to enable remote drive access in Remote Interface dialog, else MMEM:TRAN will return an error

# ======================= Transferring from the VNA to the remote PC =======================

# Open file to be stored on local computer. Creates file if not already existing
fp = open("./myTestData.s2p", 'w+')

# Analyzer has file 'testdata.s2p' in default directory.
# The default directory is where the VNA saves files to on default
data = session.query("MMEM:TRAN? './testdata.s2p'")

# Now save the file locally to myTestData.s2p
fp.write(data)
fp.close()

# ======================= Transferring from the remote PC to the VNA  =======================

# Local file to be transferred
fp = open("./myTestData.s2p", 'r')

# Store file content into variable
# Data to be transferred to analyzer file 'testupld.s2p' in default directory.
data = fp.read()                    
session.write(
f"MMEM:TRAN 'testupld.s2p', {data}")

fp.close()