#This script configures all the parameters of the burst
import pyvisa
import AFG_7000

try:
    # Initialize VISA
    rm = pyvisa.ResourceManager()

    # List connected resources
    resources = rm.list_resources()
    print(f"\n\n\nConnected devices: {resources}")

    #Intrumetn TCP/IP address
    address_listed = resources[1]
    address_not_listed = "TCPIP0::192.168.0.59::inst0::INSTR"

    #If you use NI MAX or similar, you can also use one of the adresses in the list 
    master = rm.open_resource(address_not_listed)

    #Master Encoding: Necessary if you use non-ascii characters, like accented vocals.
    master.encoding = "latin-1"

    #Initialize AWG_5062
    AFG = AFG_7000.AFG7000(master)
except Exception as e: print(f"The following exception has occured while connecting with the instrument: {e}")




##################################################################################################################

channel = AFG_7000.Channel.Channel1

#Carrier parameters
amplitude: float = 1
unit = AFG_7000.VoltageUnit.VPP
offset: float = 0  #V
frequency: float = 1000000  #Hz
phase: float = 0  #°
shape = AFG_7000.Shape1.Lorentz  #DC is not valid for burst

#Burst parameters
mode_burst: AFG_7000.BurstMode = AFG_7000.BurstMode.One_cycle
burst_tipe: AFG_7000.Ncycles = AFG_7000.Ncycles.Number
number_of_cycles: int = 5
delay: float = 0  #s
wait_trigger_on = AFG_7000.WaitState.First_sample  #Parameter available only for exponential and arbitrary waveforms
duration_burst: float = 0.000001  #s  Parameter available for noise waveform

##################################################################################################################

try:
    AFG.Initialize()
    AFG.ConfigureStandardWaveform(channel, amplitude, unit, offset, frequency, phase, shape, "")
    AFG.ConfigureBurst(channel, AFG_7000.State.ON, mode_burst, burst_tipe, number_of_cycles, delay, wait_trigger_on, duration_burst)

    input("Press return to start")
    AFG.SetOutputState(channel, AFG_7000.State.ON)

    while input("Press t to send trigger, any other key to close ") == "t":
            AFG.SendTrigger()
            AFG.ReleaseTrigger()
    AFG.Close()
except Exception as e: print(f"{e}")