Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
artiq_experiments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nicolas Nunez Barreto
artiq_experiments
Commits
c55d7e6a
Commit
c55d7e6a
authored
Jun 02, 2021
by
Lucas Giardino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lectura de json preexistente
parent
69b498b0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
24 deletions
+47
-24
dds_control_interface.py
dds_control_interface.py
+47
-24
No files found.
dds_control_interface.py
View file @
c55d7e6a
...
...
@@ -3,11 +3,12 @@
# - go to the same directory as the 'device.db' file
# (otherwise you must specify the correct --device-db)
# - run this file as `artiq_run dds_control_interface.py`
#
[-] 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
# [-] 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
##########################################################################################
import
sys
import
os
from
PyQt5.QtWidgets
import
*
# from PyQt5.QtGui import QIcon, QDoubleValidator
# from PyQt5.QtCore import pyqtSlot
...
...
@@ -16,15 +17,19 @@ from artiq.experiment import *
# TODO:
# [ ] Check why amplitude fails to update
# [ ] Set initial values of inputs to correct ones based on dict
# [ ] └ Look for a saved json at start to get initial values
# [ ] Catch errors and send according popus
# [~] Set initial values of inputs to correct ones based on dict
# [~] └ Look for a saved json at start to get initial values
# [ ] Check inputs
# [ ] Add options to specify datafiles
# [ ] Catch errors and send according popups
# [ ] Refactor to remove the artiq/dds handle issue
# [ ] Add tabs to store different configurations
JSON_DATAFILE
=
'dds_states.json'
class
SingleChannel
(
QWidget
):
#{{{
"""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
# but should be doable somehow
QWidget
.
__init__
(
self
)
...
...
@@ -32,13 +37,16 @@ class SingleChannel(QWidget): #{{{
self
.
core
=
core
self
.
dds
=
dds
# PArameter dictionary to store and save current DDS states
self
.
state_params
=
{
'state'
:
0
,
'freq'
:
200
*
MHz
,
'amp'
:
1.
,
'att'
:
0
*
dB
}
if
initial_pars
is
None
:
# PArameter dictionary to store and save current DDS states
self
.
state_params
=
{
'state'
:
0
,
'freq'
:
200
*
MHz
,
'amp'
:
1.
,
'att'
:
0
*
dB
}
else
:
self
.
state_params
=
initial_pars
# Each DDS will have each own enablable group
self
.
groupbox
=
QGroupBox
(
name
)
...
...
@@ -62,8 +70,8 @@ class SingleChannel(QWidget): #{{{
# Frecuency input {{{
self
.
freq_input
=
QDoubleSpinBox
()
self
.
freq_input
.
setPrefix
(
"Frequency: "
)
self
.
freq_input
.
setRange
(
1.
,
400.
)
self
.
freq_input
.
set
SingleStep
(
0.1
)
self
.
freq_input
.
setRange
(
1.
,
400.
,
0.1
)
self
.
freq_input
.
set
Value
(
self
.
state_params
[
'freq'
]
)
self
.
freq_input
.
setSuffix
(
" MHz"
)
self
.
freq_input
.
valueChanged
.
connect
(
self
.
freq_change
)
vbox
.
addWidget
(
self
.
freq_input
)
...
...
@@ -72,8 +80,8 @@ class SingleChannel(QWidget): #{{{
# Amplitude input {{{
self
.
amp_input
=
QDoubleSpinBox
()
self
.
amp_input
.
setPrefix
(
"Amplitude: "
)
self
.
amp_input
.
setRange
(
0.
,
1.
)
self
.
amp_input
.
set
SingleStep
(
0.1
)
self
.
amp_input
.
setRange
(
0.
,
1.
,
0.1
)
self
.
amp_input
.
set
Value
(
self
.
state_params
[
'att'
]
)
self
.
amp_input
.
valueChanged
.
connect
(
self
.
amp_change
)
vbox
.
addWidget
(
self
.
amp_input
)
# }}}
...
...
@@ -81,8 +89,8 @@ class SingleChannel(QWidget): #{{{
# Attenuation input {{{
self
.
att_input
=
QDoubleSpinBox
()
self
.
att_input
.
setPrefix
(
"Attenuation: "
)
self
.
att_input
.
setRange
(
0.
,
31.
)
self
.
att_input
.
set
SingleStep
(
0.1
)
self
.
att_input
.
setRange
(
0.
,
31.
,
0.1
)
self
.
att_input
.
set
Value
(
self
.
state_params
[
'att'
]
)
self
.
att_input
.
setSuffix
(
" dB"
)
self
.
att_input
.
valueChanged
.
connect
(
self
.
att_change
)
vbox
.
addWidget
(
self
.
att_input
)
...
...
@@ -174,15 +182,22 @@ class DDSManager(QWidget): #{{{
self
.
ch0
=
ch0
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"
)
layout
=
QGridLayout
()
self
.
setLayout
(
layout
)
# 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
)
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
)
save_btn
=
QPushButton
(
"Save state"
)
...
...
@@ -193,13 +208,21 @@ class DDSManager(QWidget): #{{{
start_btn
.
clicked
.
connect
(
self
.
start
)
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"""
ch0_data
=
self
.
laser_1
.
get_state
()
ch1_data
=
self
.
laser_2
.
get_state
()
out_json
=
{
'ch0'
:
ch0_data
,
'ch1'
:
ch1_data
}
file_name
=
'dds_states.json'
with
open
(
file_name
,
'w'
)
as
log
:
with
open
(
JSON_DATAFILE
,
'w'
)
as
log
:
json
.
dump
(
out_json
,
log
,
indent
=
1
)
def
start
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment