Commit e9b57ed6 authored by Peter Jansweijer's avatar Peter Jansweijer

python scripts worked fine and need a commit

parent 7314add1
This diff is collapsed.
......@@ -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 = 18 # the index of item "crtt" in the "stat" output string
crtt_lst_idx = 17 # 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")
......
#!/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)
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