2023-04-06 22:55:24 +02:00
|
|
|
from time import sleep
|
|
|
|
import numpy as np
|
|
|
|
from matplotlib import pyplot as plt
|
|
|
|
|
|
|
|
smua_settings = """
|
|
|
|
display.clear()
|
|
|
|
display.settext('starting')
|
|
|
|
smua.reset()
|
|
|
|
smua.measure.autorangev = smua.AUTORANGE_ON
|
2023-04-07 18:14:15 +02:00
|
|
|
smua.measure.autozero = smua.AUTOZERO_ONCE
|
2023-04-06 22:55:24 +02:00
|
|
|
smua.source.output = smua.OUTPUT_OFF
|
|
|
|
-- max 20 V expected
|
|
|
|
smua.measure.rangev = 20
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2023-04-07 18:14:15 +02:00
|
|
|
script_dir = "scripts/"
|
2023-04-06 22:55:24 +02:00
|
|
|
scripts = {
|
2023-04-07 18:14:15 +02:00
|
|
|
"buffer_reset": "buffer_reset.lua",
|
|
|
|
"smua_reset": "smua_reset.lua",
|
2023-04-06 22:55:24 +02:00
|
|
|
}
|
2023-04-13 11:09:40 +02:00
|
|
|
for key,val in scripts.items():
|
|
|
|
scripts[key] = script_dir + scripts[key]
|
2023-04-06 22:55:24 +02:00
|
|
|
|
2023-04-07 18:14:15 +02:00
|
|
|
|
|
|
|
def run_lua(instr, script_path, verbose=False):
|
2023-04-13 11:09:40 +02:00
|
|
|
"""
|
|
|
|
Run a lua script from the host on the instrument
|
|
|
|
@param instr : pyvisa instrument
|
|
|
|
@param script_path : full path to the script
|
|
|
|
"""
|
|
|
|
with open(script_path, "r") as file:
|
2023-04-06 22:55:24 +02:00
|
|
|
script = file.read()
|
2023-04-13 11:09:40 +02:00
|
|
|
if verbose: print(f"Running script: {script_path}")
|
2023-04-06 22:55:24 +02:00
|
|
|
instr.write(script)
|
|
|
|
|
|
|
|
|
2023-04-07 18:14:15 +02:00
|
|
|
def measure_V(instr, count=100, interval=0.05):
|
2023-04-06 22:55:24 +02:00
|
|
|
"""
|
|
|
|
"""
|
|
|
|
data = []
|
2023-04-07 18:14:15 +02:00
|
|
|
for _ in range(1000):
|
|
|
|
data.append(tuple(float(v) for v in instr.query("print(smua.measure.v())").strip('\n').split('\t')))
|
2023-04-06 22:55:24 +02:00
|
|
|
# print(i, data[-1])
|
|
|
|
# clear_output(wait=True)
|
|
|
|
plt.plot(data)
|
|
|
|
plt.show()
|
|
|
|
sleep(0.05)
|
|
|
|
|
2023-04-13 11:09:40 +02:00
|
|
|
def reset(instr, verbose=False):
|
|
|
|
"""
|
|
|
|
Reset smua and its buffers
|
|
|
|
@param instr : pyvisa instrument
|
|
|
|
"""
|
2023-04-07 18:14:15 +02:00
|
|
|
run_lua(instr, scripts["smua_reset"], verbose=verbose)
|
|
|
|
run_lua(instr, scripts["buffer_reset"], verbose=verbose)
|
|
|
|
|
|
|
|
|
|
|
|
def measure_count(instr, V=True, I=True, count=100, interval=0.05, beep_done=True, verbose=True):
|
|
|
|
"""
|
|
|
|
take n measurements at dt interval
|
2023-04-13 11:09:40 +02:00
|
|
|
@param instr : pyvisa instrument
|
2023-04-07 18:14:15 +02:00
|
|
|
"""
|
2023-04-13 11:09:40 +02:00
|
|
|
reset(instr, verbose=verbose)
|
2023-04-07 18:14:15 +02:00
|
|
|
f_meas = None
|
|
|
|
if V and I:
|
|
|
|
f_meas = "smua.measure.iv(smua.nvbuffer1, smua.nvbuffer2)"
|
|
|
|
elif V:
|
|
|
|
f_meas = "smua.measure.v(smua.nvbuffer1)"
|
|
|
|
elif I:
|
|
|
|
f_meas = "smua.measure.i(smua.nvbuffer1)"
|
|
|
|
else:
|
|
|
|
print("I and/or V needs to be set to True")
|
|
|
|
return
|
|
|
|
|
|
|
|
instr.write(f"smua.measure.count = {count}")
|
|
|
|
instr.write(f"smua.measure.interval = {interval}")
|
|
|
|
|
|
|
|
instr.write(f"smua.source.output = smua.OUTPUT_ON")
|
|
|
|
instr.write(f_meas)
|
|
|
|
instr.write(f"smua.source.output = smua.OUTPUT_OFF")
|
|
|
|
|
|
|
|
if beep_done:
|
|
|
|
instr.write("beeper.beep(0.3, 1000)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def event_test_TODO():
|
|
|
|
# Type of event we want to be notified about
|
|
|
|
event_type = pyvisa.constants.EventType.service_request
|
|
|
|
# Mechanism by which we want to be notified
|
|
|
|
event_mech = pyvisa.constants.EventMechanism.queue
|
|
|
|
keithley.enable_event(event_type, event_mech)
|
|
|
|
|
|
|
|
# Instrument specific code to enable service request
|
|
|
|
# (for example on operation complete OPC)
|
|
|
|
keithley.write("*SRE 1")
|
|
|
|
keithley.write("INIT")
|
|
|
|
|
|
|
|
|
|
|
|
with open("script.lua", "r") as file:
|
|
|
|
script = file.read()
|
|
|
|
# for line in script.split('\n'):
|
|
|
|
# input(line)
|
|
|
|
# keithley.write(line)
|
|
|
|
keithley.write(script)
|
|
|
|
|
|
|
|
# Wait for the event to occur
|
|
|
|
response = keithley.wait_on_event(event_type, 1000)
|
|
|
|
assert response.event.event_type == event_type
|
|
|
|
assert response.timed_out == False
|
|
|
|
|
|
|
|
instr.disable_event(event_type, event_mech)
|
|
|
|
keithley.query_ascii_values("printbuffer(1, 10, smua.nvbuffer1)", 6)
|
|
|
|
print(voltages)
|