diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-12-08 23:57:30 -0500 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-12-09 00:12:38 -0500 |
commit | 688338e6ffa4b208ecc883af03124899e55a1493 (patch) | |
tree | ce646242bbffd23d9db029af6e49ccf5eeae8019 /qolab/hardware | |
parent | e6df39ca9c3594d5800978e003f3defe47da4ada (diff) | |
download | qolab-688338e6ffa4b208ecc883af03124899e55a1493.tar.gz qolab-688338e6ffa4b208ecc883af03124899e55a1493.zip |
added scope config and header functions
Diffstat (limited to 'qolab/hardware')
-rw-r--r-- | qolab/hardware/scope/__init__.py | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/qolab/hardware/scope/__init__.py b/qolab/hardware/scope/__init__.py index 46898ac..896fb61 100644 --- a/qolab/hardware/scope/__init__.py +++ b/qolab/hardware/scope/__init__.py @@ -5,6 +5,7 @@ Created by Eugeniy E. Mikhailov 2021/11/29 from qolab.hardware.scpi import SCPIinstr from qolab.data.trace import TraceSetSameX from qolab.file_utils import get_next_data_file +import yaml class Scope: @@ -13,6 +14,13 @@ class 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 + self.deviceProperties = ['SampleRate', 'TimePerDiv', 'TrigDelay', ]; + # same is applied to channelProperties but we need setter/getter with channel number + # i.e. VoltsPerDiv -> getChanVoltsPerDiv(chNum) and setSampleRate(chNum, value) + self.channelProperties = ['VoltsPerDiv', 'Offset', ] def getTrace(self, chNum, availableNpnts=None, maxRequiredPoints=None): # Should work with minimal arguments list @@ -25,11 +33,43 @@ class Scope: allTraces.addTrace( self.getTrace(chNum, availableNpnts, maxRequiredPoints) ) return( allTraces ) + def getConfig(self): + config = {} + 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['Device'] = dconfig + chconfig = {} + for chNum in range(1, self.numberOfChannels+1): + chNconfig = {} + for p in self.channelProperties: + getter = f'getChan{p}' + if not hasattr(self, getter): + print(f'warning no getter for {p}, i.e. {getter} is missing') + continue + res = getattr(self, getter)(chNum) + chNconfig[p] = res + chconfig[chNum] = chNconfig + config['Channels']=chconfig + return config + + def getHeader(self): + header = yaml.dump(self.getConfig(), default_flow_style=False, sort_keys=False) + header = header.split('\n') + return header + + 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) - allTraces.save(fname, item_format=item_format) + allTraces.save(fname, item_format=item_format, header=self.getHeader()) return(fname) |