Warning: Can not open [/home/conf/public_html/cgi-bin/show_python.log]. Ignore No title

Download script from 2450_IV.py
Related files:


import os
import sys
import time
import pyvisa
import numpy as np
import matplotlib.pyplot as plt


rm = pyvisa.ResourceManager()

address = None
dev_list = []
devstr = ""
inst = None


def terminate():
    print("")
    exit()

def pint(s, defval = None):
    try:
        return int(s)
    except:
        return defval

def pfloat(s, defval = None):
    try:
        return float(s)
    except:
        return defval

def list(is_print = True):
    global dev_list

    dev_list = rm.list_resources()

    if is_print:
        print(" Device list:", dev_list)
    return dev_list

def get_devstr(addr):
    global dev_list

    dev_list = list(is_print = False)
#    print("dev_list=", dev_list)
    for s in dev_list:
        aa = s.split('::')
#        print("s=", s, aa)
        if len(aa) < 2:
            continue

        if pint(aa[1]) == addr:
            return s

    return None

def close_device():
    global inst

    if inst:
        inst.close()
        inst = None
        return True

    return False

def open_device(devname):
    global devstr, address, inst

    close_device()

    inst = rm.open_resource(devname)
    if inst:
        print(f" found device [{devname}]. assigned to current instrument handle")
        devstr = devname
        aa = devname.strip().split('::')
        address = pint(aa[1])
    else:
        print(f" Error: Can not open device [{devname}]")

    return inst

def main():
    global rm, dev_list, devstr, address, inst

    dev_list = list()
    if len(dev_list) > 0:
        inst = open_device(dev_list[0])
        devname = dev_list[0]
    else:
        print("Error: No device found")
        terminate()

    if inst is None:
        return

    keithley = inst

    keithley.write(":SENS:CURR:RANG:AUTO ON")


    keithley.write(":INIT")

    Vlist = []
    Ilist = []
    for V in np.arange(-1.0, 1.001, 0.1):
        keithley.write(f":SOUR:VOLT {V:10.4g}")


        V, I = ret.split(',')
        V = pfloat(V)
        I = pfloat(I)
        Vlist.append(V)
        Ilist.append(I)
        print(f" set V={V:10.4g} measured V={V:14.6g} I={I:14.6g}")
#        print("Current:", current)

    keithley.write(":OUTP OFF")

    keithley.close()

    plt.plot(Vlist, Ilist)
#    plt.yscale('log')
    plt.show()


if __name__ == "__main__":
    main()