write_range, write_tc, string_to_value method
Change-Id: I6f81db72e852d2670e0a774a621c8382680bb93a
This commit is contained in:
parent
6f6f07b0f9
commit
04940b1a0b
@ -16,10 +16,12 @@
|
|||||||
# 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, BoolType, EnumType
|
HasIO, StringIO, BoolType, EnumType
|
||||||
from frappy.errors import RangeError
|
from frappy.errors import RangeError
|
||||||
@ -57,7 +59,7 @@ class XY(HasIO, Readable):
|
|||||||
'100s', '200s', '500s', '1ks', '2ks', '5ks', '10ks', '20ks', '50ks', '100ks']
|
'100s', '200s', '500s', '1ks', '2ks', '5ks', '10ks', '20ks', '50ks', '100ks']
|
||||||
)}
|
)}
|
||||||
|
|
||||||
tc = Parameter('time const. value', FloatRange(0.00005, 100000), unit='s', 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)
|
itc = Parameter('time const. index', EnumType('time const. index range', time_const), readonly=False)
|
||||||
nm = Parameter('noise mode on', BoolType(), readonly=False)
|
nm = Parameter('noise mode on', BoolType(), readonly=False)
|
||||||
phase = Parameter('reference phase control', FloatRange(-360, 360), unit='deg', readonly=False)
|
phase = Parameter('reference phase control', FloatRange(-360, 360), unit='deg', readonly=False)
|
||||||
@ -70,6 +72,14 @@ class XY(HasIO, Readable):
|
|||||||
|
|
||||||
ioClass = SR_IO
|
ioClass = SR_IO
|
||||||
|
|
||||||
|
def string_to_value(self, value):
|
||||||
|
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}
|
||||||
|
if pfx in pfx_dict:
|
||||||
|
value = round(float(value) * pfx_dict[pfx], 12)
|
||||||
|
return float(value)
|
||||||
|
|
||||||
def comm(self, cmd):
|
def comm(self, cmd):
|
||||||
reply, status, overload = self.communicate(cmd).split(';')
|
reply, status, overload = self.communicate(cmd).split(';')
|
||||||
reply = reply.rstrip('\n')
|
reply = reply.rstrip('\n')
|
||||||
@ -146,22 +156,18 @@ class XY(HasIO, Readable):
|
|||||||
reply = self.comm('SEN.') # range value
|
reply = self.comm('SEN.') # range value
|
||||||
return float(reply)
|
return float(reply)
|
||||||
|
|
||||||
# def write_range(self, val):
|
def write_range(self, target):
|
||||||
# curr_val = self.read_range
|
cl_idx = None
|
||||||
# curr_idx = self.read_irange
|
cl_diff = float('inf')
|
||||||
#
|
|
||||||
# close_val = None
|
for name, idx in self.sen_range.items():
|
||||||
# min_diff = None
|
value = self.string_to_value(name)
|
||||||
#
|
diff = abs(value - target)
|
||||||
# for idx, value in self.sen_range.items():
|
if diff < cl_diff:
|
||||||
# diff = abs(value - val)
|
cl_idx = idx
|
||||||
# close_idx = self.comparison(curr_val, value, self.sen_range)
|
cl_diff = diff
|
||||||
# if close_idx ?:
|
self.write_irange(cl_idx)
|
||||||
# close_val = value
|
return self.read_range()
|
||||||
# close_idx = close_idx
|
|
||||||
# min_diff = abs(curr_val - close_val)
|
|
||||||
#
|
|
||||||
# return self.comm(f'SEN {close_idx}')
|
|
||||||
|
|
||||||
def read_nm(self):
|
def read_nm(self):
|
||||||
reply = self.comm('NOISEMODE')
|
reply = self.comm('NOISEMODE')
|
||||||
@ -176,15 +182,22 @@ class XY(HasIO, Readable):
|
|||||||
reply = self.comm('TC.')
|
reply = self.comm('TC.')
|
||||||
return float(reply)
|
return float(reply)
|
||||||
|
|
||||||
def write_tc(self, new_tc):
|
def write_tc(self, target):
|
||||||
curr_value = self.read_tc()
|
cl_idx = None
|
||||||
new_value = self.time_const[self.itc]
|
cl_diff = float('inf')
|
||||||
c_ind = self.comparison(curr_value, new_value, self.time_const)
|
|
||||||
|
|
||||||
if abs(curr_value - new_value) < c_ind:
|
for name, idx in self.time_const.items():
|
||||||
if self.read_nm() == 1 and (5e-4 <= self.time_const[new_tc] <= 1e-2):
|
value = self.string_to_value(name)
|
||||||
raise RangeError('Not allowed with noisemode=1')
|
diff = abs(value - target) # range is the actual value, like SEN.
|
||||||
return self.comm(f'TC {new_tc}')
|
if diff < cl_diff:
|
||||||
|
cl_idx = idx
|
||||||
|
cl_diff = diff
|
||||||
|
if self.nm:
|
||||||
|
if cl_idx < 5 or cl_idx > 9:
|
||||||
|
idx = self.read_tc()
|
||||||
|
raise RangeError('Not allowed with noisemode=1')
|
||||||
|
self.comm(f'TC {cl_idx}')
|
||||||
|
return self.read_tc()
|
||||||
|
|
||||||
def read_itc(self):
|
def read_itc(self):
|
||||||
return int(self.comm('TC'))
|
return int(self.comm('TC'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user