From 735c19aed4fc85ff6f17b413930ada1672ebb4ff Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Thu, 9 Dec 2021 20:57:53 -0500 Subject: generalized code --- qolab/hardware/scope/__init__.py | 26 +++++++++----------------- qolab/hardware/scope/sds1104x.py | 3 +++ 2 files changed, 12 insertions(+), 17 deletions(-) (limited to 'qolab/hardware') diff --git a/qolab/hardware/scope/__init__.py b/qolab/hardware/scope/__init__.py index bcbc87c..b89e2b6 100644 --- a/qolab/hardware/scope/__init__.py +++ b/qolab/hardware/scope/__init__.py @@ -3,20 +3,21 @@ Provide basic class to operate scope Created by Eugeniy E. Mikhailov 2021/11/29 """ from qolab.hardware.scpi import SCPIinstr +from qolab.hardware.basic import BasicInstrument from qolab.data.trace import TraceSetSameX from qolab.file_utils import get_next_data_file import yaml -class Scope: +class Scope(BasicInstrument): # Minimal set of methods to be implemented by a scope. def __init__(self): - self.config={} - self.config['Device type'] = 'Scope' + BasicInstrument.__init__(self) + self.config['Device type']='Scope' + self.config['FnamePrefix'] = 'scope' self.config['Device model'] = 'Generic Scope Without Hardware interface' + self.config['FnamePrefix'] = 'scope' self.numberOfChannels = 0 - self.fname_prefix = 'scope' - self.savepath = './scope' # deviceProperties must have 'get' and preferably 'set' methods available, # i.e. 'SampleRate' needs getSampleRate() and love to have setSampleRate(value) # they will be used to obtain config and set device according to it @@ -42,17 +43,7 @@ class Scope: allTraces.plot() def getConfig(self): - config = self.config.copy() - dconfig = {} - dconfig['id'] = self.idn - for p in self.deviceProperties: - getter = f'get{p}' - if not hasattr(self, getter): - print(f'warning no getter for {p}, i.e. {getter} is missing') - continue - res = getattr(self, getter)() - dconfig[p] = res - config['DeviceConfig'] = dconfig + config = BasicInstrument.getConfig(self).copy() chconfig = {} for chNum in range(1, self.numberOfChannels+1): chNconfig = {} @@ -76,7 +67,7 @@ class Scope: def save(self, fname=None, item_format='e', availableNpnts=None, maxRequiredPoints=None, extention='dat'): allTraces = self.getAllTraces(availableNpnts=availableNpnts, maxRequiredPoints=maxRequiredPoints) if fname is None: - fname = get_next_data_file(self.fname_prefix, self.savepath, extention=extention) + fname = get_next_data_file(self.config['FnamePrefix'], self.config['SavePath'], extention=extention) allTraces.save(fname, item_format=item_format) return(fname) @@ -91,6 +82,7 @@ class ScopeSCPI(SCPIinstr, Scope): def __init__(self, resource): SCPIinstr.__init__(self, resource) Scope.__init__(self) + self.config['DeviceId'] = str.strip(self.idn) from .sds1104x import SDS1104X diff --git a/qolab/hardware/scope/sds1104x.py b/qolab/hardware/scope/sds1104x.py index f9b898c..1b9b39e 100644 --- a/qolab/hardware/scope/sds1104x.py +++ b/qolab/hardware/scope/sds1104x.py @@ -188,6 +188,9 @@ if __name__ == '__main__': print(f'Time per Div: {scope.getTimePerDiv()}') print(f'Ch1 Volts per Div: {scope.getChanVoltsPerDiv(1)}') print(f'Ch1 Voltage Offset: {scope.getChanOffset(1)}') + print('------ Header start -------------') + print(str.join('\n', scope.getHeader())) + print('------ Header ends -------------') ch1 = scope.getTrace(1) traces = scope.getAllTraces() -- cgit v1.2.3