コード例 #1
0
def awgsettingssquarewave():
    global awgsess, seqhandl
    message = []
    # Shaping parameters
    voltag = []
    voltag.append(float(request.args.get('voltag1')))
    voltag.append(float(request.args.get('voltag2')))
    pointnum = []
    pointnum.append(int(request.args.get('pointnum1')))
    pointnum.append(int(request.args.get('pointnum2')))
    wavefom = ([voltag[0]] * pointnum[0] + [voltag[1]] * pointnum[1])

    stat = AWG.CreateArbWaveform(awgsess, wavefom)
    print(Fore.YELLOW + "Arb Waveform Created: %s" % stat[0])
    message += ['Waveform created: %s <%s>' % (stat[1], status_code(stat[0]))]
    stat = AWG.CreateArbSequence(
        awgsess, [stat[1]],
        [1])  # loop# canbe >1 if longer sequence is needed in the future!
    print(Fore.YELLOW + "Arb Sequence Created: %s" % stat[0])
    seqhandl = stat[1]
    print("seq handle in set-waveform is %s" % seqhandl)
    message += [
        'Sequence assembled: %s <%s>' % (stat[1], status_code(stat[0]))
    ]

    return jsonify(message=message)
コード例 #2
0
ファイル: VSA.py プロジェクト: supergravity/PYQUM
def Configure_Acquisition(session, PreselectorEnabled, Frequency, Power, Bandwidth, Time, TriggerSource):
    '''
    Sets the most-often used measurement parameters. These settings have no effect on the hardware until Measurements.Initiate() is called.
    PreselectorEnabled 
    Set to true to enable the Preselector. Set to false to select the "Bypass" path (changes the microwave downcoverter [M9361A] RF input range to 2.25 GHz to 26.5 GHz). Requires a Preselector (M9360A) module in the configuration.
    Frequency 
    The nominal (sometimes called center) frequency, in hertz, of the signal to be measured. The allowable range of values depend on hardware configuration, absolute limits are 50 MHz to 26.5 GHz. This parameter sets Acquisition Frequency.
    Power 
    Expected RMS power of the input signal, in dBm. Limits depend on hardware configuration. Absolute max is +30 dBm. This parameter sets Acquisition Power.
    Bandwidth 
    The digital IF will be configured to provide at least the bandwidth specified. The allowable range of values depend on hardware configuration. The absolute maximum is 250 MHz. This parameter sets Acquisition Bandwidth.
    Time 
    Approximate acquisition time of the measurement, in seconds. The allowable range of values depend on bandwidth, absolute maximum is 100 seconds. This parameter sets Acqusition Time. NOTE: The minimum settable acquisition time is the larger of the two quantities: 3/SampleRate and 1e-8 seconds (that is, 10ns).
    TriggerSource 
    The trigger source. May be AgM9392TriggerSourceImmediate, AgM9392TriggerSourceVideo, AgM9392TriggerSourceExternal. This parameter sets Trigger Source.
    '''
    AGM = dll.AgM9392_ConfigureAcquisition
    AGM.restype = c_int
    status = AGM(c_long(session), c_bool(PreselectorEnabled), c_double(Frequency), c_double(Power), c_double(Bandwidth), c_double(Time), c_long(TriggerSource))
    if status == 0:
        set_status(mdlname, dict(Acquisition="Configured Successfully"))
    else: set_status(mdlname, dict(Acquisition="Error: " + str(status)))
    if eval(debugger):
        print(Fore.LIGHTGREEN_EX + "%s's acquisition configured: %s" % (mdlname, status_code(status)))
    return status_code(status)
コード例 #3
0
ファイル: machine.py プロジェクト: Bocheng662533/PYQUM
def awggenerate():
    global awgsess
    message = []
    gstatus = AWG.Init_Gen(awgsess)
    message += ['Generate Pulse: %s' % (status_code(gstatus))]
    sstatus = AWG.Send_Pulse(awgsess, 1)
    message += ['Send Pulse: %s' % (status_code(sstatus))]
    return jsonify(message=message, gstatus=gstatus, sstatus=sstatus)
コード例 #4
0
ファイル: machine.py プロジェクト: zeyanchen/PYQUM
def vsaabout():
    global vsasess
    message = []
    status = VSA.model(vsasess) # model
    message += ['Model: %s (%s)' % (status[1], status_code(status[0]))]
    status = VSA.resource_descriptor(vsasess) # resource descriptor
    message += ['Resource Descriptor: %s (%s)' % (status[1], status_code(status[0]))]
    status = VSA.acquisition_time(vsasess) # acquisition time
    message += ['Acquisition Time: %s (%s)' % (status[1], status_code(status[0]))]
    return jsonify(message=message)
コード例 #5
0
ファイル: VSA.py プロジェクト: LanHsuanLee/PYQUM
def Arm_Measure(session):
    """[Arm the Measurement]
    Arms the measurement started by Initiate().
    """
    AGM = dll.AgM9392_Arm
    AGM.restype = c_int
    status = AGM(c_long(session))
    print(Fore.LIGHTGREEN_EX + "%s's measurement Armed: %s" %
          (mdlname, status_code(status)))
    return status_code(status)
コード例 #6
0
ファイル: VSA.py プロジェクト: LanHsuanLee/PYQUM
def Init_Measure(session):
    """[Initiate the Measurement]
    Initiates a measurement with the settings specified by the Acquisition and Trigger interfaces.
    """
    AGM = dll.AgM9392_Initiate
    AGM.restype = c_int
    status = AGM(c_long(session))
    print(Fore.GREEN + "%s's measurement Initiated: %s" %
          (mdlname, status_code(status)))
    return status_code(status)
コード例 #7
0
ファイル: VSA.py プロジェクト: supergravity/PYQUM
def Arm_Measure(session):
    """[Arm the Measurement]
    Arms the measurement started by Initiate().
    """
    AGM = dll.AgM9392_Arm
    AGM.restype = c_int
    status = AGM(c_long(session))
    if status != 0:
        print("Arm_Measure Error: " + str(status)) # Streaming somehow will crash with saving data at some point so we'll just make do with print only
    if eval(debugger):
        print(Fore.LIGHTGREEN_EX + "%s's measurement Armed: %s" % (mdlname, status_code(status)))
    return status_code(status)
