# SVN changeset patch # User imanay # Date 2013-02-27 22:50:03.447897 # Revision 102 Trying frame without semicolon. Index: trunk/absroot/source/abspy/abscontrol/client3.py =================================================================== diff --git a/trunk/absroot/source/abspy/abscontrol/client3.py b/trunk/absroot/source/abspy/abscontrol/client3.py --- a/trunk/absroot/source/abspy/abscontrol/client3.py (revision 101) +++ b/trunk/absroot/source/abspy/abscontrol/client3.py (revision 102) @@ -2,17 +2,19 @@ class ABSClient: - def __init__(self,ipSource="localhost", ipDestino="192.168.1.117", portDestino=7000): + def __init__(self,ipSource="192.168.1.117", iDSource="Clnt_01", ipDestino="192.168.1.117", iDDestino = "CeCnMod", portDestino=7000): self.ipSource = ipSource + self.iDSource = iDSource self.ipDestino = ipDestino + self.iDDestino = iDDestino self.portDestino = portDestino self.createObjects() def createObjects(self): - self.commObj = library3.TCPComm(self.ipSource, self.ipDestino, self.portDestino) + self.commObj = library3.TCPComm(self.ipSource, self.iDSource, self.ipDestino, self.iDDestino, self.portDestino) self.wFiles = library3.FilesStuff() def __ConnectionWithCentralControl(self, cmd, data): Index: trunk/absroot/source/abspy/abscontrol/library3.py =================================================================== diff --git a/trunk/absroot/source/abspy/abscontrol/library3.py b/trunk/absroot/source/abspy/abscontrol/library3.py --- a/trunk/absroot/source/abspy/abscontrol/library3.py (revision 101) +++ b/trunk/absroot/source/abspy/abscontrol/library3.py (revision 102) @@ -9,18 +9,20 @@ __HEADER = "JRO" __TYPE = "ABS" - def __init__(self, ipSource, ipDestino, portDestino, asServer=False): + def __init__(self, ipSource, iDSource, ipDestino, iDDestino, portDestino, asServer=False): self.ipSource = ipSource + self.iDSource = iDSource self.ipDestino = ipDestino + self.iDDestino = iDDestino self.portDestino = portDestino self.addr = (ipDestino,portDestino) self.sc = "none" self.answer = "none" #test self.asServer = False - self.len = 0 - self.crc = 0 + self.len = "000000" + self.crc = "0" self.openSocket(asServer) @@ -51,15 +53,23 @@ def waitData(self): if self.asServer == True: - trama_rx = self.waitAsServer() + trama_rx, l = self.waitAsServer() else: - trama_rx = self.waitAsClient() - - ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) + trama_rx, l = self.waitAsClient() + + ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx, l) return ipSource, ipDestino, cmd, data - - def waitAsServer(self, nbytes = 1024): + + def waitAsClient2(self, nbytes = 1024): + print "\nWaiting the server." + # Short data through ethernet + trama_rx = self.socket_c.recv(nbytes) + print "\nThis socket has received this data: " + str(trama_rx) + + return trama_rx + + def waitAsServer2(self, nbytes = 1024): print "\nWaiting some client." self.socket_c.listen(1) sc, addr = self.socket_c.accept() @@ -75,17 +85,42 @@ print "\nThis socket has received some data from: " + str(self.answer) - return trama_rx + return trama_rx + + def waitAsServer(self, nbytes = 1024): + print "\nWaiting some client." + self.socket_c.listen(1) + sc, addr = self.socket_c.accept() + self.sc = sc + self.answer = addr + # Big data through ethernet + cnt = 0; + first = 0; + trama_rx = "" + while True: + tmp = self.sc.recv(nbytes) + trama_rx = trama_rx + tmp + cnt = len(trama_rx) + if first == 0: + first = 1 + lng = int(trama_rx[20:26]) + if cnt == lng: + break + + print "\nThis socket has received some data from: " + str(self.answer) + + return trama_rx, lng def waitAsClient(self, nbytes = 1024): print "\nWaiting the server." # Short data through ethernet trama_rx = self.socket_c.recv(nbytes) + lng = int(trama_rx[20:26]) print "\nThis socket has received this data: " + str(trama_rx) - return trama_rx - - def sendData(self, cmd, data, ipDestino): + return trama_rx, lng + + def sendData2(self, cmd, data, ipDestino): trama_tx = self.__HEADER + ":" + self.__TYPE + ":" + str(self.ipSource) + ":" + str(ipDestino) + \ ":" + str(self.len) + ":" + str(cmd) + ":" + str(data) + ":" + str(self.crc) + ":" + "quit" @@ -94,6 +129,21 @@ self.SendAsServer(trama_tx) else: self.SendAsClient(ipDestino, trama_tx) + + def sendData(self, cmd, data, ipDestino): + + trama_tx = self.__HEADER + self.__TYPE + self.iDSource + \ + self.iDDestino + self.len + str(cmd) + str(data) + self.crc + + self.len = self.int2str(len(trama_tx)) + + trama_tx = self.__HEADER + self.__TYPE + self.iDSource + \ + self.iDDestino + self.len + str(cmd) + str(data) + self.crc + + if self.asServer == True: + self.SendAsServer(trama_tx) + else: + self.SendAsClient(ipDestino, trama_tx) def SendAsServer(self, trama_tx): @@ -107,7 +157,7 @@ self.socket_c.send(trama_tx) print "Sending message:[" + trama_tx + "] to: " + ipDestino - def __getTrama(self, trama): + def __getTrama2(self, trama): FrameList = trama.split(':') @@ -123,11 +173,41 @@ return ipSource, ipDestino, cmd, data + def __getTrama(self, trama, l): + + header = trama[0:3] + TypeOfInstrument = trama[3:6] + ipSource = trama[6:13] + ipDestino = trama[13:20] + len = trama[20:26] + cmd = trama[26:30] + ldata = l-31 + data = trama[30:30+ldata] + crc = trama[30+ldata:] + + return ipSource, ipDestino, cmd, data + def close_socket(self): self.socket_c.close() def open_socket(self): self.socket_c = socket.socket() + + def int2str(self, n): + + str_n = str(n) + l_n = len(str_n) + if l_n == 1: + str_n = "00000" + str_n + elif l_n == 2: + str_n = "0000" + str_n + elif l_n == 3: + str_n = "000" + str_n + elif l_n == 4: + str_n = "00" + str_n + elif l_n == 5: + str_n = "0" + str_n + return str_n class FilesStuff(): Index: trunk/absroot/source/abspy/abscontrol/server3.py =================================================================== diff --git a/trunk/absroot/source/abspy/abscontrol/server3.py b/trunk/absroot/source/abspy/abscontrol/server3.py --- a/trunk/absroot/source/abspy/abscontrol/server3.py (revision 101) +++ b/trunk/absroot/source/abspy/abscontrol/server3.py (revision 102) @@ -22,8 +22,8 @@ def createObjects(self): asServer = True - self.commServerObj = library3.TCPComm("Central_Control", self.ipDestino, self.portDestino, asServer) - self.commClientObj = library3.TCPComm("Central_Control", self.ipDestino2, self.portDestino2) + self.commServerObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino, "CnMod01", self.portDestino, asServer) + self.commClientObj = library3.TCPComm("Central_Control", "CeCnMod", self.ipDestino2, "CnMod01", self.portDestino2) def waitRequest(self):