def keithOutMethod(val):

    keith = Keithley2400(f)

    if val == 'ON':
        keith.outputOn()

    else:
        keith.outputOff()
def quitMethod():

    amp = lockinAmp(func, sense, signal, freq)
    amp.dacOutput(0, 1)
    amp.dacOutput(0, 2)
    amp.dacOutput(0, 3)
    amp.dacOutput(0, 4)

    keith=Keithley2400(f)
    keith.setCurrent(0)
    keith.outputOff()

    listbox_l.insert('end', "All fields set to zero.")
    listbox_l.see(END)
    
    global root

    root.quit()
    def event():

        current_start=float(_current)
        current_end=float(_current)*(-1)
        current_step=float(_step)

        keith=Keithley2400(f) #Initiate K2400
    
        while current_start>=current_end:

            ax.clear()
            ax.grid(True)
            ax.set_title("Realtime Hall voltage vs H Plot")
            ax.set_xlabel("Applied Field (Oe)")
            ax.set_ylabel("Lock-In X (mV)")
            
            #Prepare data entries
            global values_x, values_y, result

            values_y=[]
            values_x=[]
            result=[]
            
            #Setup K2400 for current output and resistance measurement
            keith.setCurrent(current_start)
            keith.outputOn()

            index=1
            data=[]

            while index<=5: #Average of five measurements
                data=data+keith.measureOnce()
                index+=1
        
            print("Measured current: %f mA" %(1000*data[2]))
            print("Measured voltage: %f V" %data[1])
            print("Measured resistance: %f Ohm" %(data[1]/data[2]))

            #Setup lock-in for dac output
            t=0
            a=0.0

            amp = lockinAmp(func, sense, signal, freq)
            step = (double(_output)/i)/n
    
            while t < n :

                amp.dacOutput(a, DAC)
                tmp=1000*double(amp.readX(average)) #in units of mV
                result.append(tmp)
                values_y.append(tmp)
                values_x.append(a*i)
                ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                canvas.draw()
                listbox_l.insert('end', tmp)
                t+=1
                a+=step
                listbox_l.see(END)

            while t < 3*n :

                amp.dacOutput(a, DAC)
                tmp=1000*double(amp.readX(average))
                result.append(tmp)
                values_y.append(tmp)
                values_x.append(a*i)
                ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                canvas.draw()
                listbox_l.insert('end', tmp)
                t+=1
                a-=step
                listbox_l.see(END)

            while t <= 4*n :

                amp.dacOutput(a, DAC)
                tmp=1000*double(amp.readX(average))
                result.append(tmp)
                values_y.append(tmp)
                values_x.append(a*i)
                ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                canvas.draw()
                listbox_l.insert('end', tmp)
                t+=1
                a+=step
                listbox_l.see(END)

            #scat=ax.scatter(values_x, values_y, s=50, alpha=0.5)
            #canvas.draw()

            keith.outputOff()
            current_start=current_start-current_step
            time.sleep(1) #Sleep between each scan

        
        listbox_l.insert('end',"Measurement finished")
        listbox_l.see(END)
    def event():

        Hx_start = float(_Hx)
        Hx_end = float(_Hx) * (-1)
        Hx_step = float(_dHx)

        keith = Keithley2400(f)  #Initiate K2400
        keith2000 = Keithley(f)  #Initiate K2000
        amp = lockinAmp(func, sense, signal, freq)  #Initiate Lock-in

        while Hx_start >= Hx_end:

            amp.dacOutput((Hx_start / ix), DACx)

            current_max = float(_current)
            current_min = float(_current) * (-1)
            current_step = float(_step)

            #while current_start>=current_end:

            ax.clear()
            ax.grid(True)
            ax.set_title("Realtime Resistance vs I Plot")
            ax.set_xlabel("Applied Current (mA)")
            ax.set_ylabel("Hall Resistance (Ohm)")

            listbox_l.insert('end',
                             "Now measuring with Hx = %f (Oe)" % Hx_start)
            listbox_l.see(END)

            #Prepare data entries
            global values_x, values_y, result

            values_y = []
            values_x = []
            result = []

            #Setup K2400 for current output and resistance measurement
            keith.fourWireOff()
            keith.setCurrent(0.1)  #Use 0.1mA to measure DC resistance
            keith.outputOn()

            index = 1
            data = []

            while index <= 5:  #Average of five measurements
                data = data + keith.measureOnce()
                index += 1

            print("Measured current: %f mA" % (1000 * data[2]))
            print("Measured voltage: %f V" % data[1])
            print("Measured resistance: %f Ohm" % (data[1] / data[2]))

            keith.outputOff()

            #Setup Keithley for Idc sweep
            current = 0  #starting current amplitude
            current_sense = 0.01  #sensing current amplitude 0.1mA

            #Pulse train parameters
            write_pulse_width = 0.05
            read_pulse_width = 0.05
            write_read_pause = 0.05
            period = 0.05

            keith.outputOn()

            while current < current_max:

                #keith.outputOn()
                keith.setCurrent(current)  # Set switching current
                time.sleep(write_pulse_width)
                keith.setCurrent(0)  # Reduce current amplitude to zero
                #keith.outputOff()

                time.sleep(write_read_pause)

                #keith.outputOn()
                keith.setCurrent(current_sense)  # Set sensing current to 0.1mA
                time.sleep(read_pulse_width)
                data = keith2000.measureOnce()
                keith.setCurrent(0)  # Reduce current amplitude to zero
                #keith.outputOff()

                tmp = double(1000 * data[1] /
                             current_sense)  # Voltage from K2000 / 0.1mA
                result.append(tmp)
                values_y.append(tmp)
                values_x.append(current)
                #ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                ax.plot(values_x,
                        values_y,
                        'b-o',
                        ms=dot_size,
                        mew=dot_edge,
                        alpha=0.5)
                canvas.draw()
                listbox_l.insert('end', tmp)
                current += current_step
                listbox_l.see(END)

                time.sleep(period)

            while current > current_min:

                #keith.outputOn()
                keith.setCurrent(current)  # Set switching current
                time.sleep(write_pulse_width)
                keith.setCurrent(0)  # Reduce current amplitude to zero
                #keith.outputOff()

                time.sleep(write_read_pause)

                #keith.outputOn()
                keith.setCurrent(current_sense)  # Set sensing current to 0.1mA
                time.sleep(read_pulse_width)
                data = keith2000.measureOnce()
                keith.setCurrent(0)  # Reduce current amplitude to zero
                #keith.outputOff()

                tmp = double(1000 * data[1] /
                             current_sense)  # Voltage from K2000 / 0.1mA
                result.append(tmp)
                values_y.append(tmp)
                values_x.append(current)
                #ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                ax.plot(values_x,
                        values_y,
                        'b-o',
                        ms=dot_size,
                        mew=dot_edge,
                        alpha=0.5)
                canvas.draw()
                listbox_l.insert('end', tmp)
                current -= current_step
                listbox_l.see(END)

                time.sleep(period)

            while current <= 0:

                #keith.outputOn()
                keith.setCurrent(current)  # Set switching current
                time.sleep(write_pulse_width)
                keith.setCurrent(0)  # Reduce current amplitude to zero
                #keith.outputOff()

                time.sleep(write_read_pause)

                #keith.outputOn()
                keith.setCurrent(current_sense)  # Set sensing current to 0.1mA
                time.sleep(read_pulse_width)
                data = keith2000.measureOnce()
                keith.setCurrent(0)  # Reduce current amplitude to zero
                #keith.outputOff()

                tmp = double(1000 * data[1] /
                             current_sense)  # Voltage from K2000 / 0.1mA
                result.append(tmp)
                values_y.append(tmp)
                values_x.append(current)
                #ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                ax.plot(values_x,
                        values_y,
                        'b-o',
                        ms=dot_size,
                        mew=dot_edge,
                        alpha=0.5)
                canvas.draw()
                listbox_l.insert('end', tmp)
                current += current_step
                listbox_l.see(END)

                time.sleep(period)

            #scat=ax.scatter(values_x, values_y, s=50, alpha=0.5)
            #canvas.draw()

            stamp = datetime.now().strftime('%Y-%m-%d-%H%M%S')
            listbox_l.insert('end', str(stamp))

            file = open(
                str(directory) + "/MR_STT_switching_" + str(Hx_start) + "Oe_" +
                str(stamp), "w")
            file.write("Applied in-plane field: " + str(Hx_start) + "(Oe)\n\n")
            file.write("Number" + " " + "Current(mA)" + " " +
                       "Resistance(Ohm)" + "\n")

            cnt = 1
            #output all data
            for a in range(len(values_y)):

                file.write(
                    str(cnt) + " " + str(values_x[a]) + " " +
                    str(values_y[a]) + "\n")
                cnt += 1

            file.closed

            listbox_l.insert('end', "The Measurement data is saved.")
            listbox_l.see(END)

            #keith.outputOff()

            time.sleep(1)  #Sleep between each scan

            Hx_start = Hx_start - Hx_step

        amp.dacOutput(0, DACx)
        amp.dacOutput(0, DAC)

        keith.fourWireOff()
        keith.outputOff()

        listbox_l.insert('end', "Measurement finished")
        listbox_l.see(END)