コード例 #8
0
ファイル: VSA.py プロジェクト: supergravity/PYQUM
def Init_Measure(session):
    """[Initiate the Measurement]
    Initiates a measurement with the settings specified by the Acquisition and Trigger interfaces.
    """
    AGM = dll.AgM9392_Initiate
    AGM.restype = c_int
    status = AGM(c_long(session))
    if status != 0:
        print("Init_Measure Error: " + str(status)) # Streaming somehow will crash with saving data at some point so we'll just make do with print only
    if eval(debugger):
        print(Fore.GREEN + "%s's measurement Initiated: %s" % (mdlname, status_code(status)))
    return status_code(status)
コード例 #9
0
ファイル: machine.py プロジェクト: Bocheng662533/PYQUM
def vsasettings():
    global vsasess, vsasr, vsasn
    message = []

    acquis = request.args.get('acquis')
    preselect = request.args.get('preselect')
    lofreq = request.args.get('lofreq')
    lopowa = request.args.get('lopowa')
    lobwd = request.args.get('lobwd')

    # Main settings:
    stat = VSA.acquisition_time(vsasess, action=['Set', float(acquis)])
    message += ['acquisition time: ' + status_code(stat[0])]
    stat = VSA.preselector_enabled(vsasess,
                                   action=['Set', bool(int(preselect))])
    message += ['Preselector: ' + status_code(stat[0])]
    stat = VSA.frequency(vsasess, action=['Set', float(lofreq) * 1e9])
    message += ['LO frequency: ' + status_code(stat[0])]
    stat = VSA.power(vsasess, action=['Set', float(lopowa)])
    message += ['LO power: ' + status_code(stat[0])]
    stat = VSA.bandwidth(vsasess, action=['Set', float(lobwd) * 1e6])
    message += ['LO Bandwidth: ' + status_code(stat[0])]

    triggersource = request.args.get('triggersource')
    triggerdelay = request.args.get('triggerdelay')
    extlevel = request.args.get('extlevel')
    extslope = request.args.get('extslope')
    triggertimeout = request.args.get('triggertimeout')

    # Trigger settings:
    stat = VSA.trigger_source(vsasess, action=['Set', int(triggersource)])
    message += ['Trigger Source: ' + status_code(stat[0])]
    stat = VSA.trigger_delay(vsasess, action=['Set', float(triggerdelay)])
    message += ['trigger delay: ' + status_code(stat[0])]
    stat = VSA.external_trigger_level(vsasess, action=['Set', float(extlevel)])
    message += ['External Trigger Level: ' + status_code(stat[0])]
    stat = VSA.external_trigger_slope(vsasess, action=['Set', int(extslope)])
    message += ['External Trigger Slope: ' + status_code(stat[0])]
    stat = VSA.trigger_timeout(vsasess, action=['Set', int(triggertimeout)])
    message += ['Trigger Timeout (ms): ' + status_code(stat[0])]

    # Initiate measurement:
    stat = VSA.Init_Measure(vsasess)
    message += ['Initiate Measurement: ' + stat]

    # For data plotting:
    vsasr = VSA.sample_rate(vsasess)[1]
    message += ['Sampling Rate: %sHz' % (vsasr)]
    vsasn = VSA.samples_number(vsasess)[1]
    message += ['Samples Number: %s' % (vsasn)]

    return jsonify(message=message)
コード例 #10
0
ファイル: machine.py プロジェクト: zeyanchen/PYQUM
def awgsettingsprepare():
    global awgsess
    message = []
    predist = request.args.get('predist')
    stat = AWG.predistortion_enabled(awgsess, action=['Set',int(predist)])
    message += ['predistortion enabled: %s <%s>' %(stat[1], status_code(stat[0]))]
    outpmode = request.args.get('outpmode')
    stat = AWG.output_mode_adv(awgsess, action=['Set',int(outpmode)])
    message += ['advanced output mode: %s <%s>' %(stat[1], status_code(stat[0]))]
    samprat = request.args.get('samprat')
    stat = AWG.arb_sample_rate(awgsess, action=['Set',float(samprat)])
    message += ['sample rate: %s <%s>' %(stat[1], status_code(stat[0]))]
    return jsonify(message=message)
コード例 #11
0
def awgsettingsmain():
	global awgsess
	message = []
	refclk = request.args.get('refclk')
	stat = AWG.ref_clock_source(awgsess, action=['Set',int(refclk)])
	message += ['Reference Clock Source: %s <%s>' %(stat[1], status_code(stat[0]))]
	predist = request.args.get('predist')
	stat = AWG.predistortion_enabled(awgsess, action=['Set',int(predist)])
	message += ['predistortion enabled: %s <%s>' %(stat[1], status_code(stat[0]))]
	outpmode = request.args.get('outpmode')
	stat = AWG.output_mode_adv(awgsess, action=['Set',int(outpmode)])
	message += ['advanced output mode: %s <%s>' %(stat[1], status_code(stat[0]))]
	samprat = request.args.get('samprat')
	stat = AWG.arb_sample_rate(awgsess, action=['Set',float(samprat)])
	message += ['sample rate: %s <%s>' %(stat[1], status_code(stat[0]))]

	# Marker Settings:
	active = request.args.get('active')
	stat = AWG.active_marker(awgsess, action=['Set',active])
	message += ['active marker: %s <%s>' %(stat[1], status_code(stat[0]))]
	delay = request.args.get('delay')
	stat = AWG.marker_delay(awgsess, action=['Set',float(delay)])
	message += ['marker delay: %s <%s>' %(stat[1], status_code(stat[0]))]
	pulsew = request.args.get('pulsew')
	stat = AWG.marker_pulse_width(awgsess, action=['Set',float(pulsew)])
	message += ['marker pulse width: %s <%s>' %(stat[1], status_code(stat[0]))]
	source = request.args.get('source')
	stat = AWG.marker_source(awgsess, action=['Set',int(source)])
	message += ['marker source: %s <%s>' %(stat[1], status_code(stat[0]))]

	return jsonify(message=message)
コード例 #12
0
def awgabout():
    global awgsess
    message = []
    status = AWG.model(awgsess)  # model
    message += ['Model: %s (%s)' % (status[1], status_code(status[0]))]
    status = AWG.active_marker(awgsess)  # active marker
    message += ['Active Marker: %s (%s)' % (status[1], status_code(status[0]))]
    status = AWG.marker_delay(awgsess)  # marker delay
    message += ['Marker Delay: %s (%s)' % (status[1], status_code(status[0]))]
    status = AWG.marker_pulse_width(awgsess)  # marker pulse width
    message += [
        'Marker Pulse Width: %s (%s)' % (status[1], status_code(status[0]))
    ]
    status = AWG.marker_source(awgsess)  # marker source
    message += ['Marker Source: %s (%s)' % (status[1], status_code(status[0]))]
    status = AWG.predistortion_enabled(awgsess)  # predistortion enabled
    message += [
        'Predistortion Enabled: %s (%s)' % (status[1], status_code(status[0]))
    ]
    status = AWG.output_mode_adv(awgsess)  # advanced output mode
    message += [
        'Advanced Output Mode: %s (%s)' % (status[1], status_code(status[0]))
    ]
    status = AWG.arb_sample_rate(awgsess)  # sample rate
    message += ['Sample Rate: %s (%s)' % (status[1], status_code(status[0]))]

    return jsonify(message=message)
コード例 #13
0
ファイル: machine.py プロジェクト: zeyanchen/PYQUM
def awgsettingsmarker():
    global awgsess
    message = []
    active = request.args.get('active')
    stat = AWG.active_marker(awgsess, action=['Set',active])
    message += ['active marker: %s <%s>' %(stat[1], status_code(stat[0]))]
    delay = request.args.get('delay')
    stat = AWG.marker_delay(awgsess, action=['Set',float(delay)])
    message += ['marker delay: %s <%s>' %(stat[1], status_code(stat[0]))]
    pulsew = request.args.get('pulsew')
    stat = AWG.marker_pulse_width(awgsess, action=['Set',float(pulsew)])
    message += ['marker pulse width: %s <%s>' %(stat[1], status_code(stat[0]))]
    source = request.args.get('source')
    stat = AWG.marker_source(awgsess, action=['Set',int(source)])
    message += ['marker source: %s <%s>' %(stat[1], status_code(stat[0]))]
    return jsonify(message=message)
コード例 #14
0
ファイル: machine.py プロジェクト: zeyanchen/PYQUM
def vsasettings():
    global vsasess
    message = []
    acquis = request.args.get('acquis')
    stat = VSA.acquisition_time(vsasess, action=['Set',float(acquis)])
    message += ['acquisition time: ' + status_code(stat[0])]
    return jsonify(message=message)
コード例 #15
0
ファイル: VSA.py プロジェクト: LanHsuanLee/PYQUM
def Get_Data(session, ComplexDataBufferSize):
    """[Extracting Complex Data]
    Gets the I/Q measurement results.
    ComplexData:
        Array to hold the measurement data. Allocated by the caller (for performance). 
        The array size should be >= 2 * Measurements.NumberOfSamples (2* since the array will hold interleaved complex data)
    """
    AGM = dll.AgM9392_GetData
    AGM.restype = c_int
    ComplexData = (c_double * int(ComplexDataBufferSize))()
    ComplexDataActualSize = c_long()
    NumberCopied = c_long()
    status = AGM(c_long(session), c_long(ComplexDataBufferSize),
                 byref(ComplexData), byref(ComplexDataActualSize),
                 byref(NumberCopied))
    answer = {}
    answer["ComplexData"] = [x for x in ComplexData]
    answer["ComplexDataActualSize"], answer[
        "NumberCopied"] = ComplexDataActualSize.value, NumberCopied.value
    if status == 0:
        set_status(mdlname, {stack()[0][3]: answer
                             })  #logging the name and value of the attribute
    else:
        set_status(mdlname, {stack()[0][3]: "Error: " + str(status)})
    if eval(debugger):
        print(Fore.LIGHTWHITE_EX +
              "%s out of %s actual %s's Data extracted & copied: %s" %
              (NumberCopied.value, ComplexDataActualSize.value, mdlname,
               status_code(status)))
    return status, answer
コード例 #16
0
ファイル: correction.py プロジェクト: supergravity/PYQUM
def awgreset():
    global awgsess
    awgsess = AWG.InitWithOptions()
    AWG.Abort_Gen(awgsess)
    status = AWG.model(awgsess)  # model
    print('Model: %s (%s)' % (status[1], status_code(status[0])))
    return jsonify(message=awgsess)
コード例 #17
0
ファイル: AWG.py プロジェクト: RuRu110307/PYQUM
def InitWithOptions(IdQuery=False,
                    Reset=False,
                    OptionsString='Simulate=false, DriverSetup=DDS=false'):
    '''[Initialize the connection]
    status = InitWithOptions(IdQuery, Reset, OptionsString)
    '''
    # rs = address(mdlname, reset=eval(debugger)) # Instrument's Address
    ad = address()
    rs = ad.lookup(mdlname, 2)  # Instrument's Address
    Resource = bytes(rs, 'ascii')
    Option = bytes(OptionsString, 'ascii')  # utf-8
    Session = c_long()

    AGM = dll.AgM933x_InitWithOptions  # from AgM933x.chm
    AGM.restype = c_int
    status = AGM(c_char_p(Resource), c_bool(IdQuery), c_bool(Reset),
                 c_char_p(Option), byref(Session))
    msession = Session.value
    if status == 0:
        set_status(mdlname,
                   dict(state="Initialized Successfully", session=msession))
    else:
        set_status(mdlname, dict(state="Error: " + str(status)))
        msession = get_status(mdlname)["session"]
    print(Fore.GREEN + "%s's connection Initialized at session %s: %s" %
          (mdlname, msession, status_code(status)))

    return msession
コード例 #18
0
def Abort_Gen(session):
    """[Abort Waveform Generation]
    """
    AGM = dll.KtMAwg_AbortGeneration
    AGM.restype = c_int
    status = AGM(c_long(session))
    print(Back.WHITE + Fore.BLACK + "%s's generation Aborted: %s" %(mdlname, status_code(status)))
    return status
コード例 #19
0
def Send_Pulse(session, triggernum=1):
    """[Sending Software Trigger to generate single/burst pulse]
    """
    AGM = dll.KtMAwg_TriggerSendNumberedSoftwareTrigger
    AGM.restype = c_int
    status = AGM(c_long(session), c_long(triggernum))
    if eval(debugger):
        print(Back.YELLOW + Fore.MAGENTA + "%s: %s" %(stack()[0][3], status_code(status)))
    return status
コード例 #20
0
ファイル: AWG.py プロジェクト: RuRu110307/PYQUM
def Init_Gen(session):
    """[Initiate Waveform Generation]
    """
    AGM = dll.AgM933x_InitiateGeneration
    AGM.restype = c_int
    status = AGM(c_long(session))
    print(Fore.GREEN + "%s's generation Initiated: %s" %
          (mdlname, status_code(status)))
    return status
コード例 #21
0
ファイル: AWG.py プロジェクト: RuRu110307/PYQUM
def Clear_ArbMemory(session):
    """Removes all previously created arbitrary waveforms and sequences from the instrument's memory and invalidates all waveform and sequence handles. 
    If either a waveform or sequence is currently being generated, an error will be reported.
    """
    AGM = dll.AgM933x_ClearArbMemory
    AGM.restype = c_int
    status = AGM(c_long(session))
    print(Fore.GREEN + "%s's arbitrary memory ALL Cleared: %s" %
          (mdlname, status_code(status)))
    return status
コード例 #22
0
ファイル: VSA.py プロジェクト: supergravity/PYQUM
def close(session):
    '''[Close the connection]
    '''
    AGM = dll.AgM9392_close
    AGM.restype = c_int
    status = AGM(c_long(session))
    if status == 0:
        set_status(mdlname, dict(state="Closed Successfully"))
    else: set_status(mdlname, dict(state="Error: " + str(status)))
    print(Back.WHITE + Fore.BLACK + "%s's connection Closed: %s" %(mdlname, status_code(status)))
    return status
コード例 #23
0
ファイル: machine.py プロジェクト: zeyanchen/PYQUM
def awgsettingschannel():
    global awgsess, seqhandl
    print("seq handle in set-channel is %s"%seqhandl)
    message = [] 
    channel = request.args.get('channel')
    stat = AWG.arb_sequence_handle(awgsess, RepCap=channel, action=["Set", seqhandl])
    message += ['Sequence embeded: %s <%s>' %(stat[1], status_code(stat[0]))]
    outputch = request.args.get('outputch')
    stat = AWG.output_enabled(awgsess, RepCap=channel, action=["Set", int(outputch)])
    message += ['output channel %s: %s <%s>' %(channel, output_code(stat[1]), status_code(stat[0]))]
    oupfiltr = request.args.get('oupfiltr')
    stat = AWG.output_filter_enabled(awgsess, RepCap=channel, action=["Set", int(oupfiltr)])
    message += ['output filter channel %s: %s <%s>' %(channel, output_code(stat[1]), status_code(stat[0]))]

    # temporary:
    AWG.output_filter_bandwidth(awgsess, RepCap=channel, action=["Set", 0])
    AWG.output_config(awgsess, RepCap=channel, action=["Set", 0])
    AWG.arb_gain(awgsess, RepCap=channel, action=["Set", 0.25])
    AWG.output_impedance(awgsess, RepCap=channel, action=["Set", 50])
    AWG.operation_mode(awgsess, RepCap=channel, action=["Set", 0])
    AWG.trigger_source_adv(awgsess, RepCap=channel, action=["Set", 0])
    AWG.burst_count(awgsess, RepCap=channel, action=["Set", 1000001])

    return jsonify(message=message)
コード例 #24
0
ファイル: machine.py プロジェクト: Bocheng662533/PYQUM
def vsaabout():
    global vsasess
    message = []
    status = VSA.model(vsasess)  # model
    message += ['Model: %s (%s)' % (status[1], status_code(status[0]))]
    status = VSA.resource_descriptor(vsasess)  # resource descriptor
    message += [
        'Resource Descriptor: %s (%s)' % (status[1], status_code(status[0]))
    ]
    status = VSA.acquisition_time(vsasess)  # acquisition time
    message += [
        'Acquisition Time: %s (%s)' % (status[1], status_code(status[0]))
    ]
    status = VSA.trigger_source(vsasess)
    message += [
        'Trigger Source: %s (%s)' % (status[1], status_code(status[0]))
    ]
    status = VSA.trigger_delay(vsasess)
    message += ['Trigger Delay: %s (%s)' % (status[1], status_code(status[0]))]
    status = VSA.external_trigger_level(vsasess)
    message += [
        'External Trigger Level: %s (%s)' % (status[1], status_code(status[0]))
    ]
    status = VSA.external_trigger_slope(vsasess)
    message += [
        'External Trigger Slope: %s (%s)' % (status[1], status_code(status[0]))
    ]
    status = VSA.trigger_timeout(vsasess)
    message += [
        'Trigger Timeout: %s (%s)' % (status[1], status_code(status[0]))
    ]
    status = VSA.frequency(vsasess)
    message += ['LO Frequency: %s (%s)' % (status[1], status_code(status[0]))]
    status = VSA.power(vsasess)
    message += ['LO Power: %s (%s)' % (status[1], status_code(status[0]))]
    return jsonify(message=message)
コード例 #25
0
ファイル: AWG.py プロジェクト: RuRu110307/PYQUM
def CreateArbSequence(session, sequence, counts):
    '''[Create Arbitrary Sequence]
        sequence = < waveform (handle.value from "CreateArbWaveform") >
        counts = loop# (>0)
    '''
    AGM = dll.AgM933x_CreateArbSequence
    AGM.restype = c_int
    handle = c_long()
    Size = len(sequence)
    wfmhandles = (c_long * Size)(*sequence)
    loopcounts = (c_long * Size)(*counts)
    status = AGM(c_long(session), c_long(Size), wfmhandles, loopcounts,
                 byref(handle))
    if eval(debugger):
        print("Sequence's size: %s" % Size)
        print("Sequence: %s" % sequence)
        print("Sequence's counts: %s" % counts)
        print(Back.YELLOW + Fore.MAGENTA + "%s: %s (%s)" %
              (stack()[0][3], handle.value, status_code(status)))
    return status, handle.value
