From 2f9fe8e31ccd1239ed752b2a3b147a463af7f835 Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Mon, 3 Jan 2022 23:06:52 -0500 Subject: added device config recovery from another config --- qolab/hardware/basic.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'qolab/hardware') diff --git a/qolab/hardware/basic.py b/qolab/hardware/basic.py index 03d98c6..21e1e5d 100644 --- a/qolab/hardware/basic.py +++ b/qolab/hardware/basic.py @@ -65,6 +65,26 @@ class BasicInstrument: config['DeviceConfig'] = dconfig return config + def setConfig(self, cfg): + new_config = cfg.copy() + print('setting config') + device_config = new_config.pop('DeviceConfig') + self.config.update(new_config) + for p, v in device_config.items(): + print(f'{p=} {v=}') + setter = f'set{p}' + if hasattr(self, setter): + # we have something like setProperty + getattr(self, setter)(v) + continue + if hasattr(self, p) or hasattr(type(self), p): + # we have attribute Property + setattr(self, p, v) + continue + print(f'warning: both {setter} and attribute {p} are missing, making attribute {p}') + self.deviceProperties.add(p) + setattr(self, p, v) + def getHeader(self): header = yaml.dump(self.getConfig(), default_flow_style=False, sort_keys=False) header = header.split('\n') -- cgit v1.2.3