##// END OF EJS Templates
imanay -
r48:49
parent child
Show More
@@ -1,268 +1,268
1 # imports needed for the file convertion No newline at end of file
1 # imports needed for the file convertion
2 import os No newline at end of file
2 import os
3 import sys No newline at end of file
3 import sys
4 import time No newline at end of file
4 import time
5 import numpy as np No newline at end of file
5 import numpy as np
6 No newline at end of file
6
7 import library No newline at end of file
7 import library
8 No newline at end of file
8
9 class ABSClient: No newline at end of file
9 class ABSClient:
10 No newline at end of file
10
11 def __init__(self,ipSource="localhost", ipDestino="192.168.1.255", portDestino=7000): No newline at end of file
11 def __init__(self,ipSource="localhost", ipDestino="192.168.1.255", portDestino=7000):
12 No newline at end of file
12
13 self.ipSource = ipSource No newline at end of file
13 self.ipSource = ipSource
14 self.ipDestino = ipDestino No newline at end of file
14 self.ipDestino = ipDestino
15 self.portDestino = portDestino No newline at end of file
15 self.portDestino = portDestino
16 No newline at end of file
16
17 self.createObjects() No newline at end of file
17 self.createObjects()
18 No newline at end of file
18
19 def createObjects(self): No newline at end of file
19 def createObjects(self):
20 No newline at end of file
20
21 self.commObj = library.UDPComm(self.ipSource, self.ipDestino, self.portDestino) No newline at end of file
21 self.commObj = library.UDPComm(self.ipSource, self.ipDestino, self.portDestino)
22 No newline at end of file
22
23 def sendFile(self, filename): No newline at end of file
23 def sendFile(self, filename):
24 No newline at end of file
24
25 #From matriz to control module format No newline at end of file
25 #From matriz to control module format
26 self.FuncionMaestra_GeneraFormatoControlCentral(filename) No newline at end of file
26 self.FuncionMaestra_GeneraFormatoControlCentral(filename)
27 FileName = "FormatoControlCentral.txt" No newline at end of file
27 FileName = "FormatoControlCentral.txt"
28 F_Obj = open(FileName,"r") No newline at end of file
28 F_Obj = open(FileName,"r")
29 FileList = F_Obj.readlines() No newline at end of file
29 FileList = F_Obj.readlines()
30 F_Obj.close() No newline at end of file
30 F_Obj.close()
31 FileStr = "".join(FileList) No newline at end of file
31 FileStr = "".join(FileList)
32 data = FileStr No newline at end of file
32 data = FileStr
33 No newline at end of file
33
34 self.commObj.sendData(cmd="SNDF", data=data) No newline at end of file
34 self.commObj.sendData(cmd="SNDF", data=data)
35 self.commObj.waitData() No newline at end of file
35 self.commObj.waitData()
36 No newline at end of file
36
37 def changeBeam(self, newBeam): No newline at end of file
37 def changeBeam(self, newBeam):
38 No newline at end of file
38
39 self.commObj.sendData(cmd="CHGB", data=newBeam) No newline at end of file
39 self.commObj.sendData(cmd="CHGB", data=newBeam)
40 self.commObj.waitData() No newline at end of file
40 self.commObj.waitData()
41 No newline at end of file
41
42 def getStatus(self, data): No newline at end of file
42 def getStatus(self, data):
43 No newline at end of file
43
44 self.commObj.sendData(cmd="ANST", data = data) No newline at end of file
44 self.commObj.sendData(cmd="ANST", data = data)
45 self.commObj.waitData2() No newline at end of file
45 self.commObj.waitData2()
46 No newline at end of file
46
47 ########## No newline at end of file
47 ##########
48 No newline at end of file
48
49 def FuncionMaestra_GeneraFormatoControlCentral(self,archivo): No newline at end of file
49 def FuncionMaestra_GeneraFormatoControlCentral(self,archivo):
50 """ Funcion que genera un archivo para el control central""" No newline at end of file
50 """ Funcion que genera un archivo para el control central"""
51 No newline at end of file
51
52 # CarpetaDeTrabajo='/home/redes/ABS_Control_2012_09_24/Control_Module_v1_Client_09_24/' No newline at end of file
52 # CarpetaDeTrabajo='/home/redes/ABS_Control_2012_09_24/Control_Module_v1_Client_09_24/'
53 CarpetaDeTrabajo = os.getcwd() + '/' No newline at end of file
53 CarpetaDeTrabajo = os.getcwd() + '/'
54 #print CarpetaDeTrabajo No newline at end of file
54 #print CarpetaDeTrabajo
55 #CarpetaDeTrabajo='/home/redes/workspace/ABS_Client_v2/Debug/' No newline at end of file
55 #CarpetaDeTrabajo='/home/redes/workspace/ABS_Client_v2/Debug/'
56 No newline at end of file
56
57 def lst2string(lst): No newline at end of file
57 def lst2string(lst):
58 string='' No newline at end of file
58 string=''
59 for i in lst: No newline at end of file
59 for i in lst:
60 string=string+i No newline at end of file
60 string=string+i
61 return string No newline at end of file
61 return string
62 No newline at end of file
62
63 def string2lst(string): No newline at end of file
63 def string2lst(string):
64 lst = [] No newline at end of file
64 lst = []
65 for i in string: No newline at end of file
65 for i in string:
66 lst.append(i) No newline at end of file
66 lst.append(i)
67 return lst No newline at end of file
67 return lst
68 No newline at end of file
68
69 No newline at end of file
69
70 def file1(string, type): No newline at end of file
70 def file1(string, type):
71 lst = string2lst(archivo) No newline at end of file
71 lst = string2lst(archivo)
72 fin = -1 No newline at end of file
72 fin = -1
73 t = len(lst) No newline at end of file
73 t = len(lst)
74 for i in np.arange(-1,-t,-1): No newline at end of file
74 for i in np.arange(-1,-t,-1):
75 if lst[i]=='/': No newline at end of file
75 if lst[i]=='/':
76 fin=i No newline at end of file
76 fin=i
77 break No newline at end of file
77 break
78 if type == '1': No newline at end of file
78 if type == '1':
79 nombre2 = lst[fin+1:] No newline at end of file
79 nombre2 = lst[fin+1:]
80 nombre2[-1]='s' No newline at end of file
80 nombre2[-1]='s'
81 nombre2 = lst2string(nombre2) No newline at end of file
81 nombre2 = lst2string(nombre2)
82 return nombre2 No newline at end of file
82 return nombre2
83 if type == '2': No newline at end of file
83 if type == '2':
84 nombre2 = lst[fin+1:] No newline at end of file
84 nombre2 = lst[fin+1:]
85 nombre2[-1]='1' No newline at end of file
85 nombre2[-1]='1'
86 nombre2 = lst2string(nombre2) No newline at end of file
86 nombre2 = lst2string(nombre2)
87 return nombre2 No newline at end of file
87 return nombre2
88 No newline at end of file
88
89 No newline at end of file
89
90 def EliminaSaltoDeLinea(cadena): No newline at end of file
90 def EliminaSaltoDeLinea(cadena):
91 i = 0 No newline at end of file
91 i = 0
92 for elemento in cadena: No newline at end of file
92 for elemento in cadena:
93 if elemento =='\n' or elemento =='\r': No newline at end of file
93 if elemento =='\n' or elemento =='\r':
94 pass No newline at end of file
94 pass
95 else: No newline at end of file
95 else:
96 i=i+1 No newline at end of file
96 i=i+1
97 return cadena [:i] No newline at end of file
97 return cadena [:i]
98 No newline at end of file
98
99 def NumeroDeExperimentos(path): No newline at end of file
99 def NumeroDeExperimentos(path):
100 fichero1=open(path,'r') No newline at end of file
100 fichero1=open(path,'r')
101 cont=0 No newline at end of file
101 cont=0
102 for cadena in fichero1: No newline at end of file
102 for cadena in fichero1:
103 cont=cont+1 No newline at end of file
103 cont=cont+1
104 if cont==3: No newline at end of file
104 if cont==3:
105 nexp='' No newline at end of file
105 nexp=''
106 pos=0 No newline at end of file
106 pos=0
107 for elemento in cadena: No newline at end of file
107 for elemento in cadena:
108 pos=pos+1 No newline at end of file
108 pos=pos+1
109 if elemento=='=': No newline at end of file
109 if elemento=='=':
110 nexp=int(cadena[pos:]) No newline at end of file
110 nexp=int(cadena[pos:])
111 return nexp No newline at end of file
111 return nexp
112 fichero1.close() No newline at end of file
112 fichero1.close()
113 No newline at end of file
113
114 def Paridad(numero): No newline at end of file
114 def Paridad(numero):
115 if numero%2==0: return 'par' No newline at end of file
115 if numero%2==0: return 'par'
116 elif numero%2==1: return 'impar' No newline at end of file
116 elif numero%2==1: return 'impar'
117 No newline at end of file
117
118 def EvaluaCadena(cadena): No newline at end of file
118 def EvaluaCadena(cadena):
119 if len(cadena)>35: No newline at end of file
119 if len(cadena)>35:
120 if cadena[-1]=='$': No newline at end of file
120 if cadena[-1]=='$':
121 return cadena[-35:-2] No newline at end of file
121 return cadena[-35:-2]
122 elif cadena[-1]==']': No newline at end of file
122 elif cadena[-1]==']':
123 return cadena[-34:-1] No newline at end of file
123 return cadena[-34:-1]
124 else: No newline at end of file
124 else:
125 return None No newline at end of file
125 return None
126 No newline at end of file
126
127 def GuardaEnLista(path): No newline at end of file
127 def GuardaEnLista(path):
128 fichero=open(path,'r') No newline at end of file
128 fichero=open(path,'r')
129 lista=[] No newline at end of file
129 lista=[]
130 for cadena in fichero: No newline at end of file
130 for cadena in fichero:
131 cadena = EliminaSaltoDeLinea(cadena) No newline at end of file
131 cadena = EliminaSaltoDeLinea(cadena)
132 cadena = EvaluaCadena(cadena) No newline at end of file
132 cadena = EvaluaCadena(cadena)
133 if cadena != None: No newline at end of file
133 if cadena != None:
134 lista.append(cadena) No newline at end of file
134 lista.append(cadena)
135 fichero.close() No newline at end of file
135 fichero.close()
136 return lista No newline at end of file
136 return lista
137 No newline at end of file
137
138 def CreaFicherosPrevios(): No newline at end of file
138 def CreaFicherosPrevios():
139 vector = GuardaEnLista(archivo) No newline at end of file
139 vector = GuardaEnLista(archivo)
140 for i in range(1,NumeroDeExperimentos(archivo)+1): No newline at end of file
140 for i in range(1,NumeroDeExperimentos(archivo)+1):
141 fichero =open(CarpetaDeTrabajo+str(i)+'.txt','w') No newline at end of file
141 fichero =open(CarpetaDeTrabajo+str(i)+'.txt','w')
142 for j in range(0,16): No newline at end of file
142 for j in range(0,16):
143 fichero.write(vector[j+16*(i-1)]+'\n') No newline at end of file
143 fichero.write(vector[j+16*(i-1)]+'\n')
144 fichero.close() No newline at end of file
144 fichero.close()
145 No newline at end of file
145
146 def CapturaValoresEnArchivo(path,polarizacion='up'): No newline at end of file
146 def CapturaValoresEnArchivo(path,polarizacion='up'):
147 fichero =open(path,'r') No newline at end of file
147 fichero =open(path,'r')
148 cnt=0 No newline at end of file
148 cnt=0
149 lstup=[] No newline at end of file
149 lstup=[]
150 lstdw=[] No newline at end of file
150 lstdw=[]
151 for cadena in fichero: No newline at end of file
151 for cadena in fichero:
152 cnt=cnt+1 No newline at end of file
152 cnt=cnt+1
153 if cnt==5: No newline at end of file
153 if cnt==5:
154 su01=cadena[17:20] No newline at end of file
154 su01=cadena[17:20]
155 su02=cadena[21:24] No newline at end of file
155 su02=cadena[21:24]
156 su03=cadena[25:28] No newline at end of file
156 su03=cadena[25:28]
157 su04=cadena[29:32] No newline at end of file
157 su04=cadena[29:32]
158 if cnt==6: No newline at end of file
158 if cnt==6:
159 su05=cadena[17:20] No newline at end of file
159 su05=cadena[17:20]
160 su06=cadena[21:24] No newline at end of file
160 su06=cadena[21:24]
161 su07=cadena[25:28] No newline at end of file
161 su07=cadena[25:28]
162 su08=cadena[29:32] No newline at end of file
162 su08=cadena[29:32]
163 if cnt==7: No newline at end of file
163 if cnt==7:
164 su09=cadena[17:20] No newline at end of file
164 su09=cadena[17:20]
165 su10=cadena[21:24] No newline at end of file
165 su10=cadena[21:24]
166 su11=cadena[25:28] No newline at end of file
166 su11=cadena[25:28]
167 su12=cadena[29:32] No newline at end of file
167 su12=cadena[29:32]
168 if cnt==8: No newline at end of file
168 if cnt==8:
169 su13=cadena[17:20] No newline at end of file
169 su13=cadena[17:20]
170 su14=cadena[21:24] No newline at end of file
170 su14=cadena[21:24]
171 su15=cadena[25:28] No newline at end of file
171 su15=cadena[25:28]
172 su16=cadena[29:32] No newline at end of file
172 su16=cadena[29:32]
173 if cnt==13: No newline at end of file
173 if cnt==13:
174 sd01=cadena[17:20] No newline at end of file
174 sd01=cadena[17:20]
175 sd02=cadena[21:24] No newline at end of file
175 sd02=cadena[21:24]
176 sd03=cadena[25:28] No newline at end of file
176 sd03=cadena[25:28]
177 sd04=cadena[29:32] No newline at end of file
177 sd04=cadena[29:32]
178 if cnt==14: No newline at end of file
178 if cnt==14:
179 sd05=cadena[17:20] No newline at end of file
179 sd05=cadena[17:20]
180 sd06=cadena[21:24] No newline at end of file
180 sd06=cadena[21:24]
181 sd07=cadena[25:28] No newline at end of file
181 sd07=cadena[25:28]
182 sd08=cadena[29:32] No newline at end of file
182 sd08=cadena[29:32]
183 if cnt==15: No newline at end of file
183 if cnt==15:
184 sd09=cadena[17:20] No newline at end of file
184 sd09=cadena[17:20]
185 sd10=cadena[21:24] No newline at end of file
185 sd10=cadena[21:24]
186 sd11=cadena[25:28] No newline at end of file
186 sd11=cadena[25:28]
187 sd12=cadena[29:32] No newline at end of file
187 sd12=cadena[29:32]
188 if cnt==16: No newline at end of file
188 if cnt==16:
189 sd13=cadena[17:20] No newline at end of file
189 sd13=cadena[17:20]
190 sd14=cadena[21:24] No newline at end of file
190 sd14=cadena[21:24]
191 sd15=cadena[25:28] No newline at end of file
191 sd15=cadena[25:28]
192 sd16=cadena[29:32] No newline at end of file
192 sd16=cadena[29:32]
193 lstup=[su01,su02,su03,su04,su05,su06,su07,su08,su09,su10,su11,su12,su13,su14,su15,su16] No newline at end of file
193 lstup=[su01,su02,su03,su04,su05,su06,su07,su08,su09,su10,su11,su12,su13,su14,su15,su16]
194 lstdw=[sd01,sd02,sd03,sd04,sd05,sd06,sd07,sd08,sd09,sd10,sd11,sd12,sd13,sd14,sd15,sd16] No newline at end of file
194 lstdw=[sd01,sd02,sd03,sd04,sd05,sd06,sd07,sd08,sd09,sd10,sd11,sd12,sd13,sd14,sd15,sd16]
195 if polarizacion=='up': No newline at end of file
195 if polarizacion=='up':
196 return lstup No newline at end of file
196 return lstup
197 elif polarizacion=='dw': No newline at end of file
197 elif polarizacion=='dw':
198 return lstdw No newline at end of file
198 return lstdw
199 fichero.close() No newline at end of file
199 fichero.close()
200 No newline at end of file
200
201 def CreaFormatoFinal(): No newline at end of file
201 def CreaFormatoFinal():
202 ne=NumeroDeExperimentos(archivo) No newline at end of file
202 ne=NumeroDeExperimentos(archivo)
203 No newline at end of file
203
204 #nombre01 = file1(archivo,'1') No newline at end of file
204 #nombre01 = file1(archivo,'1')
205 nombre02 = file1(archivo,'2') No newline at end of file
205 nombre02 = file1(archivo,'2')
206 fichero=open(CarpetaDeTrabajo+'FormatoControlCentral.txt','w') No newline at end of file
206 fichero=open(CarpetaDeTrabajo+'FormatoControlCentral.txt','w')
207 fichero.write(nombre02+'\n') No newline at end of file
207 fichero.write(nombre02+'\n')
208 fichero.write(str(ne)+'\n') No newline at end of file
208 fichero.write(str(ne)+'\n')
209 for i in range(1,17): No newline at end of file
209 for i in range(1,17):
210 No newline at end of file
210
211 if i<10: No newline at end of file
211 if i<10:
212 nmod = '0'+str(i) No newline at end of file
212 nmod = '0'+str(i)
213 else: nmod = str(i) No newline at end of file
213 else: nmod = str(i)
214 No newline at end of file
214
215 No newline at end of file
215
216 fichero.write('S'+nmod+'\n') No newline at end of file
216 fichero.write('S'+nmod+'\n')
217 for j in range(1,ne+1): No newline at end of file
217 for j in range(1,ne+1):
218 ruta=CarpetaDeTrabajo+str(j)+'.txt' No newline at end of file
218 ruta=CarpetaDeTrabajo+str(j)+'.txt'
219 lu=CapturaValoresEnArchivo(ruta,polarizacion='up') No newline at end of file
219 lu=CapturaValoresEnArchivo(ruta,polarizacion='up')
220 ld=CapturaValoresEnArchivo(ruta,polarizacion='dw') No newline at end of file
220 ld=CapturaValoresEnArchivo(ruta,polarizacion='dw')
221 part1='' No newline at end of file
221 part1=''
222 part2='' No newline at end of file
222 part2=''
223 if lu[i-1]=='1.0': part1='000' No newline at end of file
223 if lu[i-1]=='1.0': part1='000'
224 if lu[i-1]=='2.0': part1='001' No newline at end of file
224 if lu[i-1]=='2.0': part1='001'
225 if lu[i-1]=='3.0': part1='010' No newline at end of file
225 if lu[i-1]=='3.0': part1='010'
226 if lu[i-1]=='0.0': part1='011' No newline at end of file
226 if lu[i-1]=='0.0': part1='011'
227 if lu[i-1]=='0.5': part1='100' No newline at end of file
227 if lu[i-1]=='0.5': part1='100'
228 if lu[i-1]=='1.5': part1='101' No newline at end of file
228 if lu[i-1]=='1.5': part1='101'
229 if lu[i-1]=='2.5': part1='110' No newline at end of file
229 if lu[i-1]=='2.5': part1='110'
230 if lu[i-1]=='3.5': part1='111' No newline at end of file
230 if lu[i-1]=='3.5': part1='111'
231 if ld[i-1]=='1.0': part2='000' No newline at end of file
231 if ld[i-1]=='1.0': part2='000'
232 if ld[i-1]=='2.0': part2='001' No newline at end of file
232 if ld[i-1]=='2.0': part2='001'
233 if ld[i-1]=='3.0': part2='010' No newline at end of file
233 if ld[i-1]=='3.0': part2='010'
234 if ld[i-1]=='0.0': part2='011' No newline at end of file
234 if ld[i-1]=='0.0': part2='011'
235 if ld[i-1]=='0.5': part2='100' No newline at end of file
235 if ld[i-1]=='0.5': part2='100'
236 if ld[i-1]=='1.5': part2='101' No newline at end of file
236 if ld[i-1]=='1.5': part2='101'
237 if ld[i-1]=='2.5': part2='110' No newline at end of file
237 if ld[i-1]=='2.5': part2='110'
238 if ld[i-1]=='3.5': part2='111' No newline at end of file
238 if ld[i-1]=='3.5': part2='111'
239 fichero.write(part1+part2+'\n') No newline at end of file
239 fichero.write(part1+part2+'\n')
240 fichero.write('------'+'\n') No newline at end of file
240 fichero.write('------'+'\n')
241 fichero.close() No newline at end of file
241 fichero.close()
242 No newline at end of file
242
243 def EliminaArchivosEnLaCarpeta(): No newline at end of file
243 def EliminaArchivosEnLaCarpeta():
244 ne=NumeroDeExperimentos(archivo) No newline at end of file
244 ne=NumeroDeExperimentos(archivo)
245 for i in range(1,ne+1): No newline at end of file
245 for i in range(1,ne+1):
246 os.remove(CarpetaDeTrabajo+str(i)+'.txt') No newline at end of file
246 os.remove(CarpetaDeTrabajo+str(i)+'.txt')
247 No newline at end of file
247
248 CreaFicherosPrevios() No newline at end of file
248 CreaFicherosPrevios()
249 CreaFormatoFinal() No newline at end of file
249 CreaFormatoFinal()
250 EliminaArchivosEnLaCarpeta() No newline at end of file
250 EliminaArchivosEnLaCarpeta()
251 No newline at end of file
251
252 ########## No newline at end of file
252 ##########
253 No newline at end of file
253
254 if __name__ == '__main__': No newline at end of file
254 if __name__ == '__main__':
255 No newline at end of file
255
256 filename = "experimento1.abs" No newline at end of file
256 filename = "experimento1.abs"
257 No newline at end of file
257
258 absObj = ABSClient()
258 absObj = ABSClient()
No newline at end of file
259 absObj.sendFile(filename) No newline at end of file
259 # absObj.sendFile(filename) No newline at end of file
260 # absObj.changeBeam("0") No newline at end of file
260 # absObj.changeBeam("0")
261 # absObj.changeBeam("1")
261 # absObj.changeBeam("1")
No newline at end of file
262 # absObj.changeBeam("2") No newline at end of file
262 absObj.changeBeam("2") No newline at end of file
263 # absObj.changeBeam("3") No newline at end of file
263 # absObj.changeBeam("3")
264 # absObj.changeBeam("4") No newline at end of file
264 # absObj.changeBeam("4")
265 # absObj.changeBeam("5") No newline at end of file
265 # absObj.changeBeam("5")
266 # absObj.changeBeam("6") No newline at end of file
266 # absObj.changeBeam("6")
267 # absObj.changeBeam("7") No newline at end of file
267 # absObj.changeBeam("7")
268 # absObj.getStatus(5) No newline at end of file
268 # absObj.getStatus(5)
General Comments 0
You need to be logged in to leave comments. Login now