Communication with the modules for the ac resistance bridge.

Change-Id: I1c144bf0bfc7c8c3090aa7cf3f32f1d4d046dca7
This commit is contained in:
Oksana Shliakhtun 2024-05-21 17:30:11 +02:00
parent cba15e0237
commit efc1694408
2 changed files with 71 additions and 77 deletions

View File

@ -1,32 +1,33 @@
Node('bridge.psi.ch', Node('bridge.psi.ch',
'ac resistance bridge', 'ac resistance bridge',
'tcp://5000' 'tcp://5000',
) )
Mod('io', Mod('io',
'frappy_psi.bridge.BridgeIO', 'frappy_psi.bridge.BridgeIO',
'communication to sim900', 'communication to sim900',
uri='serial:///dev/cu.usbserial-21440' uri='serial:///dev/cu.usbserial-14440',
) )
# Mod('SIM921_A', Mod('Resistance_1',
# 'frappy_psi.bridge.SIM921', 'frappy_psi.bridge.SIM921',
# 'module communication', 'module communication',
# io='io', io='io',
# channel='A' port=1,
# ) # channel='A'
)
# Mod('SIM921_B', Mod('Resistance_2',
# 'frappy_psi.bridge.SIM921', 'frappy_psi.bridge.SIM921',
# 'module communication', 'module communication',
# io='io', io='io',
# channel='B' port=3,
# ) )
#
# Mod('SIM921_C', Mod('Resistance_3',
# 'frappy_psi.bridge.SIM921', 'frappy_psi.bridge.SIM921',
# 'module communication', 'module communication',
# io='io', io='io',
# channel='C' port=5,
# ) )

View File

@ -16,98 +16,91 @@
# Module authors: Oksana Shliakhtun <oksana.shliakhtun@psi.ch> # Module authors: Oksana Shliakhtun <oksana.shliakhtun@psi.ch>
# ***************************************************************************** # *****************************************************************************
import time
import re 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 Enum, Property, StringType
from SR830 import string_to_value # from SR830 import string_to_value
class BridgeIO(HasIO): class BridgeIO(StringIO):
end_of_line = b'\r' # should be <lf> or <cr> end_of_line = ('\r\n', '') # read terminator / rmpty write terminator
identification = [('*IDN?', r'Stanford_Research_Systems,.*')] identification = [('*IDN?\r\n', r'Stanford_Research_Systems,.*'),
('RPER 510\r\nRPER?\r\n', '510')]
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): class Base(HasIO):
channel = Property('sim921 module', StringType()) 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') setpoint = Parameter('temperature deviation', datatype=FloatRange, unit='K')
value = Parameter('resistance', datatype=FloatRange, unit='ohm') 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', RES_RANGE = ['20mOhm', '200mOhm', '2Ohm', '20Ohm', '200Ohm', '2kOhm', '20kOhm', '200kOhm',
'2MOhm', '20MOhm'] '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', irange = Parameter('range index', EnumType('resistance range index',
{name: idx for idx, name in enumerate(RES_RANGE)}), readonly=False) {name: idx for idx, name in enumerate(RES_RANGE)}), readonly=False)
phase = Parameter('phase', FloatRange, unit='ang') 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) tc = Parameter('time constant value', FloatRange(1e-1, 3e2), unit='s', readonly=False)
itc = Parameter('time constant index', itc = Parameter('time constant index',
EnumType('time const. index range', EnumType('time const. index range',
{name: value for value, name in enumerate(TIME_CONST)}), readonly=False) {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) readonly=False, default=0)
iexct = Parameter('excitation index', IntRange)
ioClass = BridgeIO ioClass = BridgeIO
def read_value(self): def read_value(self):
return self.get_par('rval?') reply = self.command('rval?', 2)
return reply
def read_phase(self): def read_phase(self):
return self.get_par('phase') return self.command('phase?', 2)
def read_setpoint(self): def read_setpoint(self):
return self.get_par('tset') return self.command('rset?')
def write_setpoint(self, setpoint): # def write_setpoint(self, setpoint):
return self.comm(f'tset {setpoint}') # return self.command('rset', setpoint)
def read_tc(self): def read_tc(self):
return self.get_par('tcon') return self.command('tcon?')
def write_tc(self, tc): # def write_tc(self, tc):
return self.set_par(f'tcon {tc}') # return self.command('tcon', tc)
def read_dev(self): 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)