コード例 #26
0
ファイル: AWG.py プロジェクト: RuRu110307/PYQUM
def CreateArbWaveform(session, Data):
    '''[Create Arbitrary Waveform]
        *Data: 
            minimum: 1000 points
            maximum: 15000 points
            minimum per change: 200 for constant, 120 for linear?
            Amplitude between -1 and 1
        *2 Channel length must match to avoid truncation to the smaller length?
        *Error usually occur when the points is too few!
    '''
    AGM = dll.AgM933x_CreateArbWaveform
    AGM.restype = c_int
    handle = c_long()
    Size = len(Data)
    carray = (c_double * Size)(*Data)
    status = AGM(c_long(session), c_int(Size), carray, byref(handle))
    if eval(debugger):
        # print("Data: %s" %Data)
        print(Back.YELLOW + Fore.MAGENTA + "%s: %s (%s)" %
              (stack()[0][3], handle.value, status_code(status)))
    return status, handle.value
コード例 #27
0
def CreateArbWaveform(session, Data):
    '''[Create Arbitrary Waveform]
        *Data: 
            => minimum: 1000 points
            => maximum: 7.3M points (~8MS per channel) -> ~5.8ms playtime max
            => number of points must be multiples of 8
            => Amplitude between -1 and 1
            => The length of both channels must match up
        *Error usually occur when the points is too few!
    '''
    AGM = dll.AgM933x_CreateArbWaveform
    AGM.restype = c_int
    handle = c_long()
    Size = len(Data)
    carray = (c_double * Size)(*Data)
    status = AGM(c_long(session), c_int(Size), carray, byref(handle))
    if eval(debugger):
        # print("Data: %s" %Data)
        print(Back.YELLOW + Fore.MAGENTA + "%s: %s (%s)" %
              (stack()[0][3], handle.value, status_code(status)))
    return status, handle.value
コード例 #28
0
ファイル: AWG.py プロジェクト: RuRu110307/PYQUM
    def wrapper(*a, **b):

        session, Type, RepCap, AttrID, buffsize, action = Name(*a, **b)
        RepCap = bytes(RepCap, "ascii")

        AGM = getattr(dll, 'AgM933x_' + action[0] + 'AttributeVi' + Type)
        AGM.restype = c_int  # return status (error)

        if action[0] == "Get":
            if Type == 'String':
                action[1] = (
                    c_char *
                    888)()  # char array: answer value format (use byref)
                status = AGM(c_long(session), c_char_p(RepCap), c_int(AttrID),
                             c_long(buffsize), byref(action[1]))
                ans = [x.decode("ascii") for x in action[1]
                       ]  # decoding binary # if x is not b'\x00'
                while '\x00' in ans:
                    ans.remove('\x00')
                ans = "".join(ans)  # join char array into string
            elif Type == 'Int32':
                action[1] = c_long()
                status = AGM(c_long(session), c_char_p(RepCap), c_int(AttrID),
                             byref(action[1]))
                ans = action[1].value
            elif Type == 'Real64':
                action[1] = c_double()
                status = AGM(c_long(session), c_char_p(RepCap), c_int(AttrID),
                             byref(action[1]))
                ans = action[1].value
            elif Type == 'Boolean':
                action[1] = c_bool()
                status = AGM(c_long(session), c_char_p(RepCap), c_int(AttrID),
                             byref(action[1]))
                ans = action[1].value

        elif action[0] == "Set":
            if Type == 'String':
                ans = action[1]
                action[1] = bytes(action[1], 'ascii')
                status = AGM(c_long(session), c_char_p(RepCap), c_int(AttrID),
                             c_char_p(action[1]))
            elif Type == 'Int32':
                ans = action[1]
                status = AGM(c_long(session), c_char_p(RepCap), c_int(AttrID),
                             c_long(action[1]))
            elif Type == 'Real64':
                ans = action[1]
                status = AGM(c_long(session), c_char_p(RepCap), c_int(AttrID),
                             c_double(action[1]))
            elif Type == 'Boolean':
                ans = action[1]
                status = AGM(c_long(session), c_char_p(RepCap), c_int(AttrID),
                             c_bool(action[1]))

        # Reformatting Answer if RepCap has something:
        RepCap = RepCap.decode('ascii')
        if RepCap != "":
            hashtag = " #Channel %s" % (RepCap)
        else:
            hashtag = ""

        # Logging Answer:
        if action[0] == "Get":  # No logging for "Set"
            if status == 0:
                set_status(mdlname,
                           {Name.__name__ + hashtag: ans
                            })  #logging the name and value of the attribute
            else:
                set_status(mdlname,
                           {Name.__name__ + hashtag: "Error: " + str(status)})

        # Debugging
        if eval(debugger):
            if action[0] == "Get":
                print(Fore.YELLOW + "%s %s's %s: %s, %s" %
                      (action[0], mdlname, Name.__name__ + hashtag, ans,
                       status_code(status)))
            if action[0] == "Set":
                print(Back.YELLOW + Fore.MAGENTA + "%s %s's %s: %s, %s" %
                      (action[0], mdlname, Name.__name__ + hashtag, ans,
                       status_code(status)))

        return status, ans
