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