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:
parent
f06fa9faa2
commit
e2cc9f74b5
@ -6,21 +6,16 @@ type = tcp
|
||||
bindto = 0.0.0.0
|
||||
bindport = 5000
|
||||
|
||||
[module lsmain]
|
||||
class = secop_psi.ls370res.Main
|
||||
description = main control of Lsc controller
|
||||
uri = localhost:4567
|
||||
|
||||
[module res]
|
||||
class = secop_psi.ls370res.ResChannel
|
||||
vexc = '2mV'
|
||||
.channel = 3
|
||||
.description = resistivity
|
||||
.main = lsmain
|
||||
.iodev = lscom
|
||||
|
||||
[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
|
||||
channel = 3
|
||||
description = resistivity
|
||||
main = lsmain
|
||||
# the auto created iodev from lsmain:
|
||||
iodev = lsmain_iodev
|
||||
|
@ -59,7 +59,7 @@ class StringIO(Communicator):
|
||||
}
|
||||
parameters = {
|
||||
'timeout':
|
||||
Parameter('timeout', datatype=FloatRange(0), default=1),
|
||||
Parameter('timeout', datatype=FloatRange(0), default=2),
|
||||
'wait_before':
|
||||
Parameter('wait time before sending', datatype=FloatRange(), default=0),
|
||||
'is_connected':
|
||||
@ -236,7 +236,7 @@ class StringIO(Communicator):
|
||||
if self.wait_before:
|
||||
time.sleep(self.wait_before)
|
||||
if garbage is None: # read garbage only once
|
||||
garbage = ''
|
||||
garbage = b''
|
||||
data = self.readWithTimeout(0)
|
||||
while data:
|
||||
garbage += data
|
||||
@ -276,12 +276,23 @@ class HasIodev(Module):
|
||||
"""Mixin for modules using a communicator"""
|
||||
properties = {
|
||||
'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):
|
||||
try:
|
||||
self._iodev.read_is_connected()
|
||||
except CommunicationFailedError:
|
||||
except (CommunicationFailedError, AttributeError):
|
||||
pass
|
||||
super().initModule()
|
||||
|
||||
|
@ -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):
|
||||
identification = [('*IDN?', 'LSCI,MODEL370,.*')]
|
||||
wait_before = 0.05
|
||||
|
||||
|
||||
class Main(HasIodev, Module):
|
||||
@ -72,6 +73,7 @@ class Main(HasIodev, Module):
|
||||
}
|
||||
|
||||
pollerClass = Poller
|
||||
iodevClass = StringIO
|
||||
|
||||
def analyze_scan(self, channel, 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]))}
|
||||
|
||||
pollerClass = Poller
|
||||
iodevClass = StringIO
|
||||
|
||||
properties = {
|
||||
'channel':
|
||||
|
Loading…
x
Reference in New Issue
Block a user