From 41ed82e72ed72ecbd1ac4d46216243ecd79621e6 Mon Sep 17 00:00:00 2001 From: Oksana Shliakhtun Date: Mon, 6 May 2024 11:57:50 +0200 Subject: [PATCH] Driver and cfg file for ac resistance bridge Change-Id: I77b2294b57315fcf7d94996a2a68fcac72866710 --- cfg/SIM921_cfg.py | 32 +++++++++++++ frappy_psi/bridge.py | 104 ++++++++++++++++++++----------------------- 2 files changed, 81 insertions(+), 55 deletions(-) create mode 100644 cfg/SIM921_cfg.py diff --git a/cfg/SIM921_cfg.py b/cfg/SIM921_cfg.py new file mode 100644 index 0000000..df7f043 --- /dev/null +++ b/cfg/SIM921_cfg.py @@ -0,0 +1,32 @@ +Node('bridge.psi.ch', + 'ac resistance bridge', + 'tcp://5000' + ) + +Mod('io', + 'frappy_psi.bridge.BridgeIO', + 'communication to sim900', + uri='serial:///dev/cu.usbserial-21440' + ) + +# Mod('SIM921_A', +# 'frappy_psi.bridge.SIM921', +# 'module communication', +# io='io', +# 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' +# ) + diff --git a/frappy_psi/bridge.py b/frappy_psi/bridge.py index 2680784..f1b28ec 100644 --- a/frappy_psi/bridge.py +++ b/frappy_psi/bridge.py @@ -18,7 +18,8 @@ import re from frappy.core import HasIO, Readable, Drivable, Parameter, FloatRange, IntRange, EnumType, \ - Enum + Enum, Property, StringType +from SR830 import string_to_value class BridgeIO(HasIO): @@ -29,54 +30,62 @@ class BridgeIO(HasIO): 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 + # 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): - #port = Parameter() - value = Parameter('temperature', unit='K') + channel = Property('sim921 module', StringType()) setpoint = Parameter('temperature deviation', datatype=FloatRange, unit='K') - resistance = Parameter('resistance', datatype=FloatRange, unit='ohm') - irange = Parameter('resistance range index', IntRange) + 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') - tc = Parameter('time constant', FloatRange) + + 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_resistance(self): - return self.get_par('rval') - def read_value(self): - return self.get_par('tval') + return self.get_par('rval?') def read_phase(self): return self.get_par('phase') @@ -93,23 +102,8 @@ class SIM921(BridgeIO, Readable, Drivable): def write_tc(self, tc): return self.set_par(f'tcon {tc}') - - - - - - - - - - - - - - - - - + def read_dev(self): + return self.comm('rdev?')