source: ETALON/BPM/read_adc.py @ 790

Last change on this file since 790 was 790, checked in by moutardier, 6 years ago

code final version

File size: 7.0 KB
Line 
1import PyTango
2import os
3import time
4from bpm_constants import *
5from datetime import datetime
6import numpy as np
7from read_position import *
8from PyTango import DeviceProxy
9
10##os.system("gedit /home/thomx-util01/alex/libera_commamde.txt")
11##PyTango.Database().get_device_exported('/opt/libera/sbin/libera-ds libera-instrument1')
12
13
14
15PyTango.ApiUtil.get_env_var("TANGO_HOST")
16
17def initialise_bpm(bpm_name1, bpm_name2, bpm_name3, bpm_name4):
18    bpm_list = []
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
47    return(bpm_list)
48
49       
50bpm_list = [DeviceProxy("Maquette/diag/bpm1"), DeviceProxy("Maquette/diag/bpm2"), DeviceProxy("Maquette/diag/bpm3")] # global list that containe data for each used BPM
51#, DeviceProxy("Maquette/diag/bpm4")]
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)
56
57def read_all_bpm(bpm_list): 
58    for bpm in bpm_list:
59        print_value(bpm)
60
61
62def bpm_boucle(boucle_number,bpm):
63    for i in range(boucle_number):
64        print_value(bpm)
65
66       
67def print_value(bpm):
68    print("\n")
69    print("Va: ", bpm.SpVa)
70    print("Vb : ", bpm.SpVb)
71    print("Vc : ", bpm.SpVc)
72    print("Vd : ", bpm.SpVd)
73    print("Sum : ", bpm.SpSum)
74    print("X : ", bpm.SpX)
75    print("Y : ", bpm.SpY)   
76
77
78def 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   
88def 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")
107    for data in list_of_data:
108        if data == "bpm_name" :
109            fichier.write(bpm[0])
110            fichier.write(' ')
111        elif data == "bpm_number" :
112            fichier.write(str(bpm_number))
113            fichier.write(' ') 
114        elif data == "x_motor_step" :
115            fichier.write(str(x_motor_step))
116            fichier.write(' ') 
117        elif data == "x_motor_mm" :
118            x_motor_mm = x_motor_step # will there isn't potentiometer, this value can't be read
119            fichier.write(str(x_motor_mm))
120            fichier.write(' ') 
121        elif data == "y_motor_step" :
122            fichier.write(str(y_motor_step))
123            fichier.write(' ') 
124        elif data == "y_motor_mm" :
125            position = read_vertical_position()
126            y_motor_mm = position[0] # it's the number of the output of the optical rules
127            fichier.write(str(y_motor_mm))
128            fichier.write(' ') 
129        elif data == "Va" :
130            fichier.write(str(data_libera[1]))
131            fichier.write(' ') 
132        elif data == "Vb" :
133            fichier.write(str(data_libera[2]))
134            fichier.write(' ') 
135        elif data == "Vc" :
136            fichier.write(str(data_libera[3]))
137            fichier.write(' ') 
138        elif data == "Vd" :
139            fichier.write(str(data_libera[4]))
140            fichier.write(' ') 
141        elif data == "Sum" :
142            fichier.write(str(data_libera[5]))
143            fichier.write(' ') 
144        elif data == "x_libera_mm" :
145            fichier.write(str(data_libera[6]/1000.)) #libera give value un micrometer, converted in millimeter
146            fichier.write(' ') 
147        elif data == "y_libera_mm" :
148            fichier.write(str(data_libera[7]/1000.)) #libera give value un micrometer, we write value in mm
149            fichier.write(' ')
150        else:
151            print("unknow ask data named " + data)
152            fichier.write("nan")
153            fichier.write(' ')
154    fichier.write('\n')
155    fichier.close()
156
157
158def acquisition_libera(x_motor_step, y_motor_step, #coordinate of motor in step
159                       data_name_and_path, #name of the file in which you write data
160                       statistic_number, # nuber of repetition of taking data whith 1 set of parameter
161                       list_of_data, #list of the name of the data that the program will read
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],...]
163    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)):
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)
166
167                                   
168#print(acquisition_libera("test",3.1415))
169
170# to get Kx : bpm.kx
171# to write Kx : bpm.kx = 10000000
172                                     
173#x_motor_step = 3.1415
174#y_motor_step = 0
175#data_name_and_path = "blabla.txt"
176#statistic_number = 1
177#list_of_data = ["bpm_name","x_motor_step","x_motor_mm","y_motor_step","y_motor_mm","Va","Vb","Vc","Vd","Sum","x_libera_mm","y_libera_mm"]
178
179#bpm_name1 = "BPM_E"
180#bpm_name2 = "BPM_C"
181#bpm_list = initialise_bpm(bpm_name1, None,bpm_name2,None)
182
183#print(bpm_list)
184
185#acquisition_libera(x_motor_step, y_motor_step, data_name_and_path, statistic_number, list_of_data, bpm_list)
Note: See TracBrowser for help on using the repository browser.