コード例 #29
0
ファイル: VSA.py プロジェクト: supergravity/PYQUM
def Get_Data(session, ComplexDataBufferSize):
    """[Extracting Complex Data]
    Gets the I/Q measurement results.
    ComplexData:
        Array to hold the measurement data. Allocated by the caller (for performance). 
        The array size should be >= 2 * Measurements.NumberOfSamples (2* since the array will hold interleaved complex data)
    """
    AGM = dll.AgM9392_GetData
    AGM.restype = c_int
    # ComplexData = (c_double*int(ComplexDataBufferSize))() # 64bit per point
    ComplexData = (c_float*int(ComplexDataBufferSize))() # 32bit per point
    ComplexDataActualSize = c_long()
    NumberCopied = c_long()
    status = AGM(c_long(session), c_long(ComplexDataBufferSize), byref(ComplexData), byref(ComplexDataActualSize), byref(NumberCopied))
    answer = {}
    answer["ComplexData"] = [x for x in ComplexData]
    answer["ComplexDataActualSize"], answer["NumberCopied"] = ComplexDataActualSize.value, NumberCopied.value
    if status != 0:
        print("Get_Data Error: " + str(status)) # Streaming somehow will crash with saving data at some point so we'll just make do with print only
    if eval(debugger):
        print(Fore.LIGHTWHITE_EX + "%s out of %s actual %s's Data extracted & copied: %s" % (NumberCopied.value, ComplexDataActualSize.value, mdlname, status_code(status)))
    return status, answer
