autogeneration of iodevs

allow a shortcut for generating iodevs:
If 'uri' is given in the config file for a module with HasIodev, it
will autogenerate its communicator.
The iodevClass attribute on the module class determines the class
for the iodev to be generated.

Change-Id: I4e82a57a33218fd159cec9f4c95171365c55d94a
Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/22068
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de>
This commit is contained in:
zolliker 2019-12-20 10:43:45 +01:00
parent f06fa9faa2
commit e2cc9f74b5
3 changed files with 27 additions and 18 deletions

View File

@ -6,21 +6,16 @@ type = tcp
bindto = 0.0.0.0 bindto = 0.0.0.0
bindport = 5000 bindport = 5000
[module lsmain]
class = secop_psi.ls370res.Main
description = main control of Lsc controller
uri = localhost:4567
[module res] [module res]
class = secop_psi.ls370res.ResChannel class = secop_psi.ls370res.ResChannel
vexc = '2mV' vexc = '2mV'
.channel = 3 channel = 3
.description = resistivity description = resistivity
.main = lsmain main = lsmain
.iodev = lscom # the auto created iodev from lsmain:
iodev = lsmain_iodev
[module lsmain]
class = secop_psi.ls370res.Main
.description = main control of Lsc controller
.iodev = lscom
[module lscom]
class = secop_psi.ls370res.StringIO
.uri=localhost:4567
.description = serial communicator to an LS 370
.visibility = 3

View File

@ -59,7 +59,7 @@ class StringIO(Communicator):
} }
parameters = { parameters = {
'timeout': 'timeout':
Parameter('timeout', datatype=FloatRange(0), default=1), Parameter('timeout', datatype=FloatRange(0), default=2),
'wait_before': 'wait_before':
Parameter('wait time before sending', datatype=FloatRange(), default=0), Parameter('wait time before sending', datatype=FloatRange(), default=0),
'is_connected': 'is_connected':
@ -236,7 +236,7 @@ class StringIO(Communicator):
if self.wait_before: if self.wait_before:
time.sleep(self.wait_before) time.sleep(self.wait_before)
if garbage is None: # read garbage only once if garbage is None: # read garbage only once
garbage = '' garbage = b''
data = self.readWithTimeout(0) data = self.readWithTimeout(0)
while data: while data:
garbage += data garbage += data
@ -276,12 +276,23 @@ class HasIodev(Module):
"""Mixin for modules using a communicator""" """Mixin for modules using a communicator"""
properties = { properties = {
'iodev': Attached(), 'iodev': Attached(),
'uri': Property('uri for auto creation of iodev', StringType(), default=''),
} }
def __init__(self, name, logger, opts, srv):
super().__init__(name, logger, opts, srv)
if self.uri:
opts = {'uri': self.uri, 'description': 'communication device for %s' % name,
'export': False}
ioname = name + '_iodev'
iodev = self.iodevClass(ioname, self.log.getChild(ioname), opts, srv)
srv.modules[ioname] = iodev
self.setProperty('iodev', ioname)
def initModule(self): def initModule(self):
try: try:
self._iodev.read_is_connected() self._iodev.read_is_connected()
except CommunicationFailedError: except (CommunicationFailedError, AttributeError):
pass pass
super().initModule() super().initModule()

View File

@ -57,6 +57,7 @@ for bit, text in enumerate('CS_OVL VCM_OVL VMIX_OVL R_OVER R_UNDER T_OVER T_UNDE
class StringIO(secop.stringio.StringIO): class StringIO(secop.stringio.StringIO):
identification = [('*IDN?', 'LSCI,MODEL370,.*')] identification = [('*IDN?', 'LSCI,MODEL370,.*')]
wait_before = 0.05
class Main(HasIodev, Module): class Main(HasIodev, Module):
@ -72,6 +73,7 @@ class Main(HasIodev, Module):
} }
pollerClass = Poller pollerClass = Poller
iodevClass = StringIO
def analyze_scan(self, channel, autoscan): def analyze_scan(self, channel, autoscan):
return dict(channel=channel, autoscan=autoscan) return dict(channel=channel, autoscan=autoscan)
@ -96,6 +98,7 @@ class ResChannel(HasIodev, Readable):
for val in [2, 6.32, 20, 63.2, 200, 632]))} for val in [2, 6.32, 20, 63.2, 200, 632]))}
pollerClass = Poller pollerClass = Poller
iodevClass = StringIO
properties = { properties = {
'channel': 'channel':