Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AWG control
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
whuie2
AWG control
Commits
6e22528b
Commit
6e22528b
authored
2 years ago
by
camera computer
Browse files
Options
Downloads
Patches
Plain Diff
small QOL changes
parent
90ebb5db
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Python/control.py
+64
-10
64 additions, 10 deletions
Python/control.py
with
64 additions
and
10 deletions
Python/control.py
+
64
−
10
View file @
6e22528b
...
...
@@ -2,12 +2,23 @@ from AWG import *
import
code
import
readline
import
rlcompleter
import
os
import
argparse
# _step = int32(0)
def
get_step
():
step
=
int32
(
0
)
spcm_dwGetParam_i32
(
awg
.
card
,
SPC_SEQMODE_STATUS
,
byref
(
step
))
return
step
.
value
def
trigger
():
global
awg
# step = get_step()
awg
.
force_trigger
()
print
(
"
forcing a trigger...
"
)
# step = int32(0)
print
(
"
triggering...
"
)
# print("current step:", step)
def
stop
():
...
...
@@ -25,28 +36,72 @@ def start():
def
close
():
global
awg
awg
.
stop
()
awg
.
close
()
print
(
"
closing awg and quitting...
"
)
exit
(
0
)
def
load
(
fpath
):
# load new waveform onto the next step
# then use trigger() to change step
global
awg
# fpath is a relative path or absolute path
# use like: load_data("data/single.npz", 0)
if
not
os
.
path
.
isfile
(
fpath
):
print
(
"
invalid file path
"
)
return
data
=
np
.
load
(
fpath
,
allow_pickle
=
True
)
sig
=
data
[
'
signal
'
]
step
=
get_step
()
segment
=
(
step
+
1
)
%
2
awg
.
write_segment
(
sig
,
segment
)
print
(
f
"
currently playing step
{
step
}
, loaded data onto step
{
segment
}
"
)
# argument parsing, more functionalities to be added later...
parser
=
argparse
.
ArgumentParser
(
description
=
'
AWG control
'
)
parser
.
add_argument
(
'
-id
'
,
type
=
int
,
default
=
0
,
help
=
'
0 for top AWG, 1 for bot AWG, default to 0
'
)
args
=
parser
.
parse_args
()
awg_id
=
''
if
args
.
id
==
0
:
awg_id
=
b
'
/dev/spcm0
'
elif
args
.
id
==
1
:
awg_id
=
b
'
/dev/spcm1
'
else
:
print
(
"
invalid id
"
)
exit
(
0
)
# load waveform data
wfm_data
=
np
.
load
(
"
data/single.npz
"
,
allow_pickle
=
True
)
static_sig
=
wfm_data
[
'
signal
'
]
empty
=
np
.
zeros
(
static_sig
.
shape
)
wfm
=
wfm_data
[
'
wfm
'
].
item
()
data0
=
np
.
load
(
"
data/single.npz
"
,
allow_pickle
=
True
)
# alternatively, change file here and restart program
wfm
=
data0
[
'
wfm
'
].
item
()
sampling_rate
=
wfm
.
sample_rate
sig0
=
data0
[
'
signal
'
]
data1
=
np
.
load
(
"
data/wfm_5.npz
"
,
allow_pickle
=
True
)
sig1
=
data1
[
"
signal
"
]
# empty = np.zeros(static_sig.shape)
# AWG stuff
awg
=
AWG
()
awg
.
open
(
id
=
b
'
/dev/spcm1
'
)
# change this to b'/dev/spcm0' for top AWG
awg
.
open
(
id
=
awg_id
)
# change this to b'/dev/spcm0' for top AWG
awg
.
set_sampling_rate
(
sampling_rate
)
awg
.
toggle_channel
(
0
,
amplitude
=
2500
)
awg
.
set_trigger
(
EXT0
=
SPC_TM_POS
)
awg
.
set_sequence_mode
(
2
)
awg
.
write_segment
(
static_
sig
,
segment
=
0
)
awg
.
write_segment
(
empty
,
segment
=
1
)
awg
.
set_sequence_mode
(
2
)
# partition AWG memory into 2 segments
awg
.
write_segment
(
sig
0
,
segment
=
0
)
awg
.
write_segment
(
sig1
,
segment
=
1
)
awg
.
configure_step
(
step
=
0
,
segment
=
0
,
nextstep
=
1
,
loop
=
1
,
condition
=
SPCSEQ_ENDLOOPONTRIG
)
awg
.
configure_step
(
step
=
1
,
segment
=
1
,
nextstep
=
0
,
loop
=
1
,
condition
=
SPCSEQ_ENDLOOPONTRIG
)
start
()
# console
vars
=
globals
()
...
...
@@ -54,4 +109,3 @@ vars.update(locals())
readline
.
set_completer
(
rlcompleter
.
Completer
(
vars
).
complete
)
readline
.
parse_and_bind
(
"
tab: complete
"
)
code
.
InteractiveConsole
(
vars
).
interact
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment