diff --git a/doc/source/protocol/todo.rst b/doc/source/protocol/todo.rst index a8d4ab2..2bee8ab 100644 --- a/doc/source/protocol/todo.rst +++ b/doc/source/protocol/todo.rst @@ -16,7 +16,7 @@ Open questions -> needs Datatype for a function * datatype for funcion: is argin a list anyway, or just one (structured) argument? (so far we use a list and argout is a single datatype (which may be stuctured)) -* polling: vendor specific or do we propose a common way to handle it? +* polling: vendor specific or do we propose a common way to handle it? (playground uses a per-device pollinterval. params may be polled less often) * interface classes !!! (maybe with feature mixins like WindowTimeout?) * hardware access: unify? how? @@ -92,7 +92,7 @@ Documentation * transfer build docu into wiki via automated jobfile - + Transfer of blobs via json -------------------------- diff --git a/secop/modules.py b/secop/modules.py index 7a98359..0ea0610 100644 --- a/secop/modules.py +++ b/secop/modules.py @@ -216,14 +216,14 @@ class Module(object): # defined even for non drivable (used for dynamic polling) return False - def early_init(self): + def earlyInit(self): # may be overriden in derived classes to init stuff - self.log.debug('empty %s.early_init()' % self.__class__.__name__) + self.log.debug('empty %s.earlyInit()' % self.__class__.__name__) - def init_module(self): - self.log.debug('empty %s.init_module()' % self.__class__.__name__) + def initModule(self): + self.log.debug('empty %s.initModule()' % self.__class__.__name__) - def start_module(self, started_callback): + def startModule(self, started_callback): '''runs after init of all modules started_callback to be called when thread spawned by late_init @@ -231,7 +231,7 @@ class Module(object): might return a timeout value, if different from default ''' - self.log.debug('empty %s.start_module()' % self.__class__.__name__) + self.log.debug('empty %s.startModule()' % self.__class__.__name__) started_callback() @@ -267,7 +267,7 @@ class Readable(Module): ), } - def start_module(self, started_callback): + def startModule(self, started_callback): '''start polling thread''' mkthread(self.__pollThread, started_callback) @@ -285,7 +285,7 @@ class Readable(Module): def __pollThread_inner(self, started_callback): """super simple and super stupid per-module polling thread""" i = 0 - fastpoll = self.poll(i) + fastpoll = self.pollParams(i) started_callback() while True: i += 1 @@ -294,21 +294,19 @@ class Readable(Module): except TypeError: time.sleep(min(self.pollinterval) if fastpoll else max(self.pollinterval)) - fastpoll = self.poll(i) + fastpoll = self.pollParams(i) - def poll(self, nr=0): + def pollParams(self, nr=0): # Just poll all parameters regularly where polling is enabled - for pname, pobj in self.accessibles.items(): - if not isinstance(pobj, Parameter): - continue + for pname, pobj in self.parameters.items(): if not pobj.poll: continue if nr % abs(int(pobj.poll)) == 0: - # poll every 'pobj.poll' iteration + # pollParams every 'pobj.pollParams' iteration rfunc = getattr(self, 'read_' + pname, None) if rfunc: try: - rfunc() + rfunc() # pylint: disable = not-callable except Exception: # really all! pass @@ -351,13 +349,11 @@ class Drivable(Writable): return 300 <= self.status[0] < 400 # improved polling: may poll faster if module is BUSY - def poll(self, nr=0): + def pollParams(self, nr=0): # poll status first - stat = self.read_status(0) - fastpoll = stat[0] == self.Status.BUSY - for pname, pobj in self.accessibles.items(): - if not isinstance(pobj, Parameter): - continue + self.read_status(0) + fastpoll = self.isBusy() + for pname, pobj in self.parameters.items(): if not pobj.poll: continue if pname == 'status': @@ -370,7 +366,7 @@ class Drivable(Writable): rfunc = getattr(self, 'read_' + pname, None) if rfunc: try: - rfunc() + rfunc() # pylint: disable = not-callable except Exception: # really all! pass return fastpoll diff --git a/secop/params.py b/secop/params.py index d91eddf..7761132 100644 --- a/secop/params.py +++ b/secop/params.py @@ -83,7 +83,7 @@ class Parameter(Accessible): poll can be: - False (never poll this parameter) - - True (poll this ever pollinterval) + - True (poll this every pollinterval) - positive int (poll every N(th) pollinterval) - negative int (normally poll every N(th) pollinterval, if module is busy, poll every pollinterval) diff --git a/secop/server.py b/secop/server.py index 13d913b..16c9d14 100644 --- a/secop/server.py +++ b/secop/server.py @@ -185,18 +185,18 @@ class Server(object): for modname, modobj in self.modules.items(): self.log.info(u'registering module %r' % modname) self.dispatcher.register_module(modobj, modname, modobj.properties['export']) - # also call early_init on the modules - modobj.early_init() + # also call earlyInit on the modules + modobj.earlyInit() # call init on each module after registering all for modname, modobj in self.modules.items(): - modobj.init_module() + modobj.initModule() start_events = [] for modname, modobj in self.modules.items(): event = threading.Event() - # start_module must return either a timeout value or None (default 30 sec) - timeout = modobj.start_module(started_callback=event.set) or 30 + # startModule must return either a timeout value or None (default 30 sec) + timeout = modobj.startModule(started_callback=event.set) or 30 start_events.append((time.time() + timeout, modname, event)) self.log.info(u'waiting for modules being started') for deadline, modname, event in sorted(start_events): diff --git a/secop_demo/cryo.py b/secop_demo/cryo.py index beb090d..c4f8a22 100644 --- a/secop_demo/cryo.py +++ b/secop_demo/cryo.py @@ -136,7 +136,7 @@ class Cryostat(CryoBase): special='content of special property'), ) - def init_module(self): + def initModule(self): self._stopflag = False self._thread = mkthread(self.thread) diff --git a/secop_demo/modules.py b/secop_demo/modules.py index 6f3a4b8..69cdfbd 100644 --- a/secop_demo/modules.py +++ b/secop_demo/modules.py @@ -122,7 +122,7 @@ class MagneticField(Drivable): 'status' : Override(datatype=TupleOf(EnumType(Status), StringType())), } - def init_module(self): + def initModule(self): self._state = Enum('state', idle=1, switch_on=2, switch_off=3, ramp=4).idle self._heatswitch = self.DISPATCHER.get_module(self.heatswitch) _thread = threading.Thread(target=self._thread) @@ -226,7 +226,7 @@ class SampleTemp(Drivable): ), } - def init_module(self): + def initModule(self): _thread = threading.Thread(target=self._thread) _thread.daemon = True _thread.start() diff --git a/secop_mlz/amagnet.py b/secop_mlz/amagnet.py index b65c761..2282dd2 100644 --- a/secop_mlz/amagnet.py +++ b/secop_mlz/amagnet.py @@ -134,8 +134,8 @@ class GarfieldMagnet(SequencerMixin, Drivable): raise ConfigError(self, '_current2field polynome not monotonic!') - def init_module(self): - super(GarfieldMagnet, self).init_module() + def initModule(self): + super(GarfieldMagnet, self).initModule() self._enable = self.DISPATCHER.get_module(self.subdev_enable) self._symmetry = self.DISPATCHER.get_module(self.subdev_symmetry) self._polswitch = self.DISPATCHER.get_module(self.subdev_polswitch) diff --git a/secop_mlz/entangle.py b/secop_mlz/entangle.py index fcbe879..880b5ff 100644 --- a/secop_mlz/entangle.py +++ b/secop_mlz/entangle.py @@ -211,12 +211,12 @@ class PyTangoDevice(Module): self._com_warn(tries, name, err, info) sleep(self.comdelay) - def early_init(self): + def earlyInit(self): # Wrap PyTango client creation (so even for the ctor, logging and # exception mapping is enabled). self._createPyTangoDevice = self._applyGuardToFunc( self._createPyTangoDevice, 'constructor') - super(PyTangoDevice, self).early_init() + super(PyTangoDevice, self).earlyInit() @lazy_property def _dev(self): @@ -380,8 +380,8 @@ class AnalogInput(PyTangoDevice, Readable): The AnalogInput handles all devices only delivering an analogue value. """ - def start_module(self, started_callback): - super(AnalogInput, self).start_module(started_callback) + def startModule(self, started_callback): + super(AnalogInput, self).startModule(started_callback) # query unit from tango and update value property attrInfo = self._dev.attribute_query('value') # prefer configured unit if nothing is set on the Tango device, else @@ -457,14 +457,14 @@ class AnalogOutput(PyTangoDevice, Drivable): _timeout = None _moving = False - def init_module(self): - super(AnalogOutput, self).init_module() + def initModule(self): + super(AnalogOutput, self).initModule() # init history self._history = [] # will keep (timestamp, value) tuple self._timeout = None # keeps the time at which we will timeout, or None - def start_module(self, started_callback): - super(AnalogOutput, self).start_module(started_callback) + def startModule(self, started_callback): + super(AnalogOutput, self).startModule(started_callback) # query unit from tango and update value property attrInfo = self._dev.attribute_query('value') # prefer configured unit if nothing is set on the Tango device, else @@ -472,8 +472,8 @@ class AnalogOutput(PyTangoDevice, Drivable): if attrInfo.unit != 'No unit': self.accessibles['value'].unit = attrInfo.unit - def poll(self, nr=0): - super(AnalogOutput, self).poll(nr) + def pollParams(self, nr=0): + super(AnalogOutput, self).pollParams(nr) while len(self._history) > 2: # if history would be too short, break if self._history[-1][0] - self._history[1][0] <= self.window: @@ -802,8 +802,8 @@ class NamedDigitalInput(DigitalInput): datatype=StringType(), export=False), # XXX:!!! } - def init_module(self): - super(NamedDigitalInput, self).init_module() + def initModule(self): + super(NamedDigitalInput, self).initModule() try: # pylint: disable=eval-used self.accessibles['value'].datatype = EnumType('value', **eval(self.mapping)) @@ -827,8 +827,8 @@ class PartialDigitalInput(NamedDigitalInput): datatype=IntRange(0), default=1), } - def init_module(self): - super(PartialDigitalInput, self).init_module() + def initModule(self): + super(PartialDigitalInput, self).initModule() self._mask = (1 << self.bitwidth) - 1 # self.accessibles['value'].datatype = IntRange(0, self._mask) @@ -869,8 +869,8 @@ class NamedDigitalOutput(DigitalOutput): datatype=StringType(), export=False), } - def init_module(self): - super(NamedDigitalOutput, self).init_module() + def initModule(self): + super(NamedDigitalOutput, self).initModule() try: # pylint: disable=eval-used self.accessibles['value'].datatype = EnumType('value', **eval(self.mapping)) @@ -897,8 +897,8 @@ class PartialDigitalOutput(NamedDigitalOutput): datatype=IntRange(0), default=1), } - def init_module(self): - super(PartialDigitalOutput, self).init_module() + def initModule(self): + super(PartialDigitalOutput, self).initModule() self._mask = (1 << self.bitwidth) - 1 # self.accessibles['value'].datatype = IntRange(0, self._mask) # self.accessibles['target'].datatype = IntRange(0, self._mask) diff --git a/test/test_modules.py b/test/test_modules.py index e68d91d..ae82357 100644 --- a/test/test_modules.py +++ b/test/test_modules.py @@ -48,10 +48,10 @@ def test_Communicator(): ))() o = Communicator('communicator',logger, {}, srv) - o.early_init() - o.init_module() + o.earlyInit() + o.initModule() event = threading.Event() - o.start_module(event.set) + o.startModule(event.set) assert event.is_set() # event should be set immediately def test_ModuleMeta(): @@ -139,9 +139,9 @@ def test_ModuleMeta(): assert o not in params_found for o in objects: - o.early_init() + o.earlyInit() for o in objects: - o.init_module() + o.initModule() for o in objects: event = threading.Event() @@ -153,6 +153,6 @@ def test_ModuleMeta(): event.set() raise Exception("end test") # this will kill the polling thread on the second call - o.start_module(started_callback) + o.startModule(started_callback) assert event2.wait(timeout=1) assert event.is_set()