diff --git a/devlib/instrument/__init__.py b/devlib/instrument/__init__.py index 981dd7b..8defbbc 100644 --- a/devlib/instrument/__init__.py +++ b/devlib/instrument/__init__.py @@ -195,8 +195,8 @@ class Instrument(object): def teardown(self): pass - def reset(self, sites=None, kinds=None): - if kinds is None and sites is None: + def reset(self, sites=None, kinds=None, channels=None): + if kinds is None and sites is None and channels is None: self.active_channels = sorted(self.channels.values(), key=lambda x: x.label) else: if isinstance(sites, basestring): @@ -204,6 +204,12 @@ class Instrument(object): if isinstance(kinds, basestring): kinds = [kinds] self.active_channels = [] + for chan_name in (channels or []): + try: + self.active_channels.append(self.channels[chan_name]) + except KeyError: + msg = 'Unexpected channel "{}"; must be in {}' + raise ValueError(msg.format(chan_name, self.channels.keys())) for chan in self.channels.values(): if (kinds is None or chan.kind in kinds) and \ (sites is None or chan.site in sites): diff --git a/devlib/instrument/daq.py b/devlib/instrument/daq.py index cbee7b8..3120480 100644 --- a/devlib/instrument/daq.py +++ b/devlib/instrument/daq.py @@ -60,8 +60,8 @@ class DaqInstrument(Instrument): for kind in ['power', 'voltage']: self.add_channel(label, kind) - def reset(self, sites=None, kinds=None): - super(DaqInstrument, self).reset(sites, kinds) + def reset(self, sites=None, kinds=None, channels=None): + super(DaqInstrument, self).reset(sites, kinds, channels) self.execute('close') result = self.execute('configure', config=self.device_config) if not result.status == Status.OK: # pylint: disable=no-member diff --git a/devlib/instrument/energy_probe.py b/devlib/instrument/energy_probe.py index 54ce8de..a40a791 100644 --- a/devlib/instrument/energy_probe.py +++ b/devlib/instrument/energy_probe.py @@ -64,8 +64,8 @@ class EnergyProbeInstrument(Instrument): for kind in self.attributes: self.add_channel(label, kind) - def reset(self, sites=None, kinds=None): - super(EnergyProbeInstrument, self).reset(sites, kinds) + def reset(self, sites=None, kinds=None, channels=None): + super(EnergyProbeInstrument, self).reset(sites, kinds, channels) self.raw_output_directory = tempfile.mkdtemp(prefix='eprobe-caiman-') parts = ['-r {}:{} '.format(i, int(1000 * rval)) for i, rval in enumerate(self.resistor_values)] diff --git a/devlib/instrument/netstats/__init__.py b/devlib/instrument/netstats/__init__.py index 0a45a0d..f42ea9b 100644 --- a/devlib/instrument/netstats/__init__.py +++ b/devlib/instrument/netstats/__init__.py @@ -98,8 +98,8 @@ class NetstatsInstrument(Instrument): self.logger.debug('Deploying {} to target'.format(self.package)) self.target.install(self.apk) - def reset(self, sites=None, kinds=None, period=None): # pylint: disable=arguments-differ - super(NetstatsInstrument, self).reset(sites, kinds) + def reset(self, sites=None, kinds=None, channels=None, period=None): # pylint: disable=arguments-differ + super(NetstatsInstrument, self).reset(sites, kinds, channels) period_arg, packages_arg = '', '' self.tag = 'netstats-{}'.format(datetime.now().strftime('%Y%m%d%H%M%s')) tag_arg = ' --es tag {}'.format(self.tag)