##// END OF EJS Templates
imanay -
r235:236
parent child
Show More
@@ -1,110 +1,110
1 import library3
1 import library3
2 import os.path
2 import os.path
3
3
4 class ABSClient(object):
4 class ABSClient(object):
5
5
6 def __init__(self,ipSource="192.168.1.117", iDSource="Clnt_01", ipDestino="192.168.1.117", iDDestino = "CeCnMod", portDestino=7000):
6 def __init__(self,ipSource="192.168.1.117", iDSource="Clnt_01", ipDestino="192.168.1.117", iDDestino = "CeCnMod", portDestino=7000):
7
7
8 self.ipSource = ipSource
8 self.ipSource = ipSource
9 self.iDSource = iDSource
9 self.iDSource = iDSource
10 self.ipDestino = ipDestino
10 self.ipDestino = ipDestino
11 self.iDDestino = iDDestino
11 self.iDDestino = iDDestino
12 self.portDestino = portDestino
12 self.portDestino = portDestino
13
13
14 self.createObjects()
14 self.createObjects()
15
15
16 def createObjects(self):
16 def createObjects(self):
17
17
18 self.commObj = library3.TCPComm(self.ipSource, self.iDSource, self.ipDestino, self.iDDestino, self.portDestino)
18 self.commObj = library3.TCPComm(self.ipSource, self.iDSource, self.ipDestino, self.iDDestino, self.portDestino)
19 #self.wFiles = library3.FilesStuff()
19 #self.wFiles = library3.FilesStuff()
20
20
21 def __ConnectionWithCentralControl(self, cmd, data):
21 def __ConnectionWithCentralControl(self, cmd, data):
22
22
23 self.commObj.open_socket()
23 self.commObj.open_socket()
24 self.commObj.sendData(cmd = cmd, data = data, ipDestino = self.ipDestino)
24 self.commObj.sendData(cmd = cmd, data = data, ipDestino = self.ipDestino)
25 ipSource, ipDestino, cmd, output = self.commObj.waitData()
25 ipSource, ipDestino, cmd, output = self.commObj.waitData()
26 self.commObj.close_socket()
26 self.commObj.close_socket()
27
27
28 return output
28 return output
29
29
30 # def abs2ControlModuleFormatFile(self, filename):
30 # def abs2ControlModuleFormatFile(self, filename):
31 #
31 #
32 # #From matriz to control module format
32 # #From matriz to control module format
33 # self.wFiles.toCentralControlFormat(filename)
33 # self.wFiles.toCentralControlFormat(filename)
34 # FileName = "CentralControlFormat.txt"
34 # FileName = "CentralControlFormat.txt"
35 # F_Obj = open(FileName,"r")
35 # F_Obj = open(FileName,"r")
36 # FileList = F_Obj.readlines()
36 # FileList = F_Obj.readlines()
37 # F_Obj.close()
37 # F_Obj.close()
38 # FileStr = "".join(FileList)
38 # FileStr = "".join(FileList)
39 #
39 #
40 # return FileStr
40 # return FileStr
41
41
42 def sendFile(self, filename):
42 def sendFile(self, filename):
43
43
44 data = self.__readFile(filename)
44 data = self.__readFile(filename)
45 answer = self.__ConnectionWithCentralControl(cmd = "SNDF", data = data)
45 answer = self.__ConnectionWithCentralControl(cmd = "SNDF", data = data)
46 return answer
46 return answer
47
47
48 def readFile(self):
48 def readFile(self,filename):
49
49
50 data = "optional"
50 data = filename
51 file = self.__ConnectionWithCentralControl(cmd = "GETF", data = data)
51 file = self.__ConnectionWithCentralControl(cmd = "GETF", data = data)
52
52
53 return file
53 return file
54
54
55 def changeBeam(self, newBeam):
55 def changeBeam(self, newBeam):
56
56
57 answer = self.__ConnectionWithCentralControl(cmd = "CHGB", data = newBeam)
57 answer = self.__ConnectionWithCentralControl(cmd = "CHGB", data = newBeam)
58 return answer
58 return answer
59
59
60 def __writeFile(self, filename, data):
60 def __writeFile(self, filename, data):
61
61
62 fobj = open(filename,"w")
62 fobj = open(filename,"w")
63 fobj.writelines(data)
63 fobj.writelines(data)
64 fobj.close()
64 fobj.close()
65
65
66 def __readFile(self, filename):
66 def __readFile(self, filename):
67
67
68 fobj = open(filename,"r")
68 fobj = open(filename,"r")
69 listData = fobj.readlines()
69 listData = fobj.readlines()
70 fobj.close()
70 fobj.close()
71 tmp = "".join(listData)
71 tmp = "".join(listData)
72 #Adding filename to the begining of the data
72 #Adding filename to the begining of the data
73 newfilename = os.path.split(filename)[1]
73 newfilename = os.path.split(filename)[1]
74 #data = filename + '\n' + tmp
74 #data = filename + '\n' + tmp
75 data = newfilename + '\n' + tmp
75 data = newfilename + '\n' + tmp
76 return data
76 return data
77
77
78
78
79 def getControlModuleStatus(self, data):
79 def getControlModuleStatus(self, data):
80
80
81 bits = self.__ConnectionWithCentralControl(cmd = "ANST", data = data)
81 bits = self.__ConnectionWithCentralControl(cmd = "ANST", data = data)
82 #self.__writeFile("report.txt", data)
82 #self.__writeFile("report.txt", data)
83
83
84 print "Report:\n"
84 print "Report:\n"
85 print "======:\n"
85 print "======:\n"
86 print bits
86 print bits
87
87
88 def getControlModulePhase(self, opt, u = "50", pw = "10"):
88 def getControlModulePhase(self, opt, u = "50", pw = "10"):
89
89
90 if opt == '0':
90 if opt == '0':
91 data = self.__ConnectionWithCentralControl(cmd = "LWPH", data = u + '/' + pw + '/')
91 data = self.__ConnectionWithCentralControl(cmd = "LWPH", data = u + '/' + pw + '/')
92 elif opt == '1':
92 elif opt == '1':
93 data = self.__ConnectionWithCentralControl(cmd = "BGPH", data = u + '/' + pw + '/')
93 data = self.__ConnectionWithCentralControl(cmd = "BGPH", data = u + '/' + pw + '/')
94 elif opt == '2':
94 elif opt == '2':
95 data = self.__ConnectionWithCentralControl(cmd = "cBPH", data = u + '/' + pw + '/')
95 data = self.__ConnectionWithCentralControl(cmd = "cBPH", data = u + '/' + pw + '/')
96 else:
96 else:
97 data = self.__ConnectionWithCentralControl(cmd = "cLPH", data = u + '/' + pw + '/')
97 data = self.__ConnectionWithCentralControl(cmd = "cLPH", data = u + '/' + pw + '/')
98 # self.__writeFile("report.txt", data)
98 # self.__writeFile("report.txt", data)
99
99
100 def getConnectionStatus(self):
100 def getConnectionStatus(self):
101
101
102 data = self.__ConnectionWithCentralControl(cmd = "NTST", data = "none")
102 data = self.__ConnectionWithCentralControl(cmd = "NTST", data = "none")
103 self.__writeFile("connection_status.txt", data)
103 self.__writeFile("connection_status.txt", data)
104
104
105 if __name__ == '__main__':
105 if __name__ == '__main__':
106
106
107 filename = "experimento1.abs"
107 filename = "experimento1.abs"
108
108
109 absObj = ABSClient()
109 absObj = ABSClient()
110 print absObj.sendFile(filename)
110 print absObj.sendFile(filename)
@@ -1,28 +1,29
1
1
2 import optparse, os, sys
2 import optparse, os, sys
3
3
4 pathFile = os.path.dirname(os.path.abspath(__file__))
4 pathFile = os.path.dirname(os.path.abspath(__file__))
5 sys.path.append(os.path.split(pathFile)[0])
5 sys.path.append(os.path.split(pathFile)[0])
6
6
7 from bin.client3 import ABSClient
7 from bin.client3 import ABSClient
8
8
9 class readFile(object):
9 class readFile(object):
10
10
11 def __init__(self):
11 def __init__(self):
12 self.output = ""
12 self.output = ""
13
13
14 def execute(self):
14 def execute(self, filename):
15 absObj = ABSClient(ipDestino="10.10.20.27")
15 absObj = ABSClient(ipDestino="10.10.20.27")
16 self.output = absObj.readFile()
16 self.output = absObj.readFile(filename)
17
17
18 def getOutput(self):
18 def getOutput(self):
19 return self.output
19 return self.output
20
20
21 usage = "::::::::::::\n"
21 usage = "::::::::::::\n"
22
22
23 if __name__ == '__main__':
23 if __name__ == '__main__':
24
24
25 filename = "tres_apuntes.ab1"
25 app = readFile()
26 app = readFile()
26 app.execute()
27 app.execute(filename)
27
28
28 print app.output
29 print app.output
General Comments 0
You need to be logged in to leave comments. Login now