merge
authored
Fri, 04 Jun 2010 17:36:11 +0200
changeset 564 464d470bdbd7
parent 563 c74a37d156df (diff)
parent 562 2c8f08f4f874 (current diff)
child 565 7b64350c1dd8
merge
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())
--- 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
--- 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
--- 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