# ***************************************************************************** # 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: Oksana Shliakhtun # ***************************************************************************** import re from frappy.core import HasIO, Readable, Drivable, Parameter, FloatRange, IntRange, EnumType, \ Enum, Property, StringType from SR830 import string_to_value class BridgeIO(HasIO): end_of_line = b'\r' # should be or identification = [('*IDN?', r'Stanford_Research_Systems,.*')] def comm(self, port, cmd): self.communicate(f'conn {port}') return self.communicate(f'send {port}, "{cmd}\r"') # def set_par(self, cmd, *args): # head = ','.join([cmd] + [a if isinstance(a, str) else f'{a:g}' for a in args]) # tail = cmd.replace(' ', '? ') # new_tail = re.sub(r'[0-9.]+', '', tail) # # reply = self.comm(f'{head};{new_tail}') # result = [] # for num in reply.split(','): # try: # result.append(float(num)) # except ValueError: # result.append(num) # if len(result) == 1: # return result[0] # return result # # def get_par(self, cmd): # reply = self.comm(cmd) # result = [] # for num in reply.split(','): # try: # result.append(float(num)) # except ValueError: # result.append(num) # if len(result) == 1: # return result[0] # return result class SIM921(BridgeIO, Readable, Drivable): channel = Property('sim921 module', StringType()) setpoint = Parameter('temperature deviation', datatype=FloatRange, unit='K') value = Parameter('resistance', datatype=FloatRange, unit='ohm') dev = Property('resistance deviation', FloatRange()) RES_RANGE = ['20mOhm', '200mOhm', '2Ohm', '20Ohm', '200Ohm', '2kOhm', '20kOhm', '200kOhm', '2MOhm', '20MOhm'] irange = Parameter('range index', EnumType('resistance range index', {name: idx for idx, name in enumerate(RES_RANGE)}), readonly=False) phase = Parameter('phase', FloatRange, unit='ang') TIME_CONST = ['0.3s', '1s', '3s', '10s', '30s', '100s', '300s'] tc = Parameter('time constant value', FloatRange(1e-1, 3e2), unit='s', readonly=False) itc = Parameter('time constant index', EnumType('time const. index range', {name: value for value, name in enumerate(TIME_CONST)}), readonly=False) autorange = Parameter('autorange_on', EnumType('autorange', off=0, soft=1, hard=2), readonly=False, default=0) ioClass = BridgeIO def read_value(self): return self.get_par('rval?') def read_phase(self): return self.get_par('phase') def read_setpoint(self): return self.get_par('tset') def write_setpoint(self, setpoint): return self.comm(f'tset {setpoint}') def read_tc(self): return self.get_par('tcon') def write_tc(self, tc): return self.set_par(f'tcon {tc}') def read_dev(self): return self.comm('rdev?')