Commit c55d7e6a authored by Lucas Giardino's avatar Lucas Giardino

lectura de json preexistente

parent 69b498b0
...@@ -3,11 +3,12 @@ ...@@ -3,11 +3,12 @@
# - go to the same directory as the 'device.db' file # - go to the same directory as the 'device.db' file
# (otherwise you must specify the correct --device-db) # (otherwise you must specify the correct --device-db)
# - run this file as `artiq_run dds_control_interface.py` # - run this file as `artiq_run dds_control_interface.py`
# [-] specify `--device-db path/to/device.db` parameter with proper path if needed # [-] specify `--device-db path/to/device.db` parameter with proper path if needed
# [-] add a & to the end of the call to run as a background process # [-] add a & to the end of the call to run as a background process
########################################################################################## ##########################################################################################
import sys import sys
import os
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
# from PyQt5.QtGui import QIcon, QDoubleValidator # from PyQt5.QtGui import QIcon, QDoubleValidator
# from PyQt5.QtCore import pyqtSlot # from PyQt5.QtCore import pyqtSlot
...@@ -16,15 +17,19 @@ from artiq.experiment import * ...@@ -16,15 +17,19 @@ from artiq.experiment import *
# TODO: # TODO:
# [ ] Check why amplitude fails to update # [ ] Check why amplitude fails to update
# [ ] Set initial values of inputs to correct ones based on dict # [~] Set initial values of inputs to correct ones based on dict
# [ ] └ Look for a saved json at start to get initial values # [~] └ Look for a saved json at start to get initial values
# [ ] Catch errors and send according popus # [ ] Check inputs
# [ ] Add options to specify datafiles
# [ ] Catch errors and send according popups
# [ ] Refactor to remove the artiq/dds handle issue # [ ] Refactor to remove the artiq/dds handle issue
# [ ] Add tabs to store different configurations # [ ] Add tabs to store different configurations
JSON_DATAFILE = 'dds_states.json'
class SingleChannel(QWidget): #{{{ class SingleChannel(QWidget): #{{{
"""Class to control a single given Urukul channel""" """Class to control a single given Urukul channel"""
def __init__(self, core, dds, name="Default Name"): def __init__(self, core, dds, name="Default Name", initial_pars=None):
# Must pass artiq and dds handles. I don't know how to work around this # Must pass artiq and dds handles. I don't know how to work around this
# but should be doable somehow # but should be doable somehow
QWidget.__init__(self) QWidget.__init__(self)
...@@ -32,13 +37,16 @@ class SingleChannel(QWidget): #{{{ ...@@ -32,13 +37,16 @@ class SingleChannel(QWidget): #{{{
self.core = core self.core = core
self.dds = dds self.dds = dds
# PArameter dictionary to store and save current DDS states if initial_pars is None:
self.state_params = { # PArameter dictionary to store and save current DDS states
'state' : 0 , self.state_params = {
'freq' : 200*MHz , 'state' : 0 ,
'amp' : 1. , 'freq' : 200*MHz ,
'att' : 0*dB 'amp' : 1. ,
} 'att' : 0*dB
}
else:
self.state_params = initial_pars
# Each DDS will have each own enablable group # Each DDS will have each own enablable group
self.groupbox = QGroupBox(name) self.groupbox = QGroupBox(name)
...@@ -62,8 +70,8 @@ class SingleChannel(QWidget): #{{{ ...@@ -62,8 +70,8 @@ class SingleChannel(QWidget): #{{{
# Frecuency input {{{ # Frecuency input {{{
self.freq_input = QDoubleSpinBox() self.freq_input = QDoubleSpinBox()
self.freq_input.setPrefix("Frequency: ") self.freq_input.setPrefix("Frequency: ")
self.freq_input.setRange(1., 400.) self.freq_input.setRange(1., 400., 0.1)
self.freq_input.setSingleStep(0.1) self.freq_input.setValue(self.state_params['freq'])
self.freq_input.setSuffix(" MHz") self.freq_input.setSuffix(" MHz")
self.freq_input.valueChanged.connect(self.freq_change) self.freq_input.valueChanged.connect(self.freq_change)
vbox.addWidget(self.freq_input) vbox.addWidget(self.freq_input)
...@@ -72,8 +80,8 @@ class SingleChannel(QWidget): #{{{ ...@@ -72,8 +80,8 @@ class SingleChannel(QWidget): #{{{
# Amplitude input {{{ # Amplitude input {{{
self.amp_input = QDoubleSpinBox() self.amp_input = QDoubleSpinBox()
self.amp_input.setPrefix("Amplitude: ") self.amp_input.setPrefix("Amplitude: ")
self.amp_input.setRange(0., 1.) self.amp_input.setRange(0., 1., 0.1)
self.amp_input.setSingleStep(0.1) self.amp_input.setValue(self.state_params['att'])
self.amp_input.valueChanged.connect(self.amp_change) self.amp_input.valueChanged.connect(self.amp_change)
vbox.addWidget(self.amp_input) vbox.addWidget(self.amp_input)
# }}} # }}}
...@@ -81,8 +89,8 @@ class SingleChannel(QWidget): #{{{ ...@@ -81,8 +89,8 @@ class SingleChannel(QWidget): #{{{
# Attenuation input {{{ # Attenuation input {{{
self.att_input = QDoubleSpinBox() self.att_input = QDoubleSpinBox()
self.att_input.setPrefix("Attenuation: ") self.att_input.setPrefix("Attenuation: ")
self.att_input.setRange(0., 31.) self.att_input.setRange(0., 31., 0.1)
self.att_input.setSingleStep(0.1) self.att_input.setValue(self.state_params['att'])
self.att_input.setSuffix(" dB") self.att_input.setSuffix(" dB")
self.att_input.valueChanged.connect(self.att_change) self.att_input.valueChanged.connect(self.att_change)
vbox.addWidget(self.att_input) vbox.addWidget(self.att_input)
...@@ -174,15 +182,22 @@ class DDSManager(QWidget): #{{{ ...@@ -174,15 +182,22 @@ class DDSManager(QWidget): #{{{
self.ch0 = ch0 self.ch0 = ch0
self.ch1 = ch1 self.ch1 = ch1
# Make a default initial parameter dictionary to pass to the channels
# in case a real one is found, this gets stepped on with the real values
initial_params = {'ch0': None, 'ch1': None}
loaded_params.update(self.load_state())
self.setWindowTitle("DDS Manager GUI") self.setWindowTitle("DDS Manager GUI")
layout = QGridLayout() layout = QGridLayout()
self.setLayout(layout) self.setLayout(layout)
# Create both output widgets # Create both output widgets
self.laser_1 = SingleChannel(core, ch0, name="Laser 1") self.laser_1 = SingleChannel(core, ch0, name="Laser 1",
initial_pars=initial_params['ch0'])
layout.addWidget(self.laser_1.get_widget(), 0, 0) layout.addWidget(self.laser_1.get_widget(), 0, 0)
self.laser_2 = SingleChannel(core, ch1, name="Laser 2") self.laser_2 = SingleChannel(core, ch1, name="Laser 2",
initial_pars=initial_params['ch1'])
layout.addWidget(self.laser_2.get_widget(), 0, 1) layout.addWidget(self.laser_2.get_widget(), 0, 1)
save_btn = QPushButton("Save state") save_btn = QPushButton("Save state")
...@@ -193,13 +208,21 @@ class DDSManager(QWidget): #{{{ ...@@ -193,13 +208,21 @@ class DDSManager(QWidget): #{{{
start_btn.clicked.connect(self.start) start_btn.clicked.connect(self.start)
layout.addWidget(start_btn, 1, 1) layout.addWidget(start_btn, 1, 1)
def save(self): def load_state(self):
"""Load the JSON parameter dictionary if existent"""
if !os.path.isfile(JSON_DATAFILE):
return False
with open(JSON_DATAFILE, "r") as in_json:
return json.load(in_json)
def save_state(self):
"""Store the parameter dictionary as a JSON file""" """Store the parameter dictionary as a JSON file"""
ch0_data = self.laser_1.get_state() ch0_data = self.laser_1.get_state()
ch1_data = self.laser_2.get_state() ch1_data = self.laser_2.get_state()
out_json = {'ch0':ch0_data, 'ch1':ch1_data} out_json = {'ch0':ch0_data, 'ch1':ch1_data}
file_name = 'dds_states.json' with open(JSON_DATAFILE, 'w') as log:
with open(file_name, 'w') as log:
json.dump(out_json, log, indent=1) json.dump(out_json, log, indent=1)
def start(self): def start(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment