##// END OF EJS Templates
Client changes to return answer to the web page.
imanay -
r166:167
parent child
Show More
@@ -1,97 +1,99
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 self.__ConnectionWithCentralControl(cmd = "SNDF", data = data)
45 answer = self.__ConnectionWithCentralControl(cmd = "SNDF", data = data)
46 return answer
46
47
47 def changeBeam(self, newBeam):
48 def changeBeam(self, newBeam):
48
49
49 self.__ConnectionWithCentralControl(cmd = "CHGB", data = newBeam)
50 answer = self.__ConnectionWithCentralControl(cmd = "CHGB", data = newBeam)
51 return answer
50
52
51 def __writeFile(self, filename, data):
53 def __writeFile(self, filename, data):
52
54
53 fobj = open(filename,"w")
55 fobj = open(filename,"w")
54 fobj.writelines(data)
56 fobj.writelines(data)
55 fobj.close()
57 fobj.close()
56
58
57 def __readFile(self, filename):
59 def __readFile(self, filename):
58
60
59 fobj = open(filename,"r")
61 fobj = open(filename,"r")
60 listData = fobj.readlines()
62 listData = fobj.readlines()
61 fobj.close()
63 fobj.close()
62 tmp = "".join(listData)
64 tmp = "".join(listData)
63 #Adding filename to the begining of the data
65 #Adding filename to the begining of the data
64 newfilename = os.path.split(filename)[1]
66 newfilename = os.path.split(filename)[1]
65 #data = filename + '\n' + tmp
67 #data = filename + '\n' + tmp
66 data = newfilename + '\n' + tmp
68 data = newfilename + '\n' + tmp
67 return data
69 return data
68
70
69
71
70 def getControlModuleStatus(self, data):
72 def getControlModuleStatus(self, data):
71
73
72 data = self.__ConnectionWithCentralControl(cmd = "ANST", data = data)
74 data = self.__ConnectionWithCentralControl(cmd = "ANST", data = data)
73 self.__writeFile("report.txt", data)
75 self.__writeFile("report.txt", data)
74
76
75 def getControlModulePhase(self, opt, u = "50", pw = "10"):
77 def getControlModulePhase(self, opt, u = "50", pw = "10"):
76
78
77 if opt == '0':
79 if opt == '0':
78 data = self.__ConnectionWithCentralControl(cmd = "LWPH", data = u + '/' + pw + '/')
80 data = self.__ConnectionWithCentralControl(cmd = "LWPH", data = u + '/' + pw + '/')
79 elif opt == '1':
81 elif opt == '1':
80 data = self.__ConnectionWithCentralControl(cmd = "BGPH", data = u + '/' + pw + '/')
82 data = self.__ConnectionWithCentralControl(cmd = "BGPH", data = u + '/' + pw + '/')
81 elif opt == '2':
83 elif opt == '2':
82 data = self.__ConnectionWithCentralControl(cmd = "cBPH", data = u + '/' + pw + '/')
84 data = self.__ConnectionWithCentralControl(cmd = "cBPH", data = u + '/' + pw + '/')
83 else:
85 else:
84 data = self.__ConnectionWithCentralControl(cmd = "cLPH", data = u + '/' + pw + '/')
86 data = self.__ConnectionWithCentralControl(cmd = "cLPH", data = u + '/' + pw + '/')
85 # self.__writeFile("report.txt", data)
87 # self.__writeFile("report.txt", data)
86
88
87 def getConnectionStatus(self):
89 def getConnectionStatus(self):
88
90
89 data = self.__ConnectionWithCentralControl(cmd = "NTST", data = "none")
91 data = self.__ConnectionWithCentralControl(cmd = "NTST", data = "none")
90 self.__writeFile("connection_status.txt", data)
92 self.__writeFile("connection_status.txt", data)
91
93
92 if __name__ == '__main__':
94 if __name__ == '__main__':
93
95
94 filename = "experimento1.abs"
96 filename = "experimento1.abs"
95
97
96 absObj = ABSClient()
98 absObj = ABSClient()
97 absObj.sendFile(filename)
99 absObj.sendFile(filename)
General Comments 0
You need to be logged in to leave comments. Login now