aboutsummaryrefslogtreecommitdiff
path: root/qolab/hardware/basic.py
blob: fa2ccb5d82691f188bd79526f77869aab2c247ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import yaml

class BasicInstrument:
    def __init__(self):
        self.config={}
        self.config['Device type'] = 'Basic Instrument'
        self.config['Device model'] = 'Model is unset'
        self.config['FnamePrefix'] = 'basicInstrument'
        self.config['SavePath'] = './data'
        # 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', ];
        self.deviceProperties = [];

    def getConfig(self):
        config = self.config.copy()
        dconfig = {}
        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
        return config

    def getHeader(self):
        header = yaml.dump(self.getConfig(), default_flow_style=False, sort_keys=False)
        header = header.split('\n')
        return header