Transfer binary data from oscilloscope to PC

This example script demonstrates using the :DISK:FILE:READ? query to transfer binary data from a file on the system running Infiniium to the script's folder. The program transfers the file's data and not the file. The program uses the same filename for the saved file on the PC, but any filename could have been used. To confirm that the data has been correctly transferred, simply double-click on the resulting file to view it. This example script uses the PyVISA method query_binary_values(), to return the binary data from the captured screen image file. This method automatically removes the binary data's IEEE header. Leaving this header in the data would result in an invalid graphics file.

Example Script

disk-file-read.py

#!python3

"""This program illustrates transferring a binary file from
the oscilloscope disk to the host computer in the
Infiniium XR8 oscilloscope.
"""

# Import modules.
import pyvisa
import sys

# Global variables.
oscilloscope_visa_address = "TCPIP0::localhost::hislip0,4880::INSTR"
timeout = 20000  # 20 seconds.
standard_folder = "C:\\Users\\pw5670\\Documents\\Keysight\\Infiniium\\"


def exit_program():
    """Exit program."""

    # Close connection to oscilloscope.
    sys.stdout.write("Closing oscilloscope connection.\n")
    Infiniium.write(":SYSTem:GTLocal")  # Unlock GUI.
    Infiniium.clear()  # Clear oscilloscope communications interface.
    Infiniium.close()  # Close communications interface to oscilloscope.
    rm.close()  # Close resource manager.
    print("End of program.")
    sys.exit()


def check_error_queue(when):
    """Check error queue."""

    errors_found = False
    while True:
        # Keep reading errors until "No error".
        error_string = Infiniium.query(":SYSTem:ERRor:NEXT? DIAGnostic")
        if error_string:  # If there is an error string value.

            if error_string.find("0,", 0, 2) == -1:  # Not "No error".
                errors_found = True
                print(f"ERROR: {error_string}")

            else:  # "No error"
                break

        else:  # :SYSTem:ERRor:NEXT? DIAGnostic should always return string.
            errors_found = True
            print("ERROR: :SYSTem:ERRor:NEXT? DIAGnostic returned nothing.")
            break

    if errors_found:
        print(f"Exited because error(s) found when: '{when}'")
        exit_program()


# ==========================================================
# Main program:
# ==========================================================

# Connect and initialize oscilloscope.
rm = pyvisa.ResourceManager("C:\\Windows\\System32\\visa64.dll")
try:
    Infiniium = rm.open_resource(oscilloscope_visa_address)
except Exception:
    print(
        f"Unable to connect to oscilloscope at {oscilloscope_visa_address}. Aborting program."
    )
    sys.exit()

Infiniium.timeout = timeout  # Set global timeout.
Infiniium.clear()  # Clear the instrument bus.
# Lock GUI happens automatically.

# Move file from the oscilloscope disk to the local computer.
image_file = f"{standard_folder}screen_image.png"
file_bytes = Infiniium.query_binary_values(
    f':DISK:FILE:READ? "{image_file}"', datatype="s", container=bytes
)
f = open(image_file, "wb")
f.write(file_bytes)
f.close()
print(f"Oscilloscope file copied to local computer: {image_file}")

# Check error queue.
check_error_queue("End of program")

# Exit program.
exit_program()

For more information, read the information on the :DISK:FILE:READ? query