Changeset 790 in ETALON for BPM/read_adc.py
- Timestamp:
- Aug 3, 2018, 2:44:23 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BPM/read_adc.py
r788 r790 1 1 import PyTango 2 2 import os 3 import time 3 4 from bpm_constants import * 4 5 from datetime import datetime … … 10 11 ##PyTango.Database().get_device_exported('/opt/libera/sbin/libera-ds libera-instrument1') 11 12 13 14 12 15 PyTango.ApiUtil.get_env_var("TANGO_HOST") 13 16 14 17 def initialise_bpm(bpm_name1, bpm_name2, bpm_name3, bpm_name4): 15 18 bpm_list = [] 16 if not(bpm_name1 is None): 17 bpm_list.append([bpm_name1,DeviceProxy("Maquette/diag/bpm1")]) 18 if not(bpm_name2 is None): 19 bpm_list.append([bpm_name2,DeviceProxy("Maquette/diag/bpm2")]) 20 if not(bpm_name3 is None): 21 bpm_list.append([bpm_name3,DeviceProxy("Maquette/diag/bpm3")]) 22 if not(bpm_name4 is None): 23 bpm_list.append([bpm_name4,DeviceProxy("Maquette/diag/bpm4")]) 24 for bpm in bpm_list: 25 bpm[1].SpEnable = True 26 bpm[1].Kx = 14136 27 bpm[1].Ky = 14136 28 bpm[1].SpThreshold = 200 29 bpm[1].SpNBefor = 1 30 bpm[1].SpNAfter = 25 19 successive_error = 0 20 while bpm_list == []: 21 try: 22 #print(successive_error) 23 successive_error += 1 24 #print("\n") 25 if not(bpm_name1 is None): 26 bpm_list.append([bpm_name1,DeviceProxy("Maquette/diag/bpm1")]) 27 if not(bpm_name2 is None): 28 bpm_list.append([bpm_name2,DeviceProxy("Maquette/diag/bpm2")]) 29 if not(bpm_name3 is None): 30 bpm_list.append([bpm_name3,DeviceProxy("Maquette/diag/bpm3")]) 31 if not(bpm_name4 is None): 32 bpm_list.append([bpm_name4,DeviceProxy("Maquette/diag/bpm4")]) 33 for bpm in bpm_list: 34 bpm[1].Fans = 6000 35 bpm[1].AdcLength = 50 36 bpm[1].SpEnable = True 37 bpm[1].Kx = 14136 38 bpm[1].Ky = 14136 39 bpm[1].SpThreshold = 200 40 bpm[1].SpNBefor = 1 41 bpm[1].SpNAfter = 20 42 except: 43 print("error of initialise bpm") 44 bpm_list = [] 45 if successive_error > 4: 46 raise 31 47 return(bpm_list) 32 48 33 49 34 #bpm_list = [DeviceProxy("Maquette/diag/bpm1"), DeviceProxy("Maquette/diag/bpm2"), DeviceProxy("Maquette/diag/bpm3")] # global list that containe data for each used BPM50 bpm_list = [DeviceProxy("Maquette/diag/bpm1"), DeviceProxy("Maquette/diag/bpm2"), DeviceProxy("Maquette/diag/bpm3")] # global list that containe data for each used BPM 35 51 #, DeviceProxy("Maquette/diag/bpm4")] 36 #bpm_list[1].Fans = 5000 52 #bpm_list[0].Fans = 2500 53 #print(bpm_list[0].get_attribute_list()) # give all the attribute of a bpm 54 #print(bpm_list[0].T2TrigCount) #give the trigger 55 #print(bpm_list[1].AdcLength) 37 56 38 57 def read_all_bpm(bpm_list): … … 57 76 58 77 59 def read_libera_and_write_2D(x_motor_step ,y_motor_step ,data_name_and_path, bpm_number, bpm, list_of_data): 78 def read_libera(bpm): 79 data_libera = [bpm[1].T2TrigCount,bpm[1].SpVa,bpm[1].SpVb,bpm[1].SpVc,bpm[1].SpVd,bpm[1].SpSum,bpm[1].SpX,bpm[1].SpY,bpm[1].T2TrigCount] 80 while data_libera[8] != data_libera[0]: 81 print("error trigger") 82 data_libera = [bpm[1].T2TrigCount,bpm[1].SpVa,bpm[1].SpVb,bpm[1].SpVc,bpm[1].SpVd,bpm[1].SpSum,bpm[1].SpX,bpm[1].SpY,bpm[1].T2TrigCount] 83 else: 84 return(data_libera) 85 86 #print(read_libera([3.1415,bpm_list[0]])) 87 88 def read_libera_and_write_2D(x_motor_step ,y_motor_step , # position of motor in step 89 data_name_and_path, 90 bpm_number, 91 bpm, #list that contain in 0 the name of the bpm, and in 1 the bpm davice on libera 92 list_of_data): # list of data what we will read 93 data_libera = [] 94 successive_error = 0 95 while data_libera == []: 96 try: 97 #print(successive_error) 98 successive_error += 1 99 #print("\n") 100 data_libera = read_libera(bpm) 101 except: 102 print("error of read libera") 103 data_libera = [] 104 if successive_error > 4: 105 raise 106 fichier = open(data_name_and_path, "a") 60 107 for data in list_of_data: 61 fichier = open(data_name_and_path, "a")62 108 if data == "bpm_name" : 63 109 fichier.write(bpm[0]) … … 65 111 elif data == "bpm_number" : 66 112 fichier.write(str(bpm_number)) 67 fichier.write(' ') 113 fichier.write(' ') 68 114 elif data == "x_motor_step" : 69 115 fichier.write(str(x_motor_step)) 70 fichier.write(' ') 116 fichier.write(' ') 71 117 elif data == "x_motor_mm" : 72 118 x_motor_mm = x_motor_step # will there isn't potentiometer, this value can't be read 73 119 fichier.write(str(x_motor_mm)) 74 fichier.write(' ') 120 fichier.write(' ') 75 121 elif data == "y_motor_step" : 76 122 fichier.write(str(y_motor_step)) 77 fichier.write(' ') 123 fichier.write(' ') 78 124 elif data == "y_motor_mm" : 79 #position = read_vertical_position()80 y_motor_mm = 0#position[0] # it's the number of the output of the optical rules125 position = read_vertical_position() 126 y_motor_mm = position[0] # it's the number of the output of the optical rules 81 127 fichier.write(str(y_motor_mm)) 82 fichier.write(' ') 128 fichier.write(' ') 83 129 elif data == "Va" : 84 fichier.write(str( bpm[1].SpVa))85 fichier.write(' ') 130 fichier.write(str(data_libera[1])) 131 fichier.write(' ') 86 132 elif data == "Vb" : 87 fichier.write(str( bpm[1].SpVb))88 fichier.write(' ') 133 fichier.write(str(data_libera[2])) 134 fichier.write(' ') 89 135 elif data == "Vc" : 90 fichier.write(str( bpm[1].SpVc))91 fichier.write(' ') 136 fichier.write(str(data_libera[3])) 137 fichier.write(' ') 92 138 elif data == "Vd" : 93 fichier.write(str( bpm[1].SpVd))94 fichier.write(' ') 139 fichier.write(str(data_libera[4])) 140 fichier.write(' ') 95 141 elif data == "Sum" : 96 fichier.write(str( bpm[1].SpSum))97 fichier.write(' ') 142 fichier.write(str(data_libera[5])) 143 fichier.write(' ') 98 144 elif data == "x_libera_mm" : 99 fichier.write(str( bpm[1].SpX))100 fichier.write(' ') 145 fichier.write(str(data_libera[6]/1000.)) #libera give value un micrometer, converted in millimeter 146 fichier.write(' ') 101 147 elif data == "y_libera_mm" : 102 fichier.write(str( bpm[1].SpY))148 fichier.write(str(data_libera[7]/1000.)) #libera give value un micrometer, we write value in mm 103 149 fichier.write(' ') 104 150 else: … … 115 161 list_of_data, #list of the name of the data that the program will read 116 162 bpm_list): #list of the bpm on which you need to read data with look like [["bpm_name1",bpm_DeviceProxy1],["bpm_name2",bpm_DeviceProxy2],...] 117 for bpm_number in range(len(bpm_list)):118 for i in range(statistic_number): #take a set of statistic_number times the data for one set of parameters163 for i in range(statistic_number): #take a set of statistic_number times the data for one set of parameters 164 for bpm_number in range(len(bpm_list)): 119 165 read_libera_and_write_2D(x_motor_step, y_motor_step,data_name_and_path, bpm_number, bpm_list[bpm_number], list_of_data) 120 166
Note: See TracChangeset
for help on using the changeset viewer.