# Simulated Instrument Install

This example shows an Infiniium Offline connection which is ideal for developing your scripts because it does not require an instrument. This script installs a simulated electrical instrument in connection 2, displays an eye diagram, and returns an eye height measurement. Notice that the address uses localhost instead of a real-time oscilloscope's computer name.

## Example Script

basic-infiniium-offline.py

    #!python3

    """This program shows how to install a simulated instrument."""

    # Import modules.
    import pyvisa
    import sys

    # Global variables.
    oscilloscope_visa_address = "TCPIP0::localhost::hislip0,4880::INSTR"
    timeout = 60000  # 60 seconds.
    connection = "2"
    channel = "8"

    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."""

        num_errors = int(Infiniium.query(":SYSTem:ERRor:COUNt?"))
        if num_errors:
            for _ in range(num_errors):
                error_string = Infiniium.query(":SYSTem:ERRor:NEXT? DIAGnostic").strip()
                print(f"ERROR: {error_string}")

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

    def install_simulated_instrument(connection, type, channel, signal="NRZ"):
        """Simplified installation of a simulated Infiniium instrument.
        type
            Type of simulated instrument. "VECHannel" is a Virtual 8 Channel
            oscilloscope.
        signal
            Format of signal. NRZ or PAM4.
        """

        Infiniium.write(f":INSTrument:CONNection{connection}:SELection {type}")
        full_ch_name = f"{connection}_{channel}"
        if signal in "NRZ":
            Infiniium.write(f":SOURce{full_ch_name}:FORMat NRZ")
        else:
            Infiniium.write(f":SOURce{full_ch_name}:FORMat PAM4")
        Infiniium.write(f":SOURce{full_ch_name}:SRATe 9.95328E+9")
        Infiniium.write(f":SOURce{full_ch_name}:FILTer:TYPE GAUSsian")
        Infiniium.write(f":SOURce{full_ch_name}:FILTer:CUToff 12.0E+9")
        Infiniium.write(f":SOURce{full_ch_name}:WTYPe DATA")
        Infiniium.write(f":SOURce{full_ch_name}:PLENgth 127")
        Infiniium.write(f":SOURce{full_ch_name}:AMPLitude 90E-3")
        Infiniium.write(f":SOURce{full_ch_name}:NOISe:RN 3.0E-3")
        Infiniium.write(f":SOURce{full_ch_name}:JITTer:RJ 2.0E-12")
        Infiniium.write(f":CHANnel{full_ch_name}:DISPlay ON")
        Infiniium.query(f":CHANnel{full_ch_name}:EYE:DISPlay ON;*OPC?")

    def connections_channels_off(connections_channels_list):
        """Turns off the specified connections_channels."""

        for connection, channels_list in connections_channels_list:
            for channel in channels_list:
                full_ch_name = f"{connection}_{channel}"
                Infiniium.write(f":CHANnel{full_ch_name}:DISPlay OFF")

    # ==========================================================
    # 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.
    Infiniium.write(":SYSTem:DEFault")

    # Install simulated instrument at "connection" and set up "channel".
    install_simulated_instrument(connection, "VECHannel", channel)

    # Autoscale and turn off channnels that haven't been set up.
    Infiniium.query(":SYSTem:AUToscale;*OPC?")
    connections_channels_off([["1", ["1", "2", "3", "4"]]])
    connections_channels_off([["2", ["1", "2", "3", "4", "5", "6", "7"]]])

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

    # Turn on eye height measurement.
    eye_source = f"ECHannel{connection}_{channel}"
    Infiniium.write(f":MEASure:EYE:EHEight:SOURce {eye_source}")
    Infiniium.write(":MEASure:EYE:EHEight")

    # 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")

    # Measure eye width and display results (including statistics).
    print("Eye Height values:")
    print(f"Source waveform: {Infiniium.query(':MEASure:EYE:EHEight:SOURce?').strip()}")
    print(f"Current value: {Infiniium.query(':MEASure:EYE:EHEight?').strip()}")
    print(f"Mean value: {Infiniium.query(':MEASure:EYE:EHEight:MEAN?').strip()}")
    print(f"Std Dev value: {Infiniium.query(':MEASure:EYE:EHEight:SDEViation?').strip()}")
    print(f"Minimum value: {Infiniium.query(':MEASure:EYE:EHEight:MIN?').strip()}")
    print(f"Maximum value: {Infiniium.query(':MEASure:EYE:EHEight:MAX?').strip()}")
    print(f"Count: {Infiniium.query(':MEASure:EYE:EHEight:COUNt?').strip()}")

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

    # Exit program.
    exit_program()