temporary state at PPMS as of 2024-01-26

This commit is contained in:
l_samenv 2024-01-29 08:29:25 +01:00
parent 416cdd5a88
commit a930dc8f6a
6 changed files with 311 additions and 124 deletions

View File

@ -1,5 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ***************************************************************************** # *****************************************************************************
# This program is free software; you can redistribute it and/or modify it under # This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software # the terms of the GNU General Public License as published by the Free Software
@ -16,18 +14,47 @@
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
# Module authors: # Module authors:
# Daniel Margineda <daniel.margineda@psi.ch>, Oksana Shliakhtun <oksana.shliakhtun@psi.ch> # Daniel Margineda <daniel.margineda@psi.ch>
# Oksana Shliakhtun <oksana.shliakhtun@psi.ch>
# ***************************************************************************** # *****************************************************************************
"""Signal Recovery SR7270: lockin amplifier for AC susceptibility""" """Signal Recovery SR7270: lockin amplifier for AC susceptibility"""
import re
from frappy.core import Readable, Parameter, FloatRange, TupleOf, \ from frappy.core import Readable, Parameter, FloatRange, TupleOf, \
HasIO, StringIO, IntRange, BoolType, Writable, EnumType HasIO, StringIO, BoolType, EnumType
from frappy.errors import RangeError from frappy.errors import RangeError
class SR_IO(StringIO): class IO65(StringIO):
identification = [('ID', r'72.*')] # Identification; causes the lock-in amplifier to respond with the model number
# special protocol: we have to wait for each echo charavter
def communicate(self, cmd):
self.comLog('> %s', cmd)
cmd = cmd + '\r'
for ch in cmd.encode('latin-1'):
self._conn.send(bytes([ch]))
echo = self._conn.recv()
if not echo:
raise RuntimeError('tmo')
if echo[0] == 13: # CR
data = echo[1:]
break
else:
raise RuntimeError('missing CR')
while True:
chunk = self._conn.recv()
data += chunk
if not chunk or chunk[-1] == 13:
break
reply = data.decode('latin-1')
self.comLog('< %s', reply)
return reply+';0;0' # make it compatible with IO70
class IO70(StringIO):
end_of_line = b'\x00' end_of_line = b'\x00'
identification = [('ID', r'.*')] # Identification; causes the lock-in amplifier to respond with the number 7270 identification = [('ID', r'72.*')] # Identification; causes the lock-in amplifier to respond with the model number
def communicate(self, cmd): # remove dash from terminator def communicate(self, cmd): # remove dash from terminator
reply = super().communicate(cmd) reply = super().communicate(cmd)
@ -37,15 +64,11 @@ class SR_IO(StringIO):
class XY(HasIO, Readable): class XY(HasIO, Readable):
value = Parameter('X, Y', datatype=TupleOf(FloatRange(unit='V'), FloatRange(unit='V'))) value = Parameter('X, Y', datatype=TupleOf(FloatRange(unit='V'), FloatRange(unit='V')))
vmode = Parameter('control mode', EnumType(both_grounded=0, A=1, B=2, A_B_diff=3), readonly=False) freq = Parameter('oscill. frequen. control', FloatRange(0, 250e3), unit='Hz', readonly=False)
range = Parameter('sensitivity value', FloatRange(0.00, 1), unit='V', default=1) amp = Parameter('oscill. amplit. control', FloatRange(0.00, 5), unit='V_rms', readonly=False)
autosen_on = Parameter('is auto sensitivity on', BoolType(), readonly=False) range = Parameter('sensitivity value', FloatRange(0.00, 1), unit='V', default=1, readonly=False)
noise_control = Parameter('is noise control mode on', BoolType(), readonly=False) autorange = Parameter('autorange_on', EnumType('autorange', off=0, soft=1, hard=2),
phase = Parameter('reference phase control', FloatRange(-360, 360), unit='deg', readonly=False) readonly=False, default=0)
frequency = Parameter('oscill. frequen. control', FloatRange(0.001, 250e3), unit='Hz', readonly=False,
group='frequency')
amplitude = Parameter('oscill. amplit. control', FloatRange(0.00, 5), unit='V_rms', readonly=False)
#filter = Parameter('line frequency filter', unit='Hz')
sen_range = {name: value + 1 for value, name in enumerate( sen_range = {name: value + 1 for value, name in enumerate(
['2nV', '5nV', '10nV', '20nV', '50nV', '100nV', '200nV', '500nV', '1uV', ['2nV', '5nV', '10nV', '20nV', '50nV', '100nV', '200nV', '500nV', '1uV',
@ -54,125 +77,104 @@ class XY(HasIO, Readable):
)} )}
irange = Parameter('sensitivity index', EnumType('sensitivity index range', sen_range), readonly=False) irange = Parameter('sensitivity index', EnumType('sensitivity index range', sen_range), readonly=False)
phase = Parameter('reference phase control', FloatRange(-360, 360), unit='deg', readonly=False)
time_const = {name: value for value, name in enumerate( vmode = Parameter('control mode', EnumType(both_grounded=0, A=1, B=2, A_B_diff=3), readonly=False)
['10us', '20us', '50us', '100us', '200us', '500us', '1ms', '2ms', '5ms', '10ms',
'20ms', '50ms', '100ms', '200ms', '500ms', '1s', '2s', '5s', '10s', '20s', '50s',
'100s', '200s', '500s', '1ks', '10ks', '20ks', '50ks', '100ks']
)}
tc = Parameter('time const. value', FloatRange(0.00005, 100000), unit='s', readonly=False)
itc = Parameter('time const. index', EnumType('time const. index range', time_const), readonly=False)
ioClass = SR_IO
def comparison(self, curr_value, new_value, value_dict):
c_ind = None # closest index
c_diff = None # closets difference
for index, value in value_dict.items():
if c_diff is None or diff < c_diff:
c_ind = index
c_diff = c_diff
if abs(curr_value - new_value) < c_diff:
return c_ind
else:
for index, value in value_dict.items():
diff = abs(new_value - value)
if c_diff is None or diff < c_diff:
c_ind = index
c_diff = diff
return c_ind
def comm(self, cmd): def comm(self, cmd):
reply, status, overload = self.communicate(cmd).split(';') reply, status, overload = self.communicate(cmd).split(';') # try/except
reply = reply.rstrip('\n')
if overload != '0': if overload != '0':
self.status = (self.Status.WARN, f'overload {overload}') self.status = (self.Status.WARN, f'overload {overload}')
self.status = (self.Status.IDLE, '') self.status = (self.Status.IDLE, '')
return reply return reply
def read_vmode(self): def string_to_value(self, value):
return self.comm('VMODE') """
This method is used for writing methods (sensitivity range and time constant in particular). As the dictionaries
def write_vmode(self, vmode): with names were used (pop-up list in gui) this method transforms names into float values, that can be used
self.comm(f'IMODE {0}') further.
return self.comm(f'VMODE {vmode}') :param value:
:return:
def read_autosen_on(self): """
return self.comm('AUTOMATIC') value_with_unit = re.compile(r'(\d+)([pnumkMG]?)')
value, pfx = value_with_unit.match(value).groups()
def write_autosen_on(self, autosen_on): pfx_dict = {'p': 1e-12, 'n': 1e-9, 'u': 1e-6, 'm': 1e-3, 'k': 1e3, 'M': 1e6, 'G':1e9}
return self.comm(f'AUTOMATIC {autosen_on}') if pfx in pfx_dict:
value = round(float(value) * pfx_dict[pfx], 12)
def read_irange(self): return float(value)
return self.comm('SEN')
def write_irange(self, irange):
self.comm(f'IMODE {0}')
self.comm(f'SEN {irange}')
self.read_range()
return irange
def read_range(self):
return self.comm('SEN.') # range value
def write_range(self):
self.comm(f'IMODE 0')
curr_value = self.read_range()
new_value = self.value
c_ind = self.comparison(curr_value, new_value, self.sen_range)
return self.comm(f'SEN {c_ind}')
def read_noise_control(self):
return self.comm('NOISEMODE')
def write_noise_control(self, noise_control):
return self.comm(f'NOISEMODE {noise_control}')
def read_tc(self):
return self.comm('TC.')
def write_tc(self):
pass
def read_itc(self):
return self.comm('TC')
def write_itc(self, new_itc):
curr_value = self.read_itc()
new_value = self.time_const[self.itc]
c_ind = self.comparison(curr_value, new_value, self.time_const)
if abs(curr_value - new_value) < c_diff:
if self.read_noise_control() == 1 and (5e-4 <= self.time_const[new_itc] <= 1e-2):
raise RangeError('not allowed with noisemode=1')
return self.comm(f'TC {new_itc}')
def read_value(self): def read_value(self):
reply = self.comm('XY.').split(b',') reply = self.comm('XY.').split(',')
x = float(reply[0]) x = float(reply[0])
y = float(reply[1]) y = float(reply[1])
if self.autorange == 1: # soft
if max(abs(x), abs(y)) >= 0.9 * self.range and self.irange < 27:
self.write_irange(self.irange + 1)
elif max(abs(x), abs(y)) <= 0.3 * self.range and self.irange > 1:
self.write_irange(self.irange - 1)
return x, y return x, y
def write_value(self, value): def read_freq(self):
return self.comm(f'XY {value}') return float(self.comm('OF.'))
def read_frequency(self): def write_freq(self, freq):
return self.comm('OF.') self.comm(f'OF. {freq}')
return freq
def write_frequency(self, frequency): def read_autorange(self):
frequency = self.frequency reply = self.comm('AUTOMATIC')
return self.comm(f'OF. {frequency}') # determine hardware autorange
if reply == 1: # soft
return 2 # hard
if self.autorange == 0: # soft
return self.autorange # read autorange
return self.autorange # off
def read_amplitude(self): def write_autorange(self, value):
return self.comm('OA.') if value == 2: # hard
self.comm('AS') # put hardware autorange on
self.comm('AUTOMATIC. 1')
else:
self.comm('AUTOMATIC. 0')
return value
def write_amplitude(self, amplitude): def read_amp(self):
return self.comm(f'OA. {amplitude}') return float(self.comm('OA.'))
def write_amp(self, amp):
self.comm(f'OA. {amp}')
return amp
def read_irange(self):
reply = self.comm('SEN')
return int(reply)
def write_irange(self, irange):
value = int(irange)
self.comm(f'SEN {value}')
self.read_range()
return value
def read_range(self):
reply = self.comm('SEN.') # range value
return float(reply)
def write_range(self, target):
cl_idx = None
for name, idx in self.sen_range.items():
value = self.string_to_value(name)
if value < target < self.sen_range.get(idx + 1, float('inf')):
cl_idx = idx + 1
elif value == target:
cl_idx = idx
self.write_irange(cl_idx)
return self.read_range()
# phase and autophase # phase and autophase
def read_phase(self): def read_phase(self):
return self.comm('REFP.') reply = self.comm('REFP.')
return float(reply)
def write_phase(self, value): def write_phase(self, value):
self.comm(f'REFP {round(1000 * value)}') self.comm(f'REFP {round(1000 * value)}')
@ -182,3 +184,113 @@ class XY(HasIO, Readable):
"""auto phase""" """auto phase"""
self.read_phase() self.read_phase()
return self.comm('AQN') return self.comm('AQN')
def read_vmode(self):
reply = self.comm('VMODE')
return int(reply)
def write_vmode(self, vmode):
value = int(vmode)
self.comm(f'VMODE {value}')
return value
class XY70(XY):
time_const = {name: value for value, name in enumerate(
['10us', '20us', '50us', '100us', '200us', '500us', '1ms', '2ms', '5ms', '10ms',
'20ms', '50ms', '100ms', '200ms', '500ms', '1s', '2s', '5s', '10s', '20s', '50s',
'100s', '200s', '500s', '1ks', '2ks', '5ks', '10ks', '20ks', '50ks', '100ks']
)}
nm = Parameter('noise mode on', BoolType(), readonly=False)
tc = Parameter('time const. value', FloatRange(0.00001, 100000), unit='s', readonly=False)
itc = Parameter('time const. index', EnumType('time const. index range', time_const), readonly=False)
ioClass = IO70
def comm(self, cmd):
reply, status, overload = self.communicate(cmd).split(';')
reply = reply.rstrip('\n')
if overload != '0':
self.status = (self.Status.WARN, f'overload {overload}')
self.status = (self.Status.IDLE, '')
return reply
def read_nm(self):
reply = self.comm('NOISEMODE')
return reply
def write_nm(self, value):
self.comm('NOISEMODE %d' % int(value))
self.read_nm()
return value
def read_tc(self):
reply = self.comm('TC.')
return float(reply)
def write_tc(self, target):
cl_idx = None
cl_diff = float('inf')
for name, idx in self.time_const.items():
value = self.string_to_value(name)
diff = abs(value - target) # range is the actual value, like SEN.
if diff < cl_diff:
cl_idx = idx
cl_diff = diff
if self.nm is False or (self.nm is True and 5 <= cl_idx <= 9):
self.comm(f'TC {cl_idx}')
return self.read_tc()
raise RangeError('Not allowed with noisemode=1')
def read_itc(self):
return int(self.comm('TC'))
def write_itc(self, itc):
value = int(itc)
self.comm(f'TC {value}')
self.read_tc()
return value
class XY65(XY):
time_const = {name: value for value, name in enumerate(
['10us', '20us', '40us', '80us', '160us', '320us', '640us', '5ms', '10ms', '20ms',
'50ms', '100ms', '200ms', '500ms', '1s', '2s', '5s', '10s', '20s', '50s', '100s',
'200s', '500s', '1ks', '2ks', '5ks', '10ks', '20ks', '50ks', '100ks']
)}
ioClass = IO65
def read_tc(self):
reply = self.comm('TC.')
return float(reply)
def write_tc(self, target):
cl_idx = None
cl_diff = float('inf')
for name, idx in self.time_const.items():
value = self.string_to_value(name)
diff = abs(value - target) # range is the actual value, like SEN.
if diff < cl_diff:
cl_idx = idx
cl_diff = diff
if self.nm is False or (self.nm is True and 5 <= cl_idx <= 9):
self.comm(f'TC {cl_idx}')
return self.read_tc()
raise RangeError('Not allowed with noisemode=1')
def read_itc(self):
return int(self.comm('TC'))
def write_itc(self, itc):
value = int(itc)
self.comm(f'TC {value}')
self.read_tc()
return value

View File

@ -53,17 +53,17 @@ class Capacitance(HasIO, Readable):
# split() ignores multiple white space # split() ignores multiple white space
reply = reply.replace('=', '= ').replace('>', '> ').split() reply = reply.replace('=', '= ').replace('>', '> ').split()
_, freq, _, _, cap, _, _, loss, lossunit, _, volt = reply[:11] _, freq, _, _, cap, _, _, loss, lossunit, _, volt = reply[:11]
self.freq = freq self.freq = float(freq)
self.voltage = volt self.voltage = float(volt)
if lossunit == 'DS': if lossunit == 'DS':
self.loss = loss self.loss = float(loss)
else: # the unit was wrong, we want DS = tan(delta), not NS = nanoSiemens else: # the unit was wrong, we want DS = tan(delta), not NS = nanoSiemens
reply = self.communicate('UN DS').split() # UN DS returns a reply similar to SI reply = self.communicate('UN DS').split() # UN DS returns a reply similar to SI
try: try:
self.loss = reply[7] self.loss = float(reply[7])
except IndexError: except IndexError:
pass # don't worry, loss will be updated next time pass # don't worry, loss will be updated next time
return cap return float(cap)
def read_value(self): def read_value(self):
return self.parse_reply(self.communicate('SI')) # SI = single trigger return self.parse_reply(self.communicate('SI')) # SI = single trigger

View File

@ -124,6 +124,7 @@ class Switcher(LakeShoreIO, ChannelSwitcher):
raise ValueError('no channels enabled') raise ValueError('no channels enabled')
self.write_target(channelno) self.write_target(channelno)
chan = self.channels.get(self.value) chan = self.channels.get(self.value)
self.value = channelno
chan.read_autorange() chan.read_autorange()
chan.fix_autorange() # check for toggled autorange button chan.fix_autorange() # check for toggled autorange button
return Done return Done
@ -228,7 +229,7 @@ class ResChannel(LakeShoreIO, Channel):
now = time.monotonic() now = time.monotonic()
if now + 0.5 < max(self._last_range_change, self.switcher._start_switch) + self.pause: if now + 0.5 < max(self._last_range_change, self.switcher._start_switch) + self.pause:
return None return None
result = self.get_param(f'RDGR{self.channel}') result = self.get_param(f'RDGR?{self.channel}')
if self.autorange: if self.autorange:
self.fix_autorange() self.fix_autorange()
if now + 0.5 > self._last_range_change + self.pause: if now + 0.5 > self._last_range_change + self.pause:
@ -252,7 +253,7 @@ class ResChannel(LakeShoreIO, Channel):
def read_value(self): def read_value(self):
if self.channel == self.switcher.value == self.switcher.target: if self.channel == self.switcher.value == self.switcher.target:
value = self._read_value() value = self.get_value()
if value is not None: if value is not None:
return value return value
return self.value # return previous value return self.value # return previous value
@ -265,7 +266,7 @@ class ResChannel(LakeShoreIO, Channel):
@CommonReadHandler(rdgrng_params) @CommonReadHandler(rdgrng_params)
def read_rdgrng(self): def read_rdgrng(self):
iscur, exc, rng, autorange, excoff = self.get_param(f'RDGRNG{self.channel}') iscur, exc, rng, autorange, excoff = self.get_param(f'RDGRNG?{self.channel}')
self._prev_rdgrng = iscur, exc self._prev_rdgrng = iscur, exc
if autorange: # pressed autorange button if autorange: # pressed autorange button
if not self._toggle_autorange: if not self._toggle_autorange:

View File

@ -22,8 +22,9 @@
"""modules to access parameters""" """modules to access parameters"""
from frappy.core import Drivable, EnumType, IDLE, Attached, StringType, Property, \ import re
Parameter, FloatRange, Readable, ERROR from frappy.core import Drivable, IDLE, Attached, StringType, Property, \
Parameter, FloatRange, Readable, EnumType
from frappy.errors import ConfigError from frappy.errors import ConfigError
from frappy_psi.convergence import HasConvergence from frappy_psi.convergence import HasConvergence
from frappy_psi.mixins import HasRamp from frappy_psi.mixins import HasRamp
@ -53,6 +54,42 @@ class Par(Readable):
def read_status(self): def read_status(self):
return IDLE, '' return IDLE, ''
INDEX = re.compile(r'(.*)\[(.*)\]')
class Comp(Readable):
value = Parameter(datatype=FloatRange(unit='$'))
read = Attached(description='<module>.<parameter> for read')
unit = Property('main unit', StringType())
_parname = None
_index = None
def setProperty(self, key, value):
if key == 'read':
value, param = value.split('.')
match = INDEX.match(param)
if match:
self._param, i = match.groups()
self._index = int(i)
else:
self._param = param
super().setProperty(key, value)
def checkProperties(self):
self.applyMainUnit(self.unit)
if self._param == self.name:
raise ConfigError('illegal recursive read module')
super().checkProperties()
def read_value(self):
par = getattr(self.read, self._param)
if self._index is None:
return par
return par[self._index]
def read_status(self):
return IDLE, ''
class Driv(Drivable): class Driv(Drivable):
value = Parameter(datatype=FloatRange(unit='$')) value = Parameter(datatype=FloatRange(unit='$'))

View File

@ -147,6 +147,7 @@ class CalCurve:
with open(filename, encoding='utf-8') as f: with open(filename, encoding='utf-8') as f:
for line in f: for line in f:
parser.parse(line) parser.parse(line)
print(f'FOUND {filename}')
except Exception as e: except Exception as e:
raise ValueError(f'calib curve {calibspec}: {e}') from e raise ValueError(f'calib curve {calibspec}: {e}') from e
self.convert_x = nplog if parser.logx else linear self.convert_x = nplog if parser.logx else linear

36
frappy_psi/srs830.py Normal file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# *****************************************************************************
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Module authors:
# Daniel Margineda <daniel.margineda@psi.ch>, Oksana Shliakhtun <oksana.shliakhtun@psi.ch>
# *****************************************************************************
"""Stanford Research SR830"""
from frappy.core import Readable, Parameter, FloatRange, TupleOf, \
HasIO, StringIO, IntRange, BoolType, Writable, EnumType
from frappy.errors import RangeError
class XY(HasIO, Readable):
value = Parameter('xy', TupleOf(FloatRange(unit='V'), FloatRange(unit='V')))
class ioClass(StringIO):
end_of_line = '\r'
identification = [('*IDN?', r'Stanford_Research_Systems,SR830.*')]
def read_value(self):
return [float(v) for v in self.communicate('SNAP?1,2').split(',')]