Added documentation

Change-Id: Id6e26a4c28fe080a55099cd54d0fa85c15946657
This commit is contained in:
Oksana Shliakhtun
2024-08-19 17:21:40 +02:00
committed by Markus Zolliker
parent c1403763f4
commit f0eb7d95f1
3 changed files with 84 additions and 2 deletions

View File

@ -15,7 +15,7 @@
#
# Module authors: Oksana Shliakhtun <oksana.shliakhtun@psi.ch>
# *****************************************************************************
"""Stanford Research Systems SIM900 Mainframe"""
import re
from frappy.core import StringIO, HasIO, Readable, \
@ -24,6 +24,11 @@ from frappy.core import StringIO, HasIO, Readable, \
def string_to_value(value):
"""
Converting the value to float, removing the units, converting the prefix into the number.
:param value: value
:return: float value without units
"""
value_with_unit = re.compile(r'(\d+)([pnumkMG]?)')
value, pfx = value_with_unit.match(value).groups()
pfx_dict = {'p': 1e-12, 'n': 1e-9, 'u': 1e-6, 'm': 1e-3, 'k': 1e3, 'M': 1e6, 'G': 1e9}
@ -33,6 +38,12 @@ def string_to_value(value):
def find_idx(list_of_values, target):
"""
Search for the nearest value and index from the given range for the given target.
:param list_of_values: range of values
:param target: target
:return: closest index and closest value
"""
target = float(target)
cl_idx = None
cl_value = float('inf')
@ -49,6 +60,9 @@ def find_idx(list_of_values, target):
class BridgeIO(StringIO):
"""_\n is placed at the beginning of each command to distinguish
the previous response with a possible asynchronous response from the actual value returned by the method. """
end_of_line = '\n'
identification = [('_\n*IDN?', r'Stanford_Research_Systems,.*')]
@ -57,9 +71,15 @@ class Base(HasIO):
port = Property('modules port', IntRange(0, 15))
def communicate(self, command):
"""
Connection to the particular module x.
:param command: command
:return: return
"""
return self.io.communicate(f'_\nconn {self.port:x},"_\n"\n{command}')
def query(self, command):
"""converting to float"""
return float(self.communicate(command))
@ -142,6 +162,7 @@ class Resistance(Base, Readable):
return self.query('rval?')
def read_irange(self):
"""index of the resistance value according to the range"""
return self.query('rang?')
def write_irange(self, idx):
@ -151,6 +172,7 @@ class Resistance(Base, Readable):
return value
def read_range(self):
"""value of the resistance range"""
idx = self.read_irange()
name = self.RES_RANGE[idx]
return string_to_value(name)
@ -161,12 +183,14 @@ class Resistance(Base, Readable):
return cl_value
def read_output_offset(self):
"""Output offset, can be set by user. This is the value subtracted from the measured value"""
return self.query('rset?')
def write_output_offset(self, output_offset):
self.query(f'rset {output_offset};rset?')
def read_itc(self):
"""index of the temperature constant value according to the range"""
return self.query('tcon?')
def write_itc(self, itc):
@ -192,6 +216,7 @@ class Resistance(Base, Readable):
return value
def read_iexct(self):
"""index of the excitation value according to the range"""
return int(self.query('exci?'))
def write_iexct(self, iexct):
@ -221,6 +246,10 @@ class Resistance(Base, Readable):
return string_to_value(name)
def read_phase_hold(self):
"""
Set the phase hold mode (if on - phase is assumed to be zero).
:return: 0 - off, 1 - on
"""
return int(self.communicate('phld?'))
def write_phase_hold(self, phase_hold):