diff --git a/cfg/sim921_cfg.py b/cfg/sim921_cfg.py index df7f043..ff01227 100644 --- a/cfg/sim921_cfg.py +++ b/cfg/sim921_cfg.py @@ -1,32 +1,33 @@ Node('bridge.psi.ch', 'ac resistance bridge', - 'tcp://5000' + 'tcp://5000', ) Mod('io', 'frappy_psi.bridge.BridgeIO', 'communication to sim900', - uri='serial:///dev/cu.usbserial-21440' + uri='serial:///dev/cu.usbserial-14440', ) -# Mod('SIM921_A', -# 'frappy_psi.bridge.SIM921', -# 'module communication', -# io='io', -# channel='A' -# ) +Mod('Resistance_1', + 'frappy_psi.bridge.SIM921', + 'module communication', + io='io', + port=1, + # channel='A' + ) -# Mod('SIM921_B', -# 'frappy_psi.bridge.SIM921', -# 'module communication', -# io='io', -# channel='B' -# ) -# -# Mod('SIM921_C', -# 'frappy_psi.bridge.SIM921', -# 'module communication', -# io='io', -# channel='C' -# ) +Mod('Resistance_2', + 'frappy_psi.bridge.SIM921', + 'module communication', + io='io', + port=3, + ) + +Mod('Resistance_3', + 'frappy_psi.bridge.SIM921', + 'module communication', + io='io', + port=5, + ) diff --git a/frappy_psi/bridge.py b/frappy_psi/bridge.py index f1b28ec..71c6c90 100644 --- a/frappy_psi/bridge.py +++ b/frappy_psi/bridge.py @@ -16,98 +16,91 @@ # Module authors: Oksana Shliakhtun # ***************************************************************************** +import time import re -from frappy.core import HasIO, Readable, Drivable, Parameter, FloatRange, IntRange, EnumType, \ +from frappy.core import StringIO, HasIO, Readable, Drivable, \ + Parameter, FloatRange, IntRange, EnumType, \ Enum, Property, StringType -from SR830 import string_to_value +# 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 BridgeIO(StringIO): + end_of_line = ('\r\n', '') # read terminator / rmpty write terminator + identification = [('*IDN?\r\n', r'Stanford_Research_Systems,.*'), + ('RPER 510\r\nRPER?\r\n', '510')] -class SIM921(BridgeIO, Readable, Drivable): - channel = Property('sim921 module', StringType()) +class Base(HasIO): + port = Property('modules port', IntRange(0, 15)) + + def command(self, command, replylines=1): + with self._lock: + reply = super().communicate(f'sndt {self.port:x}, "{command}"\r\n') + for _ in range(replylines-1): + super().communicate('') + head, tail = reply.split('#', 1) + assert head[:5] == f'MSG {self.port:x},' + return tail[tail[1:int(tail[0])+1]:] + + +class SIM921(Base, 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()) + dev = Parameter('resistance deviation', FloatRange()) RES_RANGE = ['20mOhm', '200mOhm', '2Ohm', '20Ohm', '200Ohm', '2kOhm', '20kOhm', '200kOhm', '2MOhm', '20MOhm'] + TIME_CONST = ['0.3s', '1s', '3s', '10s', '30s', '100s', '300s'] + + EXCT_RANGE = ['0', '3uV', '10uV', '30uV', '100uV', '300uV', '1mV', '3mV', '10mV', '30mV'] + 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), + autorange = Parameter('autorange_on', EnumType('autorange', off=0, on=1), readonly=False, default=0) + iexct = Parameter('excitation index', IntRange) + ioClass = BridgeIO def read_value(self): - return self.get_par('rval?') + reply = self.command('rval?', 2) + return reply def read_phase(self): - return self.get_par('phase') + return self.command('phase?', 2) def read_setpoint(self): - return self.get_par('tset') + return self.command('rset?') - def write_setpoint(self, setpoint): - return self.comm(f'tset {setpoint}') + # def write_setpoint(self, setpoint): + # return self.command('rset', setpoint) def read_tc(self): - return self.get_par('tcon') + return self.command('tcon?') - def write_tc(self, tc): - return self.set_par(f'tcon {tc}') + # def write_tc(self, tc): + # return self.command('tcon', tc) def read_dev(self): - return self.comm('rdev?') - - - + return self.command('rdev?') + def read_autorange(self): + return self.command('agai?') + # def write_autorange(self, autorange): + # return self.command('agai', autorange) + def read_iexct(self): + return self.command('exci?') + # def write_iexct(self, iexct): + # return self.command('exci', iexct) \ No newline at end of file