# -*- coding: utf-8 -*- """ Created on Tue Jan 24 15:56:51 2023 @author: Javier Navarro Montilla """ import pyvisa import time import numpy as np #============================================================================== # Input parameters #============================================================================== sweep_range = 'BEST' #Select sweep ranging: AUTO, BEST, or FIXed. spacing = 'LIN' #Sweep type points = 150 #Sweep number of points (max number of poits 100, otherwise buffer overrun) start_level = -0.5e-3 #starting current value stop_level = 0.5e-3 #ending current value compliance = 10 #Compliance voltage (max voltage to apply on the DUT) delay = 0.01 #Query source delay in seconds voltage = 1 #voltage measure range in volts NPLC = 1 #Integration time for the 2182 in units of Number of Power Line Cycles #============================================================================== # Main code #============================================================================== rm = pyvisa.ResourceManager() print('List of VISA resources available (check for GPIB connexion):') print(rm.list_resources()) print('\n') keithley = rm.open_resource('GPIB0::12::INSTR') keithley.write('*RST') time.sleep(2) keithley.write(':SYST:COMM:SERIal:SEND "*rst"') keithley.write('SYSTem:COMMunicate:SERial:BAUD 19200') #keithley.write('SYSTem:COMMunicate:SERial:PACE XON') time.sleep(1) print('Arming sweep in Ketihley 6221...') keithley.write(':SOUR:SWE:RANG ' + sweep_range) keithley.write(':SOUR:SWE:SPAC ' + spacing) keithley.write(':SOUR:SWE:POIN ' + str(points)) keithley.write(':SOUR:SWE:COUN 1' ) keithley.write(':SOUR:SWE:CAB ON') #Enable to abort sweep on compliance keithley.write(':SOUR:CURR:STAR ' + str(start_level)) keithley.write(':SOUR:CURR:STOP ' + str(stop_level)) keithley.write(':SOUR:CURR:COMP ' + str(compliance)) keithley.write('SOUR:DEL ' + str(delay)) keithley.write('TRIG:SOUR TLINK') #Configure the triggert to use the cable connecting 6221 and 2182A keithley.write('TRIG:DIR SOUR') #Control ARM source bypass keithley.write('TRIG:OLIN 2') #Set ARM output signal line to 2 keithley.write('TRIG:ILIN 1') #Set ARM input signal line to 1 keithley.write('TRIG:OUTP DEL') #Enable/disable ARM output trigger time.sleep(0.2) keithley.write('TRAC:CLE') time.sleep(0.2) keithley.write('TRAC:POIN %i' %points) #Specify size of buffer 6221 time.sleep(0.2) keithley.write(':SYST:COMM:SERIal:SEND ":TRAC:CLE"') time.sleep(0.2) keithley.write(':SYST:COMM:SERIal:SEND ":SENS:VOLT:RANG:UPP %f"'%voltage) time.sleep(0.4) keithley.write(':SYST:COMM:SERIal:SEND ":SENS:VOLT:NPLC %i"'%NPLC) time.sleep(0.4) keithley.write(':SYST:COMM:SERIal:SEND ":TRAC:CLE"') #Clear readings from buffer in 2182A time.sleep(0.2) keithley.write(':SYST:COMM:SERIal:SEND ":TRAC:FEED SENS"') #Select source of readings for buffer; SENSe[1],CALCulate[1], or NONE. time.sleep(0.2) keithley.write(':SYST:COMM:SERIal:SEND ":TRAC:POIN %i"' %points) #Specify size of buffer time.sleep(0.2) keithley.write(':SYST:COMM:SERIal:SEND ":TRIG:SOUR EXT"') #Select control source; IMMediate, TIMer, MANual, BUS, or EXTernal. time.sleep(0.2) keithley.write(':SYST:COMM:SERIal:SEND ":TRIG:COUN %i"' %points) #Specify sample count; 1 to 1024. time.sleep(0.2) keithley.write(':SYST:COMM:SERIal:SEND ":TRAC:FEED:CONTROL NEXT"') #Select buffer control mode (NEXT or NEVer). time.sleep(0.5) keithley.write(':SOUR:SWE:ARM') time.sleep(2) print('Waiting time: %.2f sec' %(points*delay*NPLC*10)) keithley.write(':INIT:IMM') #:INIT to take the instrument out of idle state keithley.write(':SYST:COMM:SERIal:SEND "INIT"') #Initiate one trigger cycle. print('Performing measurement...') time.sleep(points*delay*NPLC*10) keithley.write('SYST:COMM:SERIal:SEND "TRAC:DATA?"') time.sleep(1) empty = False i = 0 voltage_meas = '' while empty == False and i < 200: measurement = keithley.query('SYST:COMM:SER:ENTer?') time.sleep(0.4) if len(measurement) != 1: measurement = str(measurement) print('iteration %i:' %i) print(measurement) voltage_meas = voltage_meas + measurement.strip() else: empty = True i = i+1 keithley.write('OUTP OFF') print('End of the measurement') voltage_meas = [float(j) for j in voltage_meas.split(',')]