Commit a8135713 authored by Peter Jansweijer's avatar Peter Jansweijer

upgraded to python 3.6

parent 4cab2cc1
......@@ -108,15 +108,15 @@ def timeout(func, args=(), kwargs={}, timeout_duration=1, default=None):
###############################################
def wr2wrpc(ser, cmd, prompt="slv=>"):
ser.write("\r")
ser.write(bytes("\r", 'utf-8'))
time.sleep (0.1)
ser.flushInput()
for i in range(len(cmd)):
ser.write(cmd[i])
ser.write(bytes(cmd[i], 'utf-8'))
time.sleep (0.1)
time.sleep (0.5)
ser.readline() # Readback command
ser.readline().decode('utf-8') # Readback command
print(prompt + cmd)
......@@ -172,7 +172,7 @@ def wait_for_track_phase(ser_slave):
crtt = 0
while not sync_phase: # First wait for "SYNC_PHASE" state
stat = ser_slave.readline() # Readback status line
stat = ser_slave.readline().decode('utf-8') # Readback status line
stat_lst = stat.split(' ') # split on spaces
#print("Waiting for SYNC_PHASE:")
......@@ -186,7 +186,7 @@ def wait_for_track_phase(ser_slave):
err_cnt = 0
while not track_phase: # then wait for "SYNC_PHASE" state
stat = ser_slave.readline() # Readback status line
stat = ser_slave.readline().decode('utf-8') # Readback status line
stat_lst = stat.split(' ') # split on spaces
#print("Waiting for TRACK_PHASE:")
......@@ -208,10 +208,10 @@ def wait_for_track_phase(ser_slave):
print("### retry ptp stop, start...")
# stop any pending ptp and restart
wr2wrpc(ser_slave,"ptp stop\r","slv=>")
print(ser_slave.readline())
print(ser_slave.readline().decode('utf-8'))
wr2wrpc(ser_slave,"ptp start\r","slv=>")
print(ser_slave.readline())
print(ser_slave.readline())
print(ser_slave.readline().decode('utf-8'))
print(ser_slave.readline().decode('utf-8'))
err_cnt = 0 # new attempt re-start counting errors
#break # break if not in "stat" output modus
else:
......@@ -234,7 +234,7 @@ def get_statusline(ser_slave):
stat_lst = []
while len(stat_lst) < 27: # Keep reading until
stat = ser_slave.readline() # Readback valid status line
stat = ser_slave.readline().decode('utf-8') # Readback valid status line
stat_lst = stat.split(' ') # split on spaces
return(stat_lst)
......@@ -369,24 +369,24 @@ if __name__ == "__main__":
# stop any pending ptp and or statistics output
wr2wrpc(ser_master,"stat off\r","mst=>")
print(ser_master.readline())
print(ser_master.readline().decode('utf-8'))
wr2wrpc(ser_slave,"stat off\r","slv=>")
print(ser_slave.readline())
print(ser_slave.readline().decode('utf-8'))
wr2wrpc(ser_slave,"ptp stop\r","slv=>")
# Set Master dTx = fixed delay (dTx+dRx), dRx = 0, alpha = 0
wr2wrpc(ser_tunable,"sfp erase\r",ser_tunable_str)
wr2wrpc(ser_tunable,"sfp add "+sfp_module_vendor_id+" "+str(fixed_delay_mst)+" 0 0\r",ser_tunable_str)
print(ser_tunable.readline())
print(ser_tunable.readline().decode('utf-8'))
wr2wrpc(ser_tunable,"sfp match\r",ser_tunable_str)
print(ser_tunable.readline())
print(ser_tunable.readline().decode('utf-8'))
# Set Slave dTx = fixed delay (dTx+dRx), dRx = 0, alpha = 0
wr2wrpc(ser_slave,"sfp erase\r","slv=>")
wr2wrpc(ser_slave,"sfp add "+vendor_id_slv+" "+str(fixed_delay_slv)+" 0 0\r","slv=>")
print(ser_slave.readline())
print(ser_slave.readline().decode('utf-8'))
wr2wrpc(ser_slave,"sfp match\r","slv=>")
print(ser_slave.readline())
print(ser_slave.readline().decode('utf-8'))
wr2wrpc(ser_tunable,"sfp sel_page2\r",ser_tunable_str)
......@@ -399,12 +399,12 @@ if __name__ == "__main__":
filename=output_dir+time.strftime(format("%y%m%d_%H_%M_%S"),timestamp)+"_insitu_alpha_scan"
print("save insitu_alpha_scan into file:",filename)
data_file = open(filename,"w")
data_file = open(filename,"wb")
data_file.write("#In Situ Alpha measurements\n")
data_file.write("#date:"+time.strftime(format("%d %b %Y"),timestamp)+"\n")
data_file.write("#time:"+time.strftime(format("%H:%M:%S"),timestamp)+"\n")
data_file.write("#sfp_channel, ITU channel, ITU wavelength, crtt [ps], drxm, drxs, fiber-spool-temp, wr-slave-temp\n")
data_file.write(("#In Situ Alpha measurements\n").encode())
data_file.write(("#date:"+time.strftime(format("%d %b %Y"),timestamp)+"\n").encode())
data_file.write(("#time:"+time.strftime(format("%H:%M:%S"),timestamp)+"\n").encode())
data_file.write(("#sfp_channel, ITU channel, ITU wavelength, crtt [ps], drxm, drxs, fiber-spool-temp, wr-slave-temp\n").encode())
# scan through selected wavelengths
for ch in numpy.arange(itu_channel_start,itu_channel_stop+0.5, itu_channel_increment):
......@@ -419,9 +419,10 @@ if __name__ == "__main__":
# select a wavelength
wr2wrpc(ser_tunable,"sfp wr_ch " + str(sfp_ch) + "\r",ser_tunable_str)
print(ser_tunable.readline())
print(ser_tunable.readline().decode('utf-8'))
wr2wrpc(ser_tunable,"sfp rd_ch\r",ser_tunable_str)
print(ser_tunable.readline())
print(ser_tunable.readline().decode('utf-8'))
restart = 0
while restart < restarts:
......@@ -454,7 +455,7 @@ if __name__ == "__main__":
else:
#stat_lst = []
#while len(stat_lst) < 27: # Keep reading until
# stat = ser_slave.readline() # Readback valid status line
# stat = ser_slave.readline().decode('utf-8') # Readback valid status line
# stat_lst = stat.split(' ') # split on spaces
#pdb.set_trace()
......@@ -472,7 +473,7 @@ if __name__ == "__main__":
curr_temp = float(stat_lst[stat_lst.index('temp:')+1])
crtt.append(curr_crtt)
if meas_number == 0: # first measurment loads bitslide check valiables
if meas_number == 0: # first measurement loads bitslide check valiables
check_drxm = curr_drxm
check_drxs = curr_drxs
meas_number = meas_number + 1
......@@ -501,8 +502,8 @@ if __name__ == "__main__":
if args.t != None: # open and configure Digital Multimeter with attached PT100
spool_temp =float(dmm.ask("MEAS:TEMP? FRTD"))
print("sfp_channel: ", sfp_ch ,"itu_channel: ", ch ,"crtt avarage over "+str(crtt_measurement)+" measurments: "+str(crtt_mean)+" fiber-spool temp: "+str(spool_temp))
data_file.write(str(sfp_ch)+", "+str(ch)+", "+str(wavelength)+", "+str(crtt_mean)+", "+str(curr_drxm)+", "+str(curr_drxs)+", "+str(spool_temp)+", "+str(curr_temp)+"\n")
print("sfp_channel: ", sfp_ch ,"itu_channel: ", ch ,"crtt average over "+str(crtt_measurement)+" measurements: "+str(crtt_mean)+" fiber-spool temp: "+str(spool_temp))
data_file.write((str(sfp_ch)+", "+str(ch)+", "+str(wavelength)+", "+str(crtt_mean)+", "+str(curr_drxm)+", "+str(curr_drxs)+", "+str(spool_temp)+", "+str(curr_temp)+"\n").encode())
except:
print ("### exception during crtt_measurements.")
......
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