예제 #5
0
    def event():

        Hx_start=float(_Hx)
        Hx_end=float(_Hx)*(-1)
        Hx_step=float(_dHx)

        keith=Keithley2400(f) #Initiate K2400
        amp = lockinAmp(func, sense, signal, freq) #Initiate Lock-in

        while Hx_start>=Hx_end:

            amp.dacOutput((Hx_start/ix), DACx)

            current_start=float(_current)
            current_end=float(_current)*(-1)
            current_step=float(_step)
    
            while current_start>=current_end:

                ax.clear()
                ax.grid(True)
                ax.set_title("Realtime MOKE signal vs H Plot")
                ax.set_xlabel("Applied Field (Oe)")
                ax.set_ylabel("MOKE signal (R+G+B)")

                listbox_l.insert('end',"Now measuring with Hx = %f (Oe) and Idc = %f (mA) " %(Hx_start,current_start))
                listbox_l.see(END)
                
                #Prepare data entries
                global values_x, values_y, result

                values_y=[]
                values_x=[]
                result=[]
                
                #Setup K2400 for current output and resistance measurement
                keith.setCurrent(current_start)
                keith.outputOn()

                index=1
                data=[]

                while index<=5: #Average of five measurements
                    data=data+keith.measureOnce()
                    index+=1
            
                print("Measured current: %f mA" %(1000*data[2]))
                print("Measured voltage: %f V" %data[1])
                print("Measured resistance: %f Ohm" %(data[1]/data[2]))

                #Setup lock-in for dac (Hz field) output
                t=0
                a=0.0
                step = (double(_output)/i)/n
        
                while t < n :

                    amp.dacOutput(a, DAC)
                    tmp=imageMethod(x1,y1,x2,y2) #get image lumi
                    result.append(tmp)
                    values_y.append(tmp)
                    values_x.append(a*i)
                    ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                    canvas.draw()
                    listbox_l.insert('end', tmp)
                    t+=1
                    a+=step
                    listbox_l.see(END)

                while t < 3*n :

                    amp.dacOutput(a, DAC)
                    tmp=imageMethod(x1,y1,x2,y2) #get image lumi
                    result.append(tmp)
                    values_y.append(tmp)
                    values_x.append(a*i)
                    ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                    canvas.draw()
                    listbox_l.insert('end', tmp)
                    t+=1
                    a-=step
                    listbox_l.see(END)

                while t <= 4*n :

                    amp.dacOutput(a, DAC)
                    tmp=imageMethod(x1,y1,x2,y2) #get image lumi
                    result.append(tmp)
                    values_y.append(tmp)
                    values_x.append(a*i)
                    ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                    canvas.draw()
                    listbox_l.insert('end', tmp)
                    t+=1
                    a+=step
                    listbox_l.see(END)

                #scat=ax.scatter(values_x, values_y, s=50, alpha=0.5)
                #canvas.draw()

                file = open(str(directory)+"/sample_name_"+str(Hx_start)+"Oe_"+str(current_start)+"mA", "w")
                file.write("Applied in-plane field: "+str(Hx_start)+"(Oe)\n")
                file.write("Applied current: "+str(current_start)+"(mA)\n\n")
                file.write("Number"+" "+"Field(Oe)"+" "+"Voltage(mV)"+"\n")

                cnt=1
                #output all data 
                for a in range(len(values_y)):

                    file.write(str(cnt)+" "+str(values_x[a])+" "+str(values_y[a])+"\n")
                    cnt +=1

                file.closed

                listbox_l.insert('end', "The Measurement data is saved.")
                listbox_l.see(END)

                keith.outputOff()
                current_start=current_start-current_step

                time.sleep(1) #Sleep between each scan


            Hx_start=Hx_start-Hx_step

        amp.dacOutput(0, DACx)
        amp.dacOutput(0, DAC)
        listbox_l.insert('end',"Measurement finished")
        listbox_l.see(END)
