diff --git a/commands.py b/commands.py index b80d565..47c1d06 100644 --- a/commands.py +++ b/commands.py @@ -96,7 +96,7 @@ def frappy_start(**services): all_cfg = {} new_cfg = [] remove_cfg = [] - for service in SERVICES: + for service in reversed(SERVICES): secnode = session.devices.get('se_' + service) cfginfo = services.get(service) if cfginfo is None: diff --git a/devices.py b/devices.py index 48a80f4..b9a0d65 100644 --- a/devices.py +++ b/devices.py @@ -78,9 +78,14 @@ class FrappyConfig(Device): 'magneticfield': Param( 'config for magnetic field', type=anytype, default={}), 'rotation_z': Param( - 'config for sample rotation', type=anytype, default={}), + 'config for sample rotation (to be used as a3)', + type=anytype, default={}), + 'stick_rotation': Param( + 'config for stick rotation (not necessarily to be used as a3)', + type=anytype, default={}), 'nodes': Param( - 'list of names of potential SEC nodes', type=listof(str), default=[]), + 'list of names of potential SEC nodes', + type=listof(str), default=[]), } meanings = list(parameters) @@ -89,7 +94,7 @@ class FrappyConfig(Device): def remove_aliases(self): for meaning in self.meanings: info = getattr(self, meaning) - aliasnames = info['alias'] + aliasnames = info.get('alias', []) if isinstance(aliasnames, str): aliasnames = [aliasnames] for aliasname in aliasnames: @@ -103,7 +108,7 @@ class FrappyConfig(Device): result = {} for meaning in self.meanings: info = getattr(self, meaning) - aliasnames = info['alias'] + aliasnames = info.get('alias', []) if isinstance(aliasnames, str): aliasnames = [aliasnames] for aliasname in aliasnames: @@ -139,19 +144,22 @@ class FrappyConfig(Device): info = getattr(self, meaning) aliasnames = info.get('alias') if aliasnames is None: - continue - if isinstance(aliasnames, str): + aliasnames = [] + elif isinstance(aliasnames, str): aliasnames = [aliasnames] aliascfg = info.get('targets', {}) - unique = info.get('unique') - if unique: - aliases = [a for a in unique + predefined_alias = info.get('predefined_alias') + if predefined_alias: + aliases = [a for a in predefined_alias if isinstance(session.devices.get(a), DeviceAlias)] if aliases: if len(aliases) > 1: raise TypeError(f'do know to which of {aliases} {meaning} to assign to') alias_config = session.alias_config.setdefault(aliases[0], []) alias_config.extend(list(aliascfg.items())) + elif not aliasnames: + session.log.warn("neither 'predefined_alias' nor 'alias' configured. skip %s", meaning) + continue importance_list = sample_devices.get(meaning, []) importance_list.extend([(nr, nam) for nam, nr in aliascfg.items() if nam in session.devices]) importance_list = sorted(importance_list, reverse=True) @@ -172,14 +180,15 @@ class FrappyConfig(Device): session.log.debug('create alias %r -> %r', aliasname, devname) aliasdev = session.createDevice(aliasname, recreate=True, explicit=True) aliasdev.alias = devname - # only the first item of aliasnames is added to the envlist - aliasname = aliasnames[0] - to_remove.add(devname) - to_remove.add(aliasname) - if devname not in newenv and info.get('envlist', True): - # example: when 'temperature' and 'temperature_regulation' are the - # same device, the first one is kept - newenv[devname] = aliasname + if aliasnames: + # only the first item of aliasnames is added to the envlist + aliasname = aliasnames[0] + to_remove.add(devname) + to_remove.add(aliasname) + if devname not in newenv and info.get('envlist', True): + # example: when 'temperature' and 'temperature_regulation' are the + # same device, the first one is kept + newenv[devname] = aliasname break else: to_remove.union(aliasnames) @@ -299,6 +308,7 @@ class FrappyNode(SecNodeDevice, Moveable): else: self.disable() if running_cfg: + self._disconnect() self._service_manager.do_stop(ins, self.service) is_cfg = cfg and ':' not in cfg if is_cfg: diff --git a/setups/frappy.py b/setups/frappy.py index 97607f4..90eb81b 100644 --- a/setups/frappy.py +++ b/setups/frappy.py @@ -33,15 +33,19 @@ devices = dict( 'alias': ['B', 'magfield'], 'targets': {'se_mf': 20}, }, - rotation_z = { + rotation_z={ # possible names of the instruments main omega alias # only one of these must be an alias, and this is then used - 'unique': ['a3', 'om'], + 'predefined_alias': ['a3', 'om'], + 'targets': {'se_om': 20}, + 'envlist': False, + }, + stick_rotation={ 'alias': 'dom', 'targets': {'se_om': 20, 'se_stickrot': 19}, 'envlist': False, } - ) + ) ) startupcode = '''