# Get All Measurement Results

This Python example, uses the `:MEASure:RESults?` query to return all of the scalar measurements currently shown in Infiniium. The query returns a comma-delimited string which the script places into a list of named tuples. Each named tuple represents a measurement row in the table. Because the script locates the name of each field (table column title) it can handle Infiniium measurement tables that differ in field name and number of fields.

## Script

measure-frequency-and-amplitude-get-all-results.py

    #!python3

    """This program illustrates using :MEASure:RESults? to get
    measurement results and statistics in the Infiniium XR8
    oscilloscopes.
    """

    # Import modules.
    import pyvisa
    import sys
    import collections

    # Global variables.
    oscilloscope_visa_address = "TCPIP0::localhost::hislip0,4880::INSTR"
    timeout = 20000  # 20 seconds.

    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.

    # Default Setup.
    print("Default Setup.")
    Infiniium.write(":SYSTem:DEFault")

    # Use auto-scale to automatically set up oscilloscope.
    print("Autoscale.")
    Infiniium.query(":SYSTem:AUToscale;*OPC?")

    # Stop acquisitions and clear the display.
    Infiniium.write(":ACQuire:STOP")
    Infiniium.write(":ACQuire:CDISplay")  # Clear display.

    # Measure frequency and amplitude.
    source = "CHANnel1"
    Infiniium.write(f":MEASure:HORizontal:FREQuency:SOURce {source}")
    Infiniium.write(":MEASure:HORizontal:FREQuency")

    Infiniium.write(f":MEASure:VERTical:VAMPlitude:SOURce {source}")
    Infiniium.write(":MEASure:VERTical:VAMPlitude")

    # Make 100 acquisitions.
    Infiniium.write(":LTESt:ACQuire:CTYPe:WAVeforms 100")
    Infiniium.write(":LTESt:ACQuire:STATe ON")
    Infiniium.query(":ACQuire:RUN;*OPC?")  # *OPC? required when limit testing.
    Infiniium.write(":LTESt:ACQuire:STATe OFF")

    # Get measurement results using :MEASure:RESults?
    Field = collections.namedtuple("Field", ["name", "value"])
    results = (
        Infiniium.query(":MEASure:RESults? STANdard").strip().replace(",Name", "\nName")
    )
    results_list = results.split("\n")

    measurements = []
    for measurement in results_list:
        field_list = measurement.split(",")
        list_of_fields = []
        for field in field_list:
            (name, value) = field.split("=")
            list_of_fields.append(Field(name, value))
        measurements.append(list_of_fields)

    for measurement in measurements:
        print("*" * 20)
        for field in measurement:
            print(f"{field.name}: {field.value}")

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

    # Exit program.
    exit_program()