def measureMethod(_inteval, _number, _output, _average, _signal, _frequency,
                  _current):

    global values_x, values_y, result

    values_y = []
    values_x = []
    result = []

    i = float(_inteval)
    n = int(_number)
    average = int(_average)
    signal = float(_signal)
    freq = int(_frequency)
    current = float(_current)

    #Setup Keithley2400 for current output and resistance measurement
    keith = Keithley2400(f)
    keith.setCurrent(current)
    keith.outputOn()

    index = 1
    data = []

    while index <= 5:  #Average of five measurements
        data = data + keith.measureOnce()
        index += 1

    print("Measured current: %f mA" % (1000 * data[2]))
    print("Measured voltage: %f V" % data[1])
    print("Measured resistance: %f Ohm" % (data[1] / data[2]))

    ax.clear()
    ax.grid(True)
    ax.set_title("Realtime Hall voltage vs H Plot")
    ax.set_xlabel("Applied Field (Oe)")
    ax.set_ylabel("Lock-In X (mV)")

    #ax.axis([0, i*n, -10, 10])

    def event():

        t = 0
        a = 0.0

        amp = lockinAmp(func, sense, signal, freq)
        step = (double(_output) / i) / n

        while t < n:

            amp.dacOutput(a, DAC)
            tmp = 1000 * double(amp.readX(average))  #in units of mV
            result.append(tmp)
            values_y.append(tmp)
            values_x.append(a * i)
            ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
            canvas.draw()
            listbox_l.insert('end', tmp)
            t += 1
            a += step
            listbox_l.see(END)

        while t < 3 * n:

            amp.dacOutput(a, DAC)
            tmp = 1000 * double(amp.readX(average))
            result.append(tmp)
            values_y.append(tmp)
            values_x.append(a * i)
            ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
            canvas.draw()
            listbox_l.insert('end', tmp)
            t += 1
            a -= step
            listbox_l.see(END)

        while t <= 4 * n:

            amp.dacOutput(a, DAC)
            tmp = 1000 * double(amp.readX(average))
            result.append(tmp)
            values_y.append(tmp)
            values_x.append(a * i)
            ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
            canvas.draw()
            listbox_l.insert('end', tmp)
            t += 1
            a += step
            listbox_l.see(END)

        #scat=ax.scatter(values_x, values_y, s=50, alpha=0.5)
        #canvas.draw()

        keith.outputOff()

        listbox_l.insert('end', "Measurement finished")
        listbox_l.see(END)

    th = threading.Thread(target=event)
    th.start()
예제 #7
0
    def event():

        keith = Keithley2400(f)  #Initiate K2400
        keith2000 = Keithley(f)  #Initiate K2000

        writetask = nidaqmx.Task()  #Initiate GMW write & read channels
        readtask = nidaqmx.Task()

        Va_applied = writetask.ao_channels.add_ao_voltage_chan(
            "VectorMagnet/ao0")
        Vb_applied = writetask.ao_channels.add_ao_voltage_chan(
            "VectorMagnet/ao1")
        Vc_applied = writetask.ao_channels.add_ao_voltage_chan(
            "VectorMagnet/ao2")

        Field_X = readtask.ai_channels.add_ai_voltage_chan("VectorMagnet/ai0")
        Field_Y = readtask.ai_channels.add_ai_voltage_chan("VectorMagnet/ai1")
        Field_Z = readtask.ai_channels.add_ai_voltage_chan("VectorMagnet/ai2")
        #readtask.read() will give [V_ai0, V_ai1, V_ai2]

        Hin_start = float(_Hin)
        Hin_end = float(_Hin) * (-1)
        Hin_step = float(_dHin)  # step value of Hx field

        if Hin_start < 0:
            Hin_mod = -1  #allows for loop to run from negative to positive Hx values
            Hin_start = Hin_end  #initialize Hx start to be a positive number
            Hin_end = Hin_start * (-1)  #makes Hx end a negative number
        else:
            Hin_mod = 1

        while Hin_start >= Hin_end:

            current_start = float(_current)
            current_end = float(_current) * (-1)
            current_step = float(_step)

            while current_start >= current_end:
                ax.clear()
                ax.grid(True)
                ax.set_title("Realtime Resistance vs Theta Plot")
                #ax.set_xlabel("Applied Field Angle (Theta)")
                #ax.set_ylabel("Hall Resistance (Ohm)")

                listbox_l.insert(
                    'end',
                    "Now measuring with Idc = %f (mA) " % (current_start))
                listbox_l.see(END)

                #Prepare data entries
                global values_x, values_y, result, canvas

                values_y = []
                values_x = []
                result = []

                #Setup K2400 for current output and resistance measurement
                keith.fourWireOff()
                keith.setCurrent(current_start)
                keith.outputOn()

                index = 1
                data = []
                m_time = []
                m_xfield = []
                m_yfield = []
                m_zfield = []
                m_fieldang = []

                # for plot data (angle unit: rad)
                rad_values_x = []
                rad_m_fieldang = []

                while index <= 5:  #Average of five measurements
                    data = data + keith.measureOnce()
                    index += 1

                listbox_l.insert('end',
                                 "Measured current: %f mA" % (1000 * data[2]))
                listbox_l.insert('end', "Measured voltage: %f V" % data[1])
                listbox_l.insert(
                    'end', "Measured resistance: %f Ohm" % (data[1] / data[2]))
                listbox_l.see(END)

                resistance = data[1] / data[2]

                writetask.write([0, 0, 0])
                #initial application of field to avoid outliers
                j = Hin_start / i

                for g in range(0, len(angmagV)):
                    writetask.write([x * j for x in angmagV[g]])
                    start = time.time()
                    data = keith2000.measureMulti(average)
                    fdata = [
                        0, 0, 0
                    ]  # origin measured field is in unit V, ifield is conversion value with unit Oe/V
                    findex = 1

                    while findex <= 5:  #Average of five measurements
                        fdata = [
                            fdata[i] + readtask.read()[i] for i in range(0, 3)
                        ]
                        findex += 1

                    fielddata = [x * ifield / 5 for x in fdata
                                 ]  #while loop is for averaging 5 measurements
                    fieldang = np.arctan(
                        fielddata[ychan] / fielddata[xchan]) / np.pi * 180
                    # store data in lists for later writecsv process
                    m_zfield.append(fielddata[zchan])
                    m_xfield.append(fielddata[xchan])
                    m_yfield.append(fielddata[ychan])
                    m_fieldang.append(fieldang)
                    rad_m_fieldang.append(fieldang / 180 * np.pi)

                    tmp = double(
                        1000 * data / current_start
                    )  # Voltage from K2000 / Current from K2400 (Hall resistance)
                    result.append(tmp)
                    values_y.append(tmp)
                    values_x.append(ang[g])
                    rad_values_x.append(ang[g] / 180 * np.pi)
                    #ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                    mid = time.time()

                    ax.plot(rad_values_x,
                            values_y,
                            'b-o',
                            ms=dot_size,
                            mew=dot_edge,
                            alpha=0.5)
                    #ax.plot(rad_m_fieldang, values_y,'r-o', ms=dot_size, mew=dot_edge, alpha=0.5)
                    canvas.draw()
                    listbox_l.insert(
                        'end', "Hall Resistance:" + str(round(tmp, 4)) +
                        " Applied Field Angle:" + str(round(ang[g], 4)) +
                        " Measured Field Angle:" + str(round(fieldang, 4)))
                    listbox_l.see(END)
                    fin = time.time()
                    m_time.append(fin - start)
                    #print('Total Time: ', (fin-start), '\n Plot time: ', (fin-mid))
                    print("Applied Field Angle: " + str(round(ang[g], 4)))
                '''
                while t < 2*n : #------------------------------------------------------------------------------------------------------- 時間設定應該會出問題-

                    writetask.write([a,a,a])
                    #sleep at start to avoid outliers
                    if t < 5:
                        time.sleep(.5)
                    start = time.time()
                    data=keith2000.measureMulti(average)
                    fdata=[] # origin measured field is in unit V, ifield is conversion value with unit Oe/V
                    findex=1
                    while findex<=5: #Average of five measurements
                        fdata=[fdata[i]+readtask.read()[i] for i in range(0,3)]
                        findex+=1
                    fielddata=[x*ifield/5 for x in fdata] #while loop is for averaging 5 measurements
                    m_zfield.append(fielddata[zchan])
                    m_xfield.append(fielddata[xchan])
                    m_yfield.append(fielddata[ychan])
                    tmp=double(1000*data/current_start) # Voltage from K2000 / Current from K2400 (Hall resistance)
                    result.append(tmp)
                    values_y.append(tmp)
                    values_x.append(a*i)
                    #ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                    mid = time.time()
                    ax.plot(values_x, values_y,'b-o', ms=dot_size, mew=dot_edge, alpha=0.5)
                    canvas.draw()
                    listbox_l.insert('end', "Hall Resistance:" + str(round(tmp,4)) + " Applied Field:" + str(round(a*i,4)) + " Measured Field:" + str(round(fielddata[zchan],4)))
                    t+=1
                    a+=step
                    listbox_l.see(END)
                    fin = time.time()
                    m_time.append(fin-start)
                    print('Total Time: ', (fin-start), '\n Plot time: ', (fin-mid))

                while t <= 4*n :

                    start = time.time()
                    writetask.write([a,a,a])
                    data=keith2000.measureMulti(average)
                    fdata=[] # origin measured field is in unit V, ifield is conversion value with unit Oe/V
                    findex=1
                    while findex<=5: #Average of five measurements
                        fdata=[fdata[i]+readtask.read()[i] for i in range(0,3)]
                        findex+=1
                    fielddata=[x*ifield/5 for x in fdata] #while loop is for averaging 5 measurements
                    m_zfield.append(fielddata[zchan])
                    m_xfield.append(fielddata[xchan])
                    m_yfield.append(fielddata[ychan])
                    tmp=double(1000*data/current_start) # Voltage from K2000 / Current from K2400
                    result.append(tmp)
                    values_y.append(tmp)
                    values_x.append(a*i)
                    mid = time.time()
                    #ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                    ax.plot(values_x, values_y,'b-o', ms=dot_size, mew=dot_edge, alpha=0.5)
                    canvas.draw()
                    listbox_l.insert('end', "Hall Resistance:" + str(round(tmp,4)) + " Applied Field:" + str(round(a*i,4)) + " Measured Field:" + str(round(fielddata[zchan],4)))
                    t+=1
                    a-=step
                    listbox_l.see(END)
                    fin = time.time()
                    m_time.append(fin-start)
                    print('Total Time: ', (fin-start), '\n Plot time: ', (fin-mid))
'''
                #Setup timestamp
                stamp = datetime.now().strftime('%Y-%m-%d-%H%M%S')
                listbox_l.insert('end', str(stamp))

                file = open(
                    str(directory) + "/" + str(_sample) + "GMW_AMR_" +
                    str(round(resistance, 2)) + "Ohm_" +
                    str(round(current_start, 2)) + "mA_" + str(stamp), "w")
                file.write("Sample name: " + str(_sample) + "\n")
                file.write("Applied current: " + str(current_start) +
                           "(mA)\n\n")
                file.write("Number" + " " + "Applied Field Angle" + " " +
                           "Resistance(Ohm)" + " " + "Measure_time" + " " +
                           "Measured Field Angle" + " " +
                           "Measured XField(Oe)" + " " +
                           "Measured YField(Oe)" + " " +
                           "Measured ZField(Oe)" + "\n")

                cnt = 1
                #output all data
                for a in range(len(values_y)):

                    file.write(
                        str(cnt) + " " + str(values_x[a]) + " " +
                        str(values_y[a]) + " " + str(m_time[a]) + " " +
                        str(m_fieldang[a]) + " " + str(m_xfield[a]) + " " +
                        str(m_yfield[a]) + " " + str(m_zfield[a]) + "\n")
                    cnt += 1

                file.closed

                listbox_l.insert('end', "The Measurement data is saved.")
                listbox_l.see(END)

                #keith.outputOff()
                current_start = current_start - current_step

                time.sleep(1)  #Sleep between each scan

            Hin_start = Hin_start - Hin_step

        writetask.write([0, 0, 0])
        writetask.close()
        readtask.close()

        keith.fourWireOff()
        keith.outputOn()

        listbox_l.insert('end', "Measurement finished")
        listbox_l.see(END)
