Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
White Rabbit Calibration
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
White Rabbit Calibration
Commits
e9b57ed6
Commit
e9b57ed6
authored
Jun 14, 2017
by
Peter Jansweijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
python scripts worked fine and need a commit
parent
7314add1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
294 additions
and
191 deletions
+294
-191
analyze.py
sw/insitu_alpha/analyze.py
+212
-163
wr_serial.py
sw/insitu_alpha/wr_serial.py
+51
-24
itu_conversions.py
sw/lib/itu_conversions.py
+31
-4
No files found.
sw/insitu_alpha/analyze.py
View file @
e9b57ed6
This diff is collapsed.
Click to expand it.
sw/insitu_alpha/wr_serial.py
View file @
e9b57ed6
...
...
@@ -28,6 +28,7 @@ Usage:
Options:
-h --help Show this screen.
-s serial port, default: "/dev/ttyUSB1"
-o <dir> optional directory for output file storage, default: "data/"
-m <number> number of measurement cycles (default = 1 cyle is a sweep from
start to stop lambda)
...
...
@@ -80,6 +81,12 @@ def wait_for_track_phase(ser):
#print("Waiting for SYNC_PHASE:")
#print(stat_lst)
if
len
(
stat_lst
)
>=
27
:
print
(
stat_lst
[
6
])
if
"SYNC_PHASE"
in
stat_lst
[
6
]:
sync_phase
=
True
"""
if len(stat_lst) < 27:
print("### No sync_phase: retry ptp stop, start...")
# stop any pending ptp and restart
...
...
@@ -96,6 +103,9 @@ def wait_for_track_phase(ser):
if not sync_phase:
return(track_phase) # Return with False
"""
err_cnt
=
0
while
not
track_phase
:
# then wait for "SYNC_PHASE" state
stat
=
ser
.
readline
()
# Readback status line
...
...
@@ -104,20 +114,30 @@ def wait_for_track_phase(ser):
#print("Waiting for TRACK_PHASE:")
#print(stat_lst)
if
len
(
stat_lst
)
<
27
:
print
(
"### No track_phase: retry ptp stop, start..."
)
# stop any pending ptp and restart
wr2wrpc
(
ser
,
"ptp stop
\r
"
)
print
(
ser
.
readline
())
wr2wrpc
(
ser
,
"ptp start
\r
"
)
print
(
ser
.
readline
())
print
(
ser
.
readline
())
#break # break if not in "stat" output modus
err_cnt
=
err_cnt
+
1
print
(
"### No track_phase: attempt: "
+
str
(
err_cnt
)
+
"
\n
"
)
if
err_cnt
==
10
:
print
(
"### retry ptp stop, start..."
)
# stop any pending ptp and restart
wr2wrpc
(
ser
,
"ptp stop
\r
"
)
print
(
ser
.
readline
())
wr2wrpc
(
ser
,
"ptp start
\r
"
)
print
(
ser
.
readline
())
print
(
ser
.
readline
())
err_cnt
=
0
# new attempt re-start counting errors
#break # break if not in "stat" output modus
else
:
err_cnt
=
0
print
(
stat_lst
[
6
])
crtt_lst
=
stat_lst
[
crtt_lst_idx
]
.
split
(
":"
)
if
"TRACK_PHASE"
in
stat_lst
[
6
]:
track_phase
=
True
try
:
crtt_lst
=
stat_lst
[
crtt_lst_idx
]
.
split
(
":"
)
if
"TRACK_PHASE"
in
stat_lst
[
6
]:
track_phase
=
True
except
:
print
(
"### error occured while reading wr status."
)
continue
return
(
track_phase
)
...
...
@@ -132,6 +152,7 @@ Usage:
Options:
-h --help Show this screen.
-s serial port, default: "/dev/ttyUSB1"
-o <dir> optional directory for output file storage, default: "data/"
-m <number> number of measurement cycles (default = 1 cyle is a sweep from
start to stop lambda)
...
...
@@ -143,16 +164,18 @@ if __name__ == "__main__":
#arguments = docopt(__doc__,version='White Rabbit controled via serial port')
import
argparse
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"-serial"
,
default
=
"/dev/ttyUSB1"
)
parser
.
add_argument
(
"-output_dir"
,
default
=
"data"
)
parser
.
add_argument
(
"-measurements"
,
default
=
1
,
type
=
int
)
args
=
parser
.
parse_args
()
print
(
"Use Serail port: "
,
args
.
serial
)
print
(
"Output directory: "
,
args
.
output_dir
)
print
(
"Number of measuremnt cycles: "
,
args
.
measurements
)
#output_dir = "data"
#measurements = 1
crtt_lst_idx
=
1
8
# the index of item "crtt" in the "stat" output string
crtt_lst_idx
=
1
7
# the index of item "crtt" in the "stat" output string
# was 17, but is now 18 since wrpc-v4!
# add trailing slash if not present
...
...
@@ -191,7 +214,7 @@ if __name__ == "__main__":
ser
=
serial
.
Serial
()
ser
.
port
=
"/dev/ttyUSB1"
ser
.
port
=
args
.
serial
ser
.
baudrate
=
115200
ser
.
parity
=
serial
.
PARITY_NONE
ser
.
bytesize
=
serial
.
EIGHTBITS
...
...
@@ -264,19 +287,23 @@ if __name__ == "__main__":
if
not
track_phase
:
sys
.
exit
()
else
:
stat
=
ser
.
readline
()
# Readback status line
stat_lst
=
stat
.
split
(
' '
)
# split on spaces
curr_crtt_lst
=
stat_lst
[
crtt_lst_idx
]
.
split
(
":"
)
crtt
=
int
(
curr_crtt_lst
[
1
])
# crtt first value to take into account
for
i
in
range
(
10
):
# take mean value over 10
try
:
stat
=
ser
.
readline
()
# Readback status line
stat_lst
=
stat
.
split
(
' '
)
# split on spaces
stat_lst
=
stat
.
split
(
' '
)
# split on spaces
curr_crtt_lst
=
stat_lst
[
crtt_lst_idx
]
.
split
(
":"
)
curr_crtt
=
int
(
curr_crtt_lst
[
1
])
# Current crtt
crtt
=
int
(
round
((
crtt
+
curr_crtt
)
/
2
))
# add with moving average
print
(
"."
)
# print(".",end='') # <= python 3
crtt
=
int
(
curr_crtt_lst
[
1
])
# crtt first value to take into account
for
i
in
range
(
10
):
# take mean value over 10
stat
=
ser
.
readline
()
# Readback status line
stat_lst
=
stat
.
split
(
' '
)
# split on spaces
curr_crtt_lst
=
stat_lst
[
crtt_lst_idx
]
.
split
(
":"
)
curr_crtt
=
int
(
curr_crtt_lst
[
1
])
# Current crtt
crtt
=
int
(
round
((
crtt
+
curr_crtt
)
/
2
))
# add with moving average
print
(
curr_crtt
)
# print(".",end='') # <= python 3
except
:
print
(
"### error occured while reading wr status."
)
continue
print
(
"
\n
"
)
...
...
sw/lib/itu_conversions.py
View file @
e9b57ed6
#!/usr/bin/python
import
pdb
"""
Routines, that convert itu channel to wavelength and frequency
"""
c
=
299792458
# speed of light
############################################################################
def
itu_2_frequency
(
itu_channel
):
"""
converts the ITU channel number to frequency
converts the
<numpy.float64>
ITU channel number to frequency
"""
c
=
299792458
# speed of light
itu_frequency
=
(
190
+
(
itu_channel
/
10
))
*
1e12
return
(
itu_frequency
)
...
...
@@ -18,9 +21,33 @@ def itu_2_frequency(itu_channel):
############################################################################
def
itu_2_wavelength
(
itu_channel
):
"""
converts the ITU channel number to wavelength
converts the
<numpy.float64>
ITU channel number to wavelength
"""
c
=
299792458
# speed of light
itu_wavelength
=
(
c
/
itu_2_frequency
(
itu_channel
))
return
(
itu_wavelength
)
############################################################################
def
frequency_2_itu
(
frequency
):
"""
converts the <numpy.float64> frequency to ITU channel number
Note ITU channel number is rounded to one decimal to avoid long numbers
due to small rounding errors in the input frequency value
"""
itu_channel
=
((
frequency
/
1e12
)
-
190
)
*
10
itu_channel
=
round
(
itu_channel
,
1
)
# round to 1 decimal
return
(
itu_channel
)
############################################################################
def
wavelength_2_itu
(
wavelength
):
"""
converts the <numpy.float64> wavelength to ITU channel number
Note ITU channel number is rounded to one decimal to avoid long numbers
due to small rounding errors in the input wavelength value
"""
itu_channel
=
frequency_2_itu
(
c
/
wavelength
)
itu_channel
=
round
(
itu_channel
,
1
)
# round to 1 decimal
return
(
itu_channel
)
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