edited lockin (SR)

Change-Id: I66d95144d61c62a2396933c2f9a7ce6e05917fe4
This commit is contained in:
Oksana Shliakhtun 2023-05-31 17:25:00 +02:00
parent 11d1ad546f
commit da122ad961

View File

@ -21,7 +21,7 @@
"""Signal Recovery SR7270: lockin amplifier for AC susceptibility"""
from frappy.core import Readable, Parameter, FloatRange, TupleOf, \
HasIO, StringIO, IntRange, BoolType, Writable, EnumType
HasIO, StringIO, BoolType, EnumType
from frappy.errors import RangeError
@ -42,8 +42,7 @@ class XY(HasIO, Readable):
autosen_on = Parameter('is auto sensitivity on', BoolType(), readonly=False)
noise_control = Parameter('is noise control mode on', BoolType(), readonly=False)
phase = Parameter('reference phase control', FloatRange(-360, 360), unit='deg', readonly=False)
frequency = Parameter('oscill. frequen. control', FloatRange(0.001, 250e3), unit='Hz', readonly=False,
group='frequency')
frequency = Parameter('oscill. frequen. control', FloatRange(0.001, 250e3), unit='Hz', readonly=False)
amplitude = Parameter('oscill. amplit. control', FloatRange(0.00, 5), unit='V_rms', readonly=False)
#filter = Parameter('line frequency filter', unit='Hz')
@ -70,29 +69,23 @@ class XY(HasIO, Readable):
c_diff = None # closets difference
for index, value in value_dict.items():
if c_diff is None or diff < c_diff:
if c_diff is None or abs(new_value - value) < c_diff:
c_ind = index
c_diff = c_diff
c_diff = abs(new_value - value)
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):
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_vmode(self):
return self.comm('VMODE')
return int(self.comm('VMODE'))
def write_vmode(self, vmode):
self.comm(f'IMODE {0}')
@ -102,10 +95,12 @@ class XY(HasIO, Readable):
return self.comm('AUTOMATIC')
def write_autosen_on(self, autosen_on):
return self.comm(f'AUTOMATIC {autosen_on}')
autosen_on_str = '1' if autosen_on else '0'
self.comm(f'AUTOMATIC {autosen_on_str}')
return self.read_autosen_on()
def read_irange(self):
return self.comm('SEN')
return int(self.comm('SEN'))
def write_irange(self, irange):
self.comm(f'IMODE {0}')
@ -114,7 +109,8 @@ class XY(HasIO, Readable):
return irange
def read_range(self):
return self.comm('SEN.') # range value
reply = self.comm('SEN.') # range value
return float(reply)
def write_range(self):
self.comm(f'IMODE 0')
@ -130,26 +126,27 @@ class XY(HasIO, Readable):
return self.comm(f'NOISEMODE {noise_control}')
def read_tc(self):
return self.comm('TC.')
reply = self.comm('TC.')
return float(reply)
def write_tc(self):
pass
def read_itc(self):
return self.comm('TC')
return int(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 abs(curr_value - new_value) < c_ind:
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):
reply = self.comm('XY.').split(b',')
reply = self.comm('XY.').split(',')
x = float(reply[0])
y = float(reply[1])
return x, y
@ -158,21 +155,22 @@ class XY(HasIO, Readable):
return self.comm(f'XY {value}')
def read_frequency(self):
return self.comm('OF.')
return float(self.comm('OF.'))
def write_frequency(self, frequency):
frequency = self.frequency
return self.comm(f'OF. {frequency}')
def read_amplitude(self):
return self.comm('OA.')
return float(self.comm('OA.'))
def write_amplitude(self, amplitude):
return self.comm(f'OA. {amplitude}')
self.comm(f'OA. {amplitude}')
return self.read_amplitude()
# phase and autophase
def read_phase(self):
return self.comm('REFP.')
reply = self.comm('REFP.')
return float(reply)
def write_phase(self, value):
self.comm(f'REFP {round(1000 * value)}')