aboutsummaryrefslogtreecommitdiff
path: root/qolab/hardware/scope/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'qolab/hardware/scope/__init__.py')
-rw-r--r--qolab/hardware/scope/__init__.py42
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)