コード例 #30
0
def SQE_Pulse(user,
              tag="",
              corder={},
              comment='',
              dayindex='',
              taskentry=0,
              resumepoint=0,
              instr=['YOKO', 'PSGV', 'PSGA', 'AWG', 'VSA'],
              testeach=False):
    '''Time-domain Square-wave measurement:
    C-Structure: ['Flux-Bias', 
                    'Average', 'Pulse-Period', 'ADC-delay', 
                    'LO-Frequency', 'LO-Power', 'RO-Frequency', 'RO-Power', 'RO-ifLevel', 'RO-Pulse-Delay', 'RO-Pulse-Width', 
                    'XY-Frequency', 'XY-Power', 'XY-ifLevel', 'XY-Pulse-Delay', 'XY-Pulse-Width', 
                    'Sampling-Time'] (IQ-Bandwidth (250MHz or its HALFlings) + Acquisition-Time (dt must be multiples of 2ns))
    '''
    # Loading sample:
    sample = get_status("MSSN")[session['user_name']]['sample']
    # sample = get_status("MSSN")['abc']['sample'] # by-pass HTTP-request before interface is ready

    # pushing pre-measurement parameters to settings:
    yield user, sample, tag, instr, corder, comment, dayindex, taskentry, testeach

    # ***USER_DEFINED*** Controlling-PARAMETER(s) ======================================================================================
    structure = corder['C-Structure']
    fluxbias = waveform(corder['Flux-Bias'])
    averaging = waveform(corder['Average'])
    pperiod = waveform(corder['Pulse-Period'])
    adcdelay = waveform(corder['ADC-delay'])
    lofreq = waveform(corder['LO-Frequency'])
    lopowa = waveform(corder['LO-Power'])
    rofreq = waveform(corder['RO-Frequency'])
    ropowa = waveform(corder['RO-Power'])
    roiflevel = waveform(corder['RO-ifLevel'])
    ropdelay = waveform(corder['RO-Pulse-Delay'])
    ropwidth = waveform(corder['RO-Pulse-Width'])
    xyfreq = waveform(corder['XY-Frequency'])
    xypowa = waveform(corder['XY-Power'])
    xyiflevel = waveform(corder['XY-ifLevel'])
    xypdelay = waveform(corder['XY-Pulse-Delay'])
    xypwidth = waveform(corder['XY-Pulse-Width'])
    samptime = waveform(corder['Sampling-Time'])

    # Total data points:
    datasize = int(
        prod([waveform(corder[param]).count for param in structure],
             dtype='uint64')) * 2  #data density of 2 due to IQ
    print("data size: %s" % datasize)

    # Pre-loop settings:
    # Optionals:
    # YOKO:
    if "opt" not in fluxbias.data:  # check if it is in optional-state / serious-state
        yokog = YOKO.Initiate(current=True)  # pending option
        YOKO.output(yokog, 1)

    # PSGV:
    if "opt" not in xyfreq.data:  # check if it is in optional-state / serious-state
        sogo = PSG0.Initiate()  # pending option
        PSG0.rfoutput(sogo, action=['Set', 1])

    # Basics:
    # PSGA for LO:
    saga = PSG1.Initiate()  # pending option
    PSG1.rfoutput(saga, action=['Set', 1])

    # AWG for Control:
    awgsess = AWG.InitWithOptions()
    AWG.Abort_Gen(awgsess)
    AWG.ref_clock_source(awgsess,
                         action=['Set',
                                 int(1)])  # External 10MHz clock-reference
    AWG.predistortion_enabled(awgsess, action=['Set', True])
    AWG.output_mode_adv(awgsess, action=['Set',
                                         int(2)])  # Sequence output mode
    AWG.arb_sample_rate(awgsess,
                        action=['Set',
                                float(1250000000)])  # maximum sampling rate
    AWG.active_marker(awgsess, action=['Set', '1'])  # master
    AWG.marker_delay(awgsess, action=['Set', float(0)])
    AWG.marker_pulse_width(awgsess, action=['Set', float(1e-7)])
    AWG.marker_source(awgsess, action=['Set', int(7)])
    # PRESET Output:
    for ch in range(2):
        channel = str(ch + 1)
        AWG.output_config(awgsess, RepCap=channel, action=["Set",
                                                           0])  # Single-ended
        AWG.output_filter_bandwidth(awgsess, RepCap=channel, action=["Set", 0])
        AWG.arb_gain(awgsess, RepCap=channel, action=["Set", 0.5])
        AWG.output_impedance(awgsess, RepCap=channel, action=["Set", 50])
    # output settings:
    for ch in range(2):
        channel = str(ch + 1)
        AWG.output_enabled(awgsess, RepCap=channel, action=["Set",
                                                            int(1)])  # ON
        AWG.output_filter_enabled(awgsess,
                                  RepCap=channel,
                                  action=["Set", True])
        AWG.output_config(awgsess, RepCap=channel,
                          action=["Set", int(2)])  # Amplified 1:2
        AWG.output_filter_bandwidth(awgsess, RepCap=channel, action=["Set", 0])
        AWG.arb_gain(awgsess, RepCap=channel, action=["Set", 0.5])
        AWG.output_impedance(awgsess, RepCap=channel, action=["Set", 50])

    # VSA for Readout
    vsasess = VSA.InitWithOptions()

    # Buffer-size for lowest-bound data-collecting instrument:
    buffersize_1 = samptime.count * 2  #data density of 2 due to IQ
    print("Buffer-size: %s" % buffersize_1)

    # User-defined Measurement-FLOW ==============================================================================================
    if testeach:  # measure-time contribution from each measure-loop
        loopcount, loop_dur = [], []
        stage, prev = clocker(0)  # Marking starting point of time

    # Registerring parameter(s)-structure
    cstructure = [waveform(corder[param]).count for param in structure
                  ][:-1]  # The last one will become a buffer
    print('cstructure: %s' % cstructure)

    measure_loop_1 = range(
        resumepoint // buffersize_1, datasize //
        buffersize_1)  # saving chunck by chunck improves speed a lot!
    while True:
        for i in measure_loop_1:
            print(Back.BLUE + Fore.WHITE + 'measure %s/%s' %
                  (i, datasize // buffersize_1))
            # determining the index-locations for each parameters, i.e. the address at any instance
            caddress = cdatasearch(i, cstructure)

            # setting each c-order (From High to Low level of execution):
            # ***************************************************************
            for j in range(
                    len(cstructure) -
                    1):  # the last one will be run for every i (common sense!)
                if (
                        not i % prod(cstructure[j + 1::])
                ) or i == resumepoint // buffersize_1:  # virtual for-loop using exact-multiples condition
                    # print("entering %s-stage" %j)
                    # Optionals:
                    # YOKO
                    if structure[j] == 'Flux-Bias':
                        if "opt" not in fluxbias.data:  # check if it is in optional-state
                            if testeach:  # adding instrument transition-time between set-values:
                                loopcount += [fluxbias.count]
                                if fluxbias.count > 1:
                                    loop_dur += [
                                        abs(fluxbias.data[0] -
                                            fluxbias.data[1]) / 0.2 + 35 * 1e-3
                                    ]  # manually calculating time without really setting parameter on the instrument
                                else:
                                    loop_dur += [0]
                                stage, prev = clocker(stage,
                                                      prev)  # Marking time
                            else:
                                YOKO.sweep(
                                    yokog,
                                    str(fluxbias.data[caddress[structure.index(
                                        'Flux-Bias')]]),
                                    pulsewidth=77 * 1e-3,
                                    sweeprate=0.0007
                                )  # A-mode: sweeprate=0.0007 A/s ; V-mode: sweeprate=0.07 V/s

                    # PSG
                    if structure[j] == 'XY-Frequency':
                        if "opt" not in xyfreq.data:  # check if it is in optional-state
                            PSG0.frequency(
                                sogo,
                                action=[
                                    'Set',
                                    str(xyfreq.data[caddress[structure.index(
                                        'XY-Frequency')]]) + "GHz"
                                ])
                    if structure[j] == 'XY-Power':
                        if "opt" not in xypowa.data:  # check if it is in optional-state
                            PSG0.power(sogo,
                                       action=[
                                           'Set',
                                           str(xypowa.data[caddress[
                                               structure.index('XY-Power')]]) +
                                           "dBm"
                                       ])
                    if structure[j] == 'RO-Frequency':
                        if "opt" not in rofreq.data:  # check if it is in optional-state
                            PSG1.frequency(
                                saga,
                                action=[
                                    'Set',
                                    str(rofreq.data[caddress[structure.index(
                                        'RO-Frequency')]]) + "GHz"
                                ])
                    if structure[j] == 'RO-Power':
                        if "opt" not in ropowa.data:  # check if it is in optional-state
                            PSG1.power(saga,
                                       action=[
                                           'Set',
                                           str(ropowa.data[caddress[
                                               structure.index('RO-Power')]]) +
                                           "dBm"
                                       ])

            # AWG (Every-loop)
            if "opt" not in pperiod.data:  # check if it is in optional-state
                AWG.Clear_ArbMemory(awgsess)
                WAVE = []

                # construct waveform:
                ifperiod = pperiod.data[caddress[structure.index(
                    'Pulse-Period')]]
                ifscale = float(
                    xyiflevel.data[caddress[structure.index('XY-ifLevel')]]
                ), float(
                    roiflevel.data[caddress[structure.index('RO-ifLevel')]])

                if "lockxypwd" in str(ropdelay.data[0]):
                    if '+' in str(ropdelay.data[0]):
                        rooffset = float(ropdelay.data[0].split('+')[1])
                    else:
                        rooffset = 0  # default value
                    ifdelay = float(xypdelay.data[caddress[structure.index(
                        'XY-Pulse-Delay')]]), float(xypwidth.data[caddress[
                            structure.index('XY-Pulse-Width')]]) + rooffset
                    print("RO-Pulse Delays behind XY-Pulse for %sns" %
                          (ifdelay[1] - ifdelay[0]))
                else:
                    ifdelay = float(xypdelay.data[caddress[structure.index(
                        'XY-Pulse-Delay')]]), float(ropdelay.data[caddress[
                            structure.index('RO-Pulse-Delay')]])

                ifontime = float(
                    xypwidth.data[caddress[structure.index('XY-Pulse-Width')]]
                ), float(
                    ropwidth.data[caddress[structure.index('RO-Pulse-Width')]])
                for ch in range(2):
                    channel = str(ch + 1)
                    wavefom = squarewave(ifperiod, ifontime[ch], ifdelay[ch],
                                         ifscale[ch])  # in ns
                    stat, wave = AWG.CreateArbWaveform(awgsess, wavefom)
                    print('Waveform channel %s: %s <%s>' %
                          (channel, wave, status_code(stat)))
                    WAVE.append(wave)
                # Building Sequences:
                for ch in range(2):
                    channel = str(ch + 1)
                    status, seqhandl = AWG.CreateArbSequence(
                        awgsess, [WAVE[ch]], [1]
                    )  # loop# canbe >1 if longer sequence is needed in the future!
                    # print('Sequence channel %s: %s <%s>' %(channel, seqhandl, status_code(status)))
                    # Channel Assignment:
                    stat = AWG.arb_sequence_handle(awgsess,
                                                   RepCap=channel,
                                                   action=["Set", seqhandl])
                    # print('Sequence channel %s embeded: %s <%s>' %(channel, stat[1], status_code(stat[0])))
                # Trigger Settings:
                for ch in range(2):
                    channel = str(ch + 1)
                    AWG.operation_mode(awgsess,
                                       RepCap=channel,
                                       action=["Set", 0])
                    AWG.trigger_source_adv(awgsess,
                                           RepCap=channel,
                                           action=["Set", 0])
                AWG.Init_Gen(awgsess)
                AWG.Send_Pulse(awgsess, 1)

            # Basic / Buffer:
            # VSA (Every-loop)
            VSA.acquisition_time(vsasess,
                                 action=['Set',
                                         float(samptime.count * 2e-9)
                                         ])  # minimum time resolution
            VSA.preselector_enabled(vsasess, action=[
                'Set', False
            ])  # disable preselector to allow the highest bandwidth of 250MHz

            if "lockro" in str(lofreq.data[0]):
                if '+' in str(lofreq.data[0]):
                    lof_offset = float(lofreq.data[0].split('+')[1])
                elif '-' in str(lofreq.data[0]):
                    lof_offset = -float(lofreq.data[0].split('-')[1])
                else:
                    lof_offset = 0  # default value
                VSA.frequency(vsasess,
                              action=[
                                  'Set',
                                  float(rofreq.data[caddress[structure.index(
                                      'RO-Frequency')]]) * 1e9 + lof_offset
                              ])  # freq offset / correction in Hz
                print("Locking on RO at %sGHz" %
                      (VSA.frequency(vsasess)[1] / 1e9))
            else:
                VSA.frequency(vsasess,
                              action=[
                                  'Set',
                                  float(lofreq.data[caddress[structure.index(
                                      'LO-Frequency')]]) * 1e9
                              ])

            VSA.power(
                vsasess,
                action=[
                    'Set',
                    float(lopowa.data[caddress[structure.index('LO-Power')]])
                ])
            VSA.bandwidth(
                vsasess, action=['Set', 250e6]
            )  # maximum LO bandwidth of 250MHz (500MHz Sampling-rate gives 2ns of time resolution)
            VSA.trigger_source(vsasess,
                               action=['Set',
                                       int(1)])  # External Trigger (slave)

            # Delay for Readout
            if "lockxypwd" in str(ropdelay.data[0]):
                # trigger-delay sync with xy-pulse-width for Rabi measurement:
                VSA.trigger_delay(vsasess, action=['Set', float(adcdelay.data[caddress[structure.index('ADC-delay')]]) + \
                    float(xypwidth.data[caddress[structure.index('XY-Pulse-Width')]])*1e-9 + rooffset*1e-9])
                print("ACQ delays with XY-Pulse for %sns" %
                      int(VSA.trigger_delay(vsasess)[1] / 1e-9))
            elif "lockropdelay" in str(adcdelay.data[0]):
                # trigger-delay sync with ro-pulse-delay for T1 measurement:
                VSA.trigger_delay(
                    vsasess,
                    action=[
                        'Set',
                        float(ropdelay.data[caddress[structure.index(
                            'RO-Pulse-Delay')]]) * 1e-9
                    ])
                print("ACQ delays with RO-Pulse for %sns" %
                      int(VSA.trigger_delay(vsasess)[1] / 1e-9))
            else:
                VSA.trigger_delay(vsasess,
                                  action=[
                                      'Set',
                                      float(adcdelay.data[caddress[
                                          structure.index('ADC-delay')]])
                                  ])

            VSA.external_trigger_level(vsasess, action=['Set', float(0.3)])
            VSA.external_trigger_slope(vsasess,
                                       action=['Set',
                                               int(1)])  # Positive slope
            VSA.trigger_timeout(vsasess, action=['Set',
                                                 int(1000)])  # 1s of timeout
            stat = VSA.Init_Measure(vsasess)  # Initiate Measurement

            # Start Quantum machine:
            # Start Averaging Loop:
            avenum = int(averaging.data[caddress[structure.index('Average')]])
            vsasn = VSA.samples_number(vsasess)[1]
            iqdata = zeros((avenum, 2 * vsasn))
            for ave in range(avenum):
                VSA.Arm_Measure(vsasess)
                gd = VSA.Get_Data(vsasess, 2 * vsasn)
                iqdata[ave, :] = array(gd[1]['ComplexData'])
            iqdata = mean(iqdata, axis=0)
            print("Operation Complete")
            print(Fore.YELLOW + "\rProgress: %.3f%%" %
                  ((i + 1) / datasize * buffersize_1 * 100),
                  end='\r',
                  flush=True)

            # test for the last loop if there is
            if testeach:  # test each measure-loop:
                loopcount += [len(measure_loop_1)]
                loop_dur += [time() - prev]
                stage, prev = clocker(stage, prev)  # Marking time
                VSA.close(vsasess)
                if "opt" not in pperiod.data:  # check if it is in optional-state
                    AWG.close(awgsess)
                if "opt" not in xyfreq.data:  # check if it is in optional-state
                    PSG0.close(sogo, False)
                if "opt" not in rofreq.data:  # check if it is in optional-state
                    PSG1.close(saga, False)
                if "opt" not in fluxbias.data:  # check if it is in optional-state
                    YOKO.close(yokog, False)
                yield loopcount, loop_dur

            else:
                if get_status("SQE_Pulse")['pause']:
                    break
                else:
                    yield list(iqdata)

        if not get_status("SQE_Pulse")['repeat']:
            set_status("SQE_Pulse", dict(pause=True))
            VSA.close(vsasess)
            if "opt" not in pperiod.data:  # check if it is in optional-state
                AWG.Abort_Gen(awgsess)
                AWG.close(awgsess)
            if "opt" not in xyfreq.data:  # check if it is in optional-state
                PSG0.rfoutput(sogo, action=['Set', 0])
                PSG0.close(sogo, False)
            if "opt" not in rofreq.data:  # check if it is in optional-state
                PSG1.rfoutput(saga, action=['Set', 0])
                PSG1.close(saga, False)
            if "opt" not in fluxbias.data:  # check if it is in optional-state
                YOKO.output(yokog, 0)
                YOKO.close(yokog, False)
            return