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:
@ -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()
|
||||
|
||||
|
Reference in New Issue
Block a user