From dc59906c8a21bfe91045f0df9dc52f5067808f45 Mon Sep 17 00:00:00 2001 From: Oksana Shliakhtun Date: Wed, 12 Jul 2023 15:13:35 +0200 Subject: [PATCH] Added tc for the Ametek 7265 Change-Id: Ifd8e55b2da14cb41391f72787cd726951192ec95 --- frappy_psi/SR.py | 180 +++++++++++++++++++++++++++++------------------ 1 file changed, 111 insertions(+), 69 deletions(-) diff --git a/frappy_psi/SR.py b/frappy_psi/SR.py index 5a54736..037d1a4 100644 --- a/frappy_psi/SR.py +++ b/frappy_psi/SR.py @@ -29,7 +29,7 @@ from frappy.errors import RangeError class SR_IO(StringIO): 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 reply = super().communicate(cmd) @@ -39,7 +39,7 @@ class SR_IO(StringIO): class XY(HasIO, Readable): value = Parameter('X, Y', datatype=TupleOf(FloatRange(unit='V'), FloatRange(unit='V'))) - freq = Parameter('oscill. frequen. control', FloatRange(0.001, 250e3), unit='Hz', readonly=False) + freq = Parameter('oscill. frequen. control', FloatRange(0, 250e3), unit='Hz', readonly=False) amp = Parameter('oscill. amplit. control', FloatRange(0.00, 5), unit='V_rms', readonly=False) range = Parameter('sensitivity value', FloatRange(0.00, 1), unit='V', default=1, readonly=False) autorange = Parameter('autorange_on', EnumType('autorange', off=0, soft=1, hard=2), @@ -52,53 +52,37 @@ class XY(HasIO, Readable): )} irange = Parameter('sensitivity index', EnumType('sensitivity index range', sen_range), readonly=False) - - 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'] - )} - - 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) nm = Parameter('noise mode on', BoolType(), readonly=False) phase = Parameter('reference phase control', FloatRange(-360, 360), unit='deg', readonly=False) vmode = Parameter('control mode', EnumType(both_grounded=0, A=1, B=2, A_B_diff=3), readonly=False) - # filter = Parameter('line frequency filter', unit='Hz') - # dac = Parameter('output DAC channel value', datatype=TupleOf(IntRange(1, 4), FloatRange(0.0, 5000, unit='mV')), - # readonly=False, initwrite=True, default=(3,0)) - # dac = Parameter('output DAC channel value', FloatRange(-10000, 10000, unit='mV'), - # readonly=False, initwrite=True, default=0) 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 read_status(self): + pass 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': self.status = (self.Status.WARN, f'overload {overload}') self.status = (self.Status.IDLE, '') return reply - 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 abs(new_value - value) < c_diff: - c_ind = index - c_diff = abs(new_value - value) - - if abs(curr_value - new_value) < c_diff: - return c_ind + def string_to_value(self, value): + """ + This method is used for writing methods (sensitivity range and time constant in particular). As the dictionaries + with names were used (pop-up list in gui) this method transforms names into float values, that can be used + further. + :param value: + :return: + """ + 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 read_value(self): reply = self.comm('XY.').split(',') @@ -158,14 +142,13 @@ class XY(HasIO, Readable): def write_range(self, target): cl_idx = None - cl_diff = float('inf') for name, idx in self.sen_range.items(): value = self.string_to_value(name) - diff = abs(value - target) - if diff < cl_diff: + if value < target < self.sen_range.get(idx + 1, float('inf')): + cl_idx = idx + 1 + elif value == target: cl_idx = idx - cl_diff = diff self.write_irange(cl_idx) return self.read_range() @@ -178,36 +161,6 @@ class XY(HasIO, Readable): 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: - 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): - return int(self.comm('TC')) - - def write_itc(self, itc): - value = int(itc) - self.comm(f'TC {value}') - self.read_tc() - return value - # phase and autophase def read_phase(self): reply = self.comm('REFP.') @@ -230,3 +183,92 @@ class XY(HasIO, Readable): 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'] + )} + + 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 = SR_IO + + 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_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'] + )} + + 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