[TransWarp] component path - property name dualism, does this make sense?
Matthias Drochner
M.Drochner at fz-juelich.de
Mon Aug 18 08:44:15 EDT 2003
Looking for tools which can help me getting some structure into
a Python program which has grown into an anmost unmanageable state,
I recently found PEAK.
The program is for controlling a spectrometer with some tens of
mechanical axes, which can be grouped to logical units, or hidden
by logical layers which perform unit conversions (or more complicated
cristallographic calculations), or restrict movement.
(This looks a lot like the "car" example in the tutorial...)
Configuration data (limits, speeds, mapping to physical motor controllers)
come from a special database in normal use, but each axis should be
configurable to get its data from an ".ini" file for test reasons.
If component bindings reflect the logical structure of the device, it
seems natural for me to use this namespace to lookup configuration
data. Now I get 2 problems:
-the component path is not known at component class creation time
-component and configuration paths are syntactically incompatible
I'll append how I worked around so far.
This doesn't look clean and pretty, so maybe I'm just missing
the PEAKish way of accomplishing that?
Or is it a bad idea to use component paths for configuration?
thanks for any help
Matthias
<<testaxis.py>>
class testaxis(binding.Component):
__implements__ = [movable.Imovable]
logger = binding.bindToProperty('logging.movement')
__initMe = binding.whenAssembled(
lambda self, d, a: self.__init()
)
def __init(self):
self.path = binding.getComponentPath(self)
self.logger.debug('testaxis: initializing %s', self.path)
self.currentpos = 0
self.moving = 0
self.devpath = '.'.join(self.path[1:])
self.configsrc = config.getProperty(self, 'devconfig.%s' %
self.devpath)
self.ll = self.devlookup('ll')
self.ul = self.devlookup('ul')
self.speed = self.devlookup('speed')
def devlookup(self, what):
return self.lookupComponent('%s:%s.%s/' %
(self.configsrc, self.devpath, what))
<<movetest.ini>>
[devconfig]
movetest.* = 'config'
#movetest.* = 'tacodb'
[movetest]
group1.member1.ll = 0
group1.member1.ul = 100
group1.member1.speed = 0.4
group1.member2.ll = 0
group1.member2.ul = 100
group1.member2.speed = 0.2
More information about the PEAK
mailing list