87 lines
2.4 KiB
Python
87 lines
2.4 KiB
Python
import pyvisa
|
|
from time import sleep
|
|
# import pkg_resources
|
|
import os
|
|
from typing import Callable
|
|
|
|
from ..base import MeasurementDevice
|
|
from ...utility.visa import enumerate_devices
|
|
|
|
import logging
|
|
log = logging.getLogger(__name__)
|
|
|
|
class SR830(MeasurementDevice):
|
|
"""
|
|
Wrapper class for the Keithley2700 SMU controlled via pyvisa
|
|
"""
|
|
def __init__(self, instr, check_front_switch=True):
|
|
self.instr = instr
|
|
init_script = """
|
|
' set input A
|
|
ISRC 0
|
|
' set float
|
|
IGND 0
|
|
' set AC coupling
|
|
ICPL 0
|
|
' Enable 1x and 2x Line notch filters
|
|
ILIN 3
|
|
' Enable synchronous filter < 200Hz
|
|
SYNC 1
|
|
' Show R and Phase on the displays
|
|
DDEF 1 1 0
|
|
DDEF 2 1 0
|
|
' Set sample rate to 256 Hz
|
|
12
|
|
' Set buffer loop mode
|
|
SEND 1
|
|
"""
|
|
self.run(init_script)
|
|
|
|
def __del__(self):
|
|
"""Properly close the instrument connection"""
|
|
self.instr.close()
|
|
|
|
# RUN COMMANDS ON THE DEVICE
|
|
def run(self, code, verbose=False):
|
|
"""
|
|
Run SCPI code on the device by writing it.
|
|
Empty lines, leading whitespaces and lines starting with ' or # are ignored.
|
|
Parameters
|
|
----------
|
|
code : str
|
|
SCPI commands
|
|
"""
|
|
script = ''
|
|
for line in code.strip(" ").split("\n"):
|
|
l = line.strip(" ")
|
|
if len(l) == 0 or l[0] in "#'": continue
|
|
script += l + "\n"
|
|
if verbose:
|
|
print(f"Running code:\n{script}")
|
|
try:
|
|
ret = self.instr.write(script)
|
|
if ret != 8:
|
|
raise RuntimeError(f"Error while writing command(s):\n'{script}'\n\nDevice returned code {ret}")
|
|
except pyvisa.VisaIOError as e:
|
|
raise RuntimeError(f"VisaIOError raised while writing command(s):\n'{script}'\n\nVisaIOError:\n{e}")
|
|
|
|
def get_frequency(self) -> float:
|
|
return float(self.query("FREQ?"))
|
|
|
|
def query(self, query):
|
|
return self.instr.query(query).strip("\n")
|
|
|
|
|
|
@staticmethod
|
|
def enumerate_devices(query="(GPIB)|(USB)?*:INSTR"):
|
|
return enumerate_devices("SR830", query)
|
|
|
|
@staticmethod
|
|
def connect_device(name):
|
|
rm = pyvisa.ResourceManager()
|
|
instr = rm.open_resource(name)
|
|
return SR830(instr)
|
|
|
|
def __str__(self):
|
|
return "SR830"
|