# HG changeset patch # User ed # Date 1275665771 -7200 # Node ID 464d470bdbd7b557f3db5224d32b5a90acbd4c06 # Parent c74a37d156df89aac61cdaab52c60f57b12d179b# Parent 2c8f08f4f8749f96add5174f10cd1957948eda66 merge diff -r 2c8f08f4f874 -r 464d470bdbd7 connectors/LPC/LPCAppObject.py --- a/connectors/LPC/LPCAppObject.py Fri Jun 04 17:04:25 2010 +0200 +++ b/connectors/LPC/LPCAppObject.py Fri Jun 04 17:36:11 2010 +0200 @@ -32,17 +32,6 @@ 115200, #speed 2) #timeout self.HandleSerialTransaction(IDLETransaction()) - - def HandleSerialTransaction(self, transaction): - if self.SerialConnection is not None: - try: - self.PLCStatus, res = self.SerialConnection.HandleTransaction(transaction) - return res - except LPCProtoError,e: - self.pluginsroot.logger.write_error(str(e)+"\n") - self.SerialConnection = None - self.PLCStatus = "Disconnected" - return None def StartPLC(self, debug=False): self.HandleSerialTransaction(STARTTransaction()) diff -r 2c8f08f4f874 -r 464d470bdbd7 connectors/LPC/LPCAppProto.py --- a/connectors/LPC/LPCAppProto.py Fri Jun 04 17:04:25 2010 +0200 +++ b/connectors/LPC/LPCAppProto.py Fri Jun 04 17:36:11 2010 +0200 @@ -15,7 +15,9 @@ if current_plc_status is not None: res = transaction.ExchangeData() else: - raise LPCProtoError("LPC transaction error - controller did not answer as expected") + raise LPCProtoError("controller did not answer as expected") + except Exception, e: + raise LPCProtoError("LPC transaction error : "+str(e)) finally: self.TransactionLock.release() return LPC_STATUS.get(current_plc_status,"Broken"), res diff -r 2c8f08f4f874 -r 464d470bdbd7 connectors/LPC/LPCObject.py --- a/connectors/LPC/LPCObject.py Fri Jun 04 17:04:25 2010 +0200 +++ b/connectors/LPC/LPCObject.py Fri Jun 04 17:36:11 2010 +0200 @@ -45,6 +45,7 @@ return res except LPCProtoError,e: self.pluginsroot.logger.write_error(str(e)+"\n") + self.SerialConnection.close() self.SerialConnection = None self.PLCStatus = "Disconnected" return None diff -r 2c8f08f4f874 -r 464d470bdbd7 connectors/LPC/LPCProto.py --- a/connectors/LPC/LPCProto.py Fri Jun 04 17:04:25 2010 +0200 +++ b/connectors/LPC/LPCProto.py Fri Jun 04 17:36:11 2010 +0200 @@ -17,25 +17,32 @@ # open serial port # self.serialPort = serial.Serial( port, rate, timeout = timeout ) # Debugging serial stuff - self._serialPort = serial.Serial( port, rate, timeout = timeout ) - class myser: - def read(self_,cnt): - res = self._serialPort.read(cnt) - if len(res) > 16: - print "Recv :", map(hex,map(ord,res[:16])), "[...]" - else: - print "Recv :", map(hex,map(ord,res)) - - return res - def write(self_, str): - if len(str) > 16: - print "Send :", map(hex,map(ord,str[:16])), "[...]" - else: - print "Send :", map(hex,map(ord,str)) - self._serialPort.write(str) - def flush(self_): - self._serialPort.flush() - self.serialPort = myser() + self.serialPort = serial.Serial( port, rate, timeout = timeout ) +# class myser: +# def read(self_,cnt): +# res = self._serialPort.read(cnt) +# if len(res) > 16: +# print "Recv :", map(hex,map(ord,res[:16])), "[...]" +# else: +# print "Recv :", map(hex,map(ord,res)) +# +# return res +# def write(self_, str): +# if len(str) > 16: +# print "Send :", map(hex,map(ord,str[:16])), "[...]" +# else: +# print "Send :", map(hex,map(ord,str)) +# self._serialPort.write(str) +# def flush(self_): +# self._serialPort.flush() +# self.serialPort = myser() # start with empty self.serialPort.flush() + def __del__(self): + if self.serialPort: + self.serialPort.close() + + def close(self): + self.serialPort.close() + self.serialPort = None