예제 #8
0
    def event():

        Hx_start = float(_Hx)  # Max Hx field value
        Hx_end = float(_Hx) * (-1)  # Min Hx field value
        Hx_step = float(_dHx)  # step in Hx field

        keith = Keithley2400(f)  #Initiate K2400
        amp = lockinAmp(func, sense, signal, freq)  #Initiate Lock-in

        while Hx_start >= Hx_end:

            amp.dacOutput((Hx_start / ix), DACx)

            current_start = float(
                _current)  # Max current set by Keithley  2400
            current_end = float(_current) * (
                -1)  # Min current set by Keithley 2400
            current_step = float(_step)  # step in current

            while current_start >= current_end:

                ax.clear()
                ax.grid(True)
                ax.set_title("Realtime Hall voltage vs H Plot")
                ax.set_xlabel("Applied Field (Oe)")
                ax.set_ylabel("Lock-In X (mV)")

                listbox_l.insert(
                    'end',
                    "Now measuring with Hx = %f (Oe) and Idc = %f (mA) " %
                    (Hx_start, current_start))
                listbox_l.see(END)

                #Prepare data entries
                global values_x, values_y, result

                values_y = []
                values_x = []
                result = []

                #Setup K2400 for current output and resistance measurement
                keith.setCurrent(current_start)
                keith.outputOn()

                index = 1
                data = []

                while index <= 5:  #Average of five measurements
                    data = data + keith.measureOnce()
                    index += 1

                print("Measured current: %f mA" % (1000 * data[2]))
                print("Measured voltage: %f V" % data[1])
                print("Measured resistance: %f Ohm" % (data[1] / data[2]))

                save = (data[1] / data[2])

                #Setup lock-in for dac (Hz field) output
                t = 0
                a = 0.0
                step = (double(_output) / i) / n

                while t < n:

                    amp.dacOutput(a, DAC)
                    tmp = 1000 * double(amp.readX(average))  #in units of mV
                    result.append(tmp)
                    values_y.append(tmp)
                    values_x.append(a * i)
                    ax.plot(values_x,
                            values_y,
                            'b-o',
                            ms=dot_size,
                            mew=dot_edge,
                            alpha=0.5)
                    canvas.draw()
                    listbox_l.insert('end', tmp)
                    t += 1
                    a += step
                    listbox_l.see(END)

                while t < 3 * n:

                    amp.dacOutput(a, DAC)
                    tmp = 1000 * double(amp.readX(average))
                    result.append(tmp)
                    values_y.append(tmp)
                    values_x.append(a * i)
                    ax.plot(values_x,
                            values_y,
                            'b-o',
                            ms=dot_size,
                            mew=dot_edge,
                            alpha=0.5)
                    canvas.draw()
                    listbox_l.insert('end', tmp)
                    t += 1
                    a -= step
                    listbox_l.see(END)

                while t <= 4 * n:

                    amp.dacOutput(a, DAC)
                    tmp = 1000 * double(amp.readX(average))
                    result.append(tmp)
                    values_y.append(tmp)
                    values_x.append(a * i)
                    ax.plot(values_x,
                            values_y,
                            'b-o',
                            ms=dot_size,
                            mew=dot_edge,
                            alpha=0.5)
                    canvas.draw()
                    listbox_l.insert('end', tmp)
                    t += 1
                    a += step
                    listbox_l.see(END)

                #Setup timestamp
                stamp = datetime.now().strftime('%Y-%m-%d-%H%M%S')
                listbox_l.insert('end', str(stamp))

                file = open(
                    str(directory) + "/" + str(_sample) + "_" + str(save) +
                    "Ohm_" + str(Hx_start) + "Oe_" + str(current_start) +
                    "mA_" + str(stamp), "w")
                file.write("" + str(_sample) + "\n")
                file.write("Initial resistance: " + str(save) + "(Ohm)\n")
                file.write("Applied in-plane field: " + str(Hx_start) +
                           "(Oe)\n")
                file.write("Applied current: " + str(current_start) +
                           "(mA)\n\n")
                file.write("Number" + " " + "Field(Oe)" + " " + "Voltage(mV)" +
                           "\n")

                cnt = 1
                #output all data
                for a in range(len(values_y)):

                    file.write(
                        str(cnt) + " " + str(values_x[a]) + " " +
                        str(values_y[a]) + "\n")
                    cnt += 1

                file.closed

                listbox_l.insert('end', "The Measurement data is saved.")
                listbox_l.see(END)

                keith.outputOff()
                current_start = current_start - current_step

                time.sleep(1)  #Sleep between each scan

            Hx_start = Hx_start - Hx_step

        amp.dacOutput(0, DACx)
        amp.dacOutput(0, DAC)
        listbox_l.insert('end', "Measurement finished")
        listbox_l.see(END)
    def event():

        Hx_start = float(_Hx)  # Max Hx field strength
        Hx_end = float(_Hx) * (-1)  # Min Hx field strength
        Hx_step = float(_dHx)  # step in Hx field per loop

        keith = Keithley2400('CURR')  #Initiate K2400
        amp = lockinAmp(func, sense, signal, freq)  #Initiate Lock-in

        while Hx_start >= Hx_end:

            amp.dacOutput((Hx_start / ix), DACx)

            current_max = float(
                _current)  # max current applied by Keithley 2400
            current_min = float(_current) * (
                -1)  # min current applied by Keithley 2400
            current_step = float(_step)  # current step per loop

            ax.clear()
            ax.grid(True)

            ax.set_title("Realtime MOKE signal vs I Plot")
            ax.set_xlabel("Applied Current (mA)")
            ax.set_ylabel("MOKE signal (R+G+B)")

            ax.set_title("Realtime Hall voltage vs I Plot")
            ax.set_xlabel("Applied Current (mA)")
            ax.set_ylabel("Lock-In X (mV)")

            listbox_l.insert('end',
                             "Now measuring with Hx = %f (Oe)" % Hx_start)
            listbox_l.see(END)

            #Prepare data entries
            global values_x, values_y, result

            values_y = []
            values_x = []
            result = []

            #Setup K2400 for current output and resistance measurement
            keith.setCurrent(0.1)  #Use 0.1mA to measure DC resistance
            keith.outputOn()

            index = 1
            data = []

            while index <= 5:  #Average of five measurements
                data = data + keith.measureOnce()
                index += 1

            print("Measured current: %f mA" % (1000 * data[2]))
            print("Measured voltage: %f V" % data[1])
            print("Measured resistance: %f Ohm" % (data[1] / data[2]))

            save = (data[1] / data[2])

            #Setup Keithley for Idc sweep
            current = 0

            trigger_delay = float(_rest_length)
            source_delay = float(_pulse_length)

            while current < current_max:

                keith.pulse(current, current_max, trigger_delay, source_delay)

                tmp = imageMethod(x1, y1, x2, y2)  #get image lumi
                result.append(tmp)
                values_y.append(tmp)
                values_x.append(current)
                ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                canvas.draw()
                listbox_l.insert('end', tmp)
                current += current_step
                listbox_l.see(END)

            while current > -current_max:

                keith.pulse(current, current_max, trigger_delay, source_delay)
                tmp = imageMethod(x1, y1, x2, y2)  #get image lumi
                result.append(tmp)
                values_y.append(tmp)
                values_x.append(current)
                ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                canvas.draw()
                listbox_l.insert('end', tmp)
                current -= current_step
                listbox_l.see(END)

            while current <= 0:

                keith.pulse(current, current_max, trigger_delay, source_delay)
                tmp = imageMethod(x1, y1, x2, y2)  #get image lumi
                result.append(tmp)
                values_y.append(tmp)
                values_x.append(current)
                ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                canvas.draw()
                listbox_l.insert('end', tmp)
                current += current_step
                listbox_l.see(END)

            stamp = datetime.now().strftime('%Y-%m-%d-%H%M%S')
            file = open(
                str(directory) + "/" + str(_sample) + "_pulse_switching" +
                str(Hx_start) + "Oe" + "_" + str(stamp), "w")
            file.write(str(_sample) + "\n")
            file.write("Initial resistance: " + str(save) + "(Ohm)\n")
            file.write("Applied in-plane field: " + str(Hx_start) + "(Oe)\n\n")
            file.write("Number" + " " + "Field(Oe)" + " " +
                       "MOKE signal(RGB)" + "\n")

            cnt = 1
            #output all data
            for a in range(len(values_y)):

                file.write(
                    str(cnt) + " " + str(values_x[a]) + " " +
                    str(values_y[a]) + "\n")
                cnt += 1

            file.closed

            listbox_l.insert('end', "The Measurement data is saved.")
            listbox_l.see(END)

            keith.outputOff()

            time.sleep(1)  #Sleep between each scan

            Hx_start = Hx_start - Hx_step

        amp.dacOutput(0, DACx)
        amp.dacOutput(0, DAC)
        listbox_l.insert('end', "Measurement finished")
        listbox_l.see(END)
    def event():

        Hx_start=float(_Hx)
        Hx_end=float(_Hx)*(-1)
        Hx_step=float(_dHx)

        keith=Keithley2400('CURR') #Initiate K2400
        amp = lockinAmp(func, sense, signal, freq) #Initiate Lock-in

        while Hx_start>=Hx_end:

            amp.dacOutput((Hx_start/ix), DACx)

            current_max=float(_current)
            current_min=float(_current)*(-1)
            current_step=float(_step)
    
            #while current_start>=current_end:

            ax.clear()
            ax.grid(True)
            ax.set_title("Realtime Resistance vs I Plot")
            ax.set_xlabel("Applied Pulsed Current (mA)")
            ax.set_ylabel("Keithley 2400 Resistance (Ohm)")

            listbox_l.insert('end',"Now measuring with Hx = %f (Oe)" %Hx_start)
            listbox_l.see(END)
            
            #Prepare data entries
            global values_x, values_y, result

            values_y=[]
            values_x=[]
            result=[]
            
            #Setup K2400 for current output and resistance measurement
            keith.setCurrent(0.1) #Use 0.1mA to measure DC resistance 
            keith.outputOn()

            index=1
            data=[]

            while index<=5: #Average of five measurements
                data=data+keith.measureOnce()
                index+=1
        
            print("Measured current: %f mA" %(1000*data[2]))
            print("Measured voltage: %f V" %data[1])
            print("Measured resistance: %f Ohm" %(data[1]/data[2]))

            #Setup Keithley for Idc sweep
            current=0.01
            
            trigger_delay=float(_rest_length)
            source_delay=float(_pulse_length)
    
            while current < current_max :
                
                keith.pulse(current,current_max, trigger_delay, source_delay)
                data=keith.measureOnce()
                tmp=double(data[1]/data[2]) #Resistance from K2400
                result.append(tmp)
                values_y.append(tmp)
                values_x.append(current)
                #ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                ax.plot(values_x, values_y,'b-o', ms=dot_size, mew=dot_edge, alpha=0.5)
                canvas.draw()
                listbox_l.insert('end', tmp)
                current+=current_step
                listbox_l.see(END)

            while current > -current_max:

            
                keith.pulse(current,current_max, trigger_delay, source_delay)
                data=keith.measureOnce()
                tmp=double(data[1]/data[2]) #Resistance from K2400
                result.append(tmp)
                values_y.append(tmp)
                values_x.append(current)
                #ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                ax.plot(values_x, values_y,'b-o', ms=dot_size, mew=dot_edge, alpha=0.5)
                canvas.draw()
                listbox_l.insert('end', tmp)
                current-=current_step
                listbox_l.see(END)

            while current <= 0 :

                keith.pulse(current, current_max, trigger_delay, source_delay)
                data=keith.measureOnce()
                tmp=double(data[1]/data[2]) #Resistance from K2400
                result.append(tmp)
                values_y.append(tmp)
                values_x.append(current)
                #ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                ax.plot(values_x, values_y,'b-o', ms=dot_size, mew=dot_edge, alpha=0.5)
                canvas.draw()
                listbox_l.insert('end', tmp)
                current+=current_step
                listbox_l.see(END)


            stamp = datetime.now().strftime('%Y-%m-%d-%H%M%S')
            listbox_l.insert('end', str(stamp))

            file = open(str(directory)+"/MR_STT_pulsed_switching_"+str(_sample)+"_"+str(Hx_start)+"Oe_"+str(source_delay)+"s_"+str(stamp), "w")
            file.write(str(_sample)+"\n")
            file.write("Applied in-plane field: "+str(Hx_start)+"(Oe)\n\n")
            file.write("Number"+" "+"Current(mA)"+" "+"Resistance(Ohm)"+"\n")

            cnt=1
            #output all data 
            for a in range(len(values_y)):

                file.write(str(cnt)+" "+str(values_x[a])+" "+str(values_y[a])+"\n")
                cnt +=1

            file.closed

            listbox_l.insert('end', "The Measurement data is saved.")
            listbox_l.see(END)

            keith.outputOff()

            time.sleep(1) #Sleep between each scan

            Hx_start=Hx_start-Hx_step

        amp.dacOutput(0, DACx)
        amp.dacOutput(0, DAC)
        listbox_l.insert('end',"Measurement finished")
        listbox_l.see(END)
예제 #11
0
def measure_method(magnet, keith, plot_title, x_axis_label, y_axis_label):

    # make sure delay and averages are ints
    if fetch_entry('Delay (s)', keith).lstrip('-').replace('.', '',
                                                           1).isdigit():
        delay = float(fetch_entry('Delay (s)', keith))
    else:
        messagebox.showwarning(
            'Invalid Entry',
            'Delay value not found to be a number, automatically set to 1')
        delay = 1

    if fetch_entry('Averages', keith).lstrip('-').replace('.', '',
                                                          1).isdigit():
        avg = float(fetch_entry('Averages', keith))
    else:
        messagebox.showwarning(
            'Invalid Entry',
            'Delay value not found to be a number, automatically set to 1')
        avg = 1

    # set the scan and fixed applied field directions
    if H_dir_loop == 'Hz':
        scan = 'Hz'
        scan_dac = DACz
        scan_interval = float(fetch_entry('Hz (Oe)/DAC (V)', magnet))
        scan_limit = 1
        fix = 'Hx'
        fix_dac = DACx
        fix_interval = float(fetch_entry('Hx (Oe)/DAC (V)', magnet))
        fix_limit = 12
    else:
        scan = 'Hx'
        scan_dac = DACx
        scan_interval = float(fetch_entry('Hx (Oe)/DAC (V)', magnet))
        scan_limit = 12
        fix = 'Hz'
        fix_dac = DACz
        fix_interval = float(fetch_entry('Hz (Oe)/DAC (V)', magnet))
        fix_limit = 1

    # create the lists of field values, scan loop is modified to include full loop
    if field_loop == 'Step':
        scan_field_output = make_list(
            fetch_entry('%s Field (Oe)' % scan, magnet),
            fetch_entry('%s Step (Oe)' % scan, magnet))
        inverse = reversed(scan_field_output[0:-1])
        for x in inverse:
            scan_field_output.append(x)
        fix_field_output = make_list(
            fetch_entry('%s Field (Oe)' % fix, magnet),
            fetch_entry('%s Step (Oe)' % fix, magnet))
    else:
        scan_field_output = convert_to_list(
            fetch_entry('%s Field (Oe)' % scan, magnet))
        inverse = reversed(scan_field_output[0:-1])
        for x in inverse:
            scan_field_output.append(x)
        fix_field_output = convert_to_list(
            fetch_entry('%s Field (Oe)' % fix, magnet))

    # create the list of current values
    if current_loop == 'Step':
        current_output = make_list(fetch_entry('Current (mA)', keith),
                                   fetch_entry('Current Step (mA)', keith))
    else:
        current_output = convert_to_list(fetch_entry('Current (mA)', keith))

    keith_2400 = Keithley2400('f')  #Initiate K2400
    keith_2000 = Keithley('f')  #Initiate K2000
    amp = lockinAmp(func, sense, signal, freq)  #Initiate Lock-in

    def event():
        # if in bounds run scan
        for fix_val in fix_field_output:

            amp.dacOutput(fix_val / fix_interval, fix_dac)

            for current_val in current_output:

                #Setup K2400 for current output and initial resistance measurements
                keith_2400.fourWireOff()
                keith_2400.setCurrent(current_val)
                keith_2400.outputOn()

                index = 1
                data = []

                while index <= 5:  #Average of five measurements
                    data = data + keith_2400.measureOnce()
                    index += 1

                display.insert('end',
                               "Measured current: %f mA" % (1000 * data[2]))
                display.insert('end', "Measured voltage: %f V" % data[1])
                display.insert(
                    'end', "Measured resistance: %f Ohm" % (data[1] / data[2]))
                display.see(END)

                resistance = data[1] / data[2]

                # intializes the measurement data list
                measured_values = []

                # reset the plot to be clear for graphing
                plot_set(plot_title, x_axis_label, y_axis_label)

                display.insert('end',
                               'Measurement at %s (mA)' % str(current_val))
                display.insert('end', 'Measurement at %s (Oe)' % str(fix_val))
                display.see(END)

                # loop over all scan values
                for scan_val in scan_field_output:

                    amp.dacOutput(scan_val / scan_interval, scan_dac)
                    # allows amp output to power fully up at high values
                    if len(measured_values) < 5:
                        time.sleep(0.5)
                    data = keith_2000.measureMulti(avg)
                    tmp = float(
                        1000 * data /
                        current_val)  # Voltage from K2000 / Current from K2400
                    measured_values.append(tmp)
                    ax.plot(scan_field_output[0:len(measured_values)],
                            measured_values,
                            'b-o',
                            ms=10,
                            mew=0.5,
                            alpha=0.5)
                    dataplot.draw()
                    display.insert(
                        'end',
                        'Applied %s Field Value: %s (Oe)      Measured Resistance: %s (Ohm)'
                        % (scan, scan_val, round(tmp, 4)))
                    display.see(END)

                # save data
                save_method(fix_val, current_val, scan_field_output,
                            measured_values)
                # sleep between cycles
                time.sleep(delay)

        # turn everything off at end of loop
        amp.dacOutput(0, fix_dac)
        amp.dacOutput(0, scan_dac)

        keith_2400.fourWireOff()
        keith_2400.outputOn()

        display.insert('end', "Measurement finished")
        display.see(END)

    #check to make sure all output values are in bounds.
    if max(fix_field_output) / fix_interval < fix_limit and max(
            scan_field_output) / scan_interval < scan_limit:
        th = threading.Thread(target=event)
        th.start()
    else:
        messagebox.showwarning('Output Too Large',
                               'Output value beyond amp voltage threshold')
        display.insert('end', 'Output value too large!')
        display.see(END)
