client3.py
99 lines
| 3.2 KiB
| text/x-python
|
PythonLexer
|
r164 | import library3 | ||
import os.path | ||||
r75 | ||||
|
r164 | class ABSClient(object): | ||
r75 | ||||
r101 | def __init__(self,ipSource="192.168.1.117", iDSource="Clnt_01", ipDestino="192.168.1.117", iDDestino = "CeCnMod", portDestino=7000): | |||
r75 | ||||
self.ipSource = ipSource | ||||
r101 | self.iDSource = iDSource | |||
r75 | self.ipDestino = ipDestino | |||
r101 | self.iDDestino = iDDestino | |||
r75 | self.portDestino = portDestino | |||
self.createObjects() | ||||
def createObjects(self): | ||||
r101 | self.commObj = library3.TCPComm(self.ipSource, self.iDSource, self.ipDestino, self.iDDestino, self.portDestino) | |||
|
r164 | #self.wFiles = library3.FilesStuff() | ||
r75 | ||||
r89 | def __ConnectionWithCentralControl(self, cmd, data): | |||
self.commObj.open_socket() | ||||
self.commObj.sendData(cmd = cmd, data = data, ipDestino = self.ipDestino) | ||||
ipSource, ipDestino, cmd, output = self.commObj.waitData() | ||||
self.commObj.close_socket() | ||||
return output | ||||
r138 | # def abs2ControlModuleFormatFile(self, filename): | |||
# | ||||
# #From matriz to control module format | ||||
# self.wFiles.toCentralControlFormat(filename) | ||||
# FileName = "CentralControlFormat.txt" | ||||
# F_Obj = open(FileName,"r") | ||||
# FileList = F_Obj.readlines() | ||||
# F_Obj.close() | ||||
# FileStr = "".join(FileList) | ||||
# | ||||
# return FileStr | ||||
r89 | ||||
def sendFile(self, filename): | ||||
r141 | data = self.__readFile(filename) | |||
r166 | answer = self.__ConnectionWithCentralControl(cmd = "SNDF", data = data) | |||
return answer | ||||
r75 | ||||
def changeBeam(self, newBeam): | ||||
r166 | answer = self.__ConnectionWithCentralControl(cmd = "CHGB", data = newBeam) | |||
return answer | ||||
r75 | ||||
def __writeFile(self, filename, data): | ||||
fobj = open(filename,"w") | ||||
fobj.writelines(data) | ||||
fobj.close() | ||||
r138 | ||||
def __readFile(self, filename): | ||||
fobj = open(filename,"r") | ||||
listData = fobj.readlines() | ||||
fobj.close() | ||||
r141 | tmp = "".join(listData) | |||
#Adding filename to the begining of the data | ||||
|
r164 | newfilename = os.path.split(filename)[1] | ||
#data = filename + '\n' + tmp | ||||
data = newfilename + '\n' + tmp | ||||
r138 | return data | |||
r75 | ||||
r138 | ||||
r80 | def getControlModuleStatus(self, data): | |||
r75 | ||||
r89 | data = self.__ConnectionWithCentralControl(cmd = "ANST", data = data) | |||
r75 | self.__writeFile("report.txt", data) | |||
r127 | ||||
r146 | def getControlModulePhase(self, opt, u = "50", pw = "10"): | |||
r127 | ||||
r146 | if opt == '0': | |||
data = self.__ConnectionWithCentralControl(cmd = "LWPH", data = u + '/' + pw + '/') | ||||
elif opt == '1': | ||||
data = self.__ConnectionWithCentralControl(cmd = "BGPH", data = u + '/' + pw + '/') | ||||
elif opt == '2': | ||||
data = self.__ConnectionWithCentralControl(cmd = "cBPH", data = u + '/' + pw + '/') | ||||
else: | ||||
data = self.__ConnectionWithCentralControl(cmd = "cLPH", data = u + '/' + pw + '/') | ||||
r127 | # self.__writeFile("report.txt", data) | |||
r89 | ||||
r80 | def getConnectionStatus(self): | |||
r89 | data = self.__ConnectionWithCentralControl(cmd = "NTST", data = "none") | |||
r80 | self.__writeFile("connection_status.txt", data) | |||
r89 | ||||
r75 | if __name__ == '__main__': | |||
filename = "experimento1.abs" | ||||
absObj = ABSClient() | ||||
r80 | absObj.sendFile(filename) | |||