예제 #12
0
    def event():

        keith = Keithley2400(f)  #Initiate K2400
        keith2000 = Keithley(f)  #Initiate K2000

        writetask = nidaqmx.Task()  #Initiate GMW write & read channels
        readtask = nidaqmx.Task()

        Va_applied = writetask.ao_channels.add_ao_voltage_chan(
            "VectorMagnet/ao0")
        Vb_applied = writetask.ao_channels.add_ao_voltage_chan(
            "VectorMagnet/ao1")
        Vc_applied = writetask.ao_channels.add_ao_voltage_chan(
            "VectorMagnet/ao2")

        Field_X = readtask.ai_channels.add_ai_voltage_chan("VectorMagnet/ai0")
        Field_Y = readtask.ai_channels.add_ai_voltage_chan("VectorMagnet/ai1")
        Field_Z = readtask.ai_channels.add_ai_voltage_chan("VectorMagnet/ai2")
        #readtask.read() will give [V_ai0, V_ai1, V_ai2]

        current_start = float(_current)
        current_end = float(_current) * (-1)
        current_step = float(_step)

        while current_start >= current_end:
            ax.clear()
            ax.grid(True)
            ax.set_title("Realtime Resistance vs H Plot")
            ax.set_xlabel("Applied Z Field (Oe)")
            ax.set_ylabel("Hall Resistance (Ohm)")

            listbox_l.insert(
                'end', "Now measuring with Idc = %f (mA) " % (current_start))
            listbox_l.see(END)

            #Prepare data entries
            global values_x, values_y, result, canvas

            values_y = []
            values_x = []
            result = []

            #Setup K2400 for current output and resistance measurement
            keith.fourWireOff()
            keith.setCurrent(current_start)
            keith.outputOn()

            index = 1
            data = []
            m_time = []
            m_xfield = []
            m_yfield = []
            m_zfield = []

            while index <= 5:  #Average of five measurements
                data = data + keith.measureOnce()
                index += 1

            listbox_l.insert('end',
                             "Measured current: %f mA" % (1000 * data[2]))
            listbox_l.insert('end', "Measured voltage: %f V" % data[1])
            listbox_l.insert(
                'end', "Measured resistance: %f Ohm" % (data[1] / data[2]))
            listbox_l.see(END)

            resistance = data[1] / data[2]

            #Setup lock-in for dac (Hz field) output
            t = 0
            a = (float(_output) / i) * (-1)
            step = (double(_output) / i) / n

            writetask.write(
                [a, a, a])  #initial application of field to avoid outliers

            while t < 2 * n:

                writetask.write([a, a, a])
                #sleep at start to avoid outliers
                if t < 5:
                    time.sleep(.5)
                start = time.time()
                data = keith2000.measureMulti(average)
                fdata = [
                    0, 0, 0
                ]  # origin measured field is in unit V, ifield is conversion value with unit Oe/V
                findex = 1
                while findex <= 5:  #Average of five measurements
                    fdata = [
                        fdata[i] + readtask.read()[i] for i in range(0, 3)
                    ]
                    findex += 1
                fielddata = [x * ifield / 5 for x in fdata
                             ]  #while loop is for averaging 5 measurements
                print(fielddata)
                m_zfield.append(fielddata[zchan])
                m_xfield.append(fielddata[xchan])
                m_yfield.append(fielddata[ychan])
                tmp = double(
                    1000 * data / current_start
                )  # Voltage from K2000 / Current from K2400 (Hall resistance)
                result.append(tmp)
                values_y.append(tmp)
                values_x.append(a * i)
                #ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                mid = time.time()
                ax.plot(values_x,
                        values_y,
                        'b-o',
                        ms=dot_size,
                        mew=dot_edge,
                        alpha=0.5)
                canvas.draw()
                listbox_l.insert(
                    'end', "Hall Resistance:" + str(round(tmp, 4)) +
                    " Applied Field:" + str(round(a * i, 4)) +
                    " Measured Field:" + str(round(fielddata[zchan], 4)))
                t += 1
                a += step
                listbox_l.see(END)
                fin = time.time()
                m_time.append(fin - start)
                print('Total Time: ', (fin - start), '\n Plot time: ',
                      (fin - mid))

            while t <= 4 * n:

                start = time.time()
                writetask.write([a, a, a])
                data = keith2000.measureMulti(average)
                fdata = [
                    0, 0, 0
                ]  # origin measured field is in unit V, ifield is conversion value with unit Oe/V
                findex = 1
                while findex <= 5:  #Average of five measurements
                    fdata = [
                        fdata[i] + readtask.read()[i] for i in range(0, 3)
                    ]
                    findex += 1
                fielddata = [x * ifield / 5 for x in fdata
                             ]  #while loop is for averaging 5 measurements
                m_zfield.append(fielddata[zchan])
                m_xfield.append(fielddata[xchan])
                m_yfield.append(fielddata[ychan])
                tmp = double(
                    1000 * data /
                    current_start)  # Voltage from K2000 / Current from K2400
                result.append(tmp)
                values_y.append(tmp)
                values_x.append(a * i)
                mid = time.time()
                #ax.scatter(values_x[-1], values_y[-1], s=50, alpha=0.5)
                ax.plot(values_x,
                        values_y,
                        'b-o',
                        ms=dot_size,
                        mew=dot_edge,
                        alpha=0.5)
                canvas.draw()
                listbox_l.insert(
                    'end', "Hall Resistance:" + str(round(tmp, 4)) +
                    " Applied Field:" + str(round(a * i, 4)) +
                    " Measured Field:" + str(round(fielddata[zchan], 4)))
                t += 1
                a -= step
                listbox_l.see(END)
                fin = time.time()
                m_time.append(fin - start)
                print('Total Time: ', (fin - start), '\n Plot time: ',
                      (fin - mid))

            #Setup timestamp
            stamp = datetime.now().strftime('%Y-%m-%d-%H%M%S')
            listbox_l.insert('end', str(stamp))

            file = open(
                str(directory) + "/" + str(_sample) + "_GMW_pureZ_" +
                str(round(resistance, 2)) + "Ohm_" +
                str(round(current_start, 2)) + "mA_" + str(stamp), "w")
            file.write("Sample name: " + str(_sample) + "\n")
            file.write("Applied current: " + str(current_start) + "(mA)\n\n")
            file.write("Number" + " " + "Applied Field(Oe)" + " " +
                       "Resistance(Ohm)" + " " + "Measure_time" + " " +
                       "Measured XField(Oe)" + " " + "Measured YField(Oe)" +
                       " " + "Measured ZField(Oe)" + "\n")

            cnt = 1
            #output all data
            for a in range(len(values_y)):

                file.write(
                    str(cnt) + " " + str(values_x[a]) + " " +
                    str(values_y[a]) + " " + str(m_time[a]) + " " +
                    str(m_xfield[a]) + " " + str(m_yfield[a]) + " " +
                    str(m_zfield[a]) + "\n")
                cnt += 1

            file.closed

            listbox_l.insert('end', "The Measurement data is saved.")
            listbox_l.see(END)

            #keith.outputOff()
            current_start = current_start - current_step

            time.sleep(1)  #Sleep between each scan

        #amp.dacOutput(0, DACx)
        #amp.dacOutput(0, DAC)
        writetask.write([0, 0, 0])
        writetask.close()
        readtask.close()

        keith.fourWireOff()
        keith.outputOn()

        listbox_l.insert('end', "Measurement finished")
        listbox_l.see(END)