connectors/LPC/LPCProto.py
changeset 571 427bf9130d12
parent 563 c74a37d156df
child 576 7fcdc0d3d8d9
--- a/connectors/LPC/LPCProto.py	Thu Feb 03 18:23:24 2011 +0100
+++ b/connectors/LPC/LPCProto.py	Thu Feb 17 10:11:04 2011 +0100
@@ -1,6 +1,7 @@
 import serial
 import exceptions
 from threading import Lock
+import time
 
 class LPCProtoError(exceptions.Exception):
         """Exception class"""
@@ -14,29 +15,45 @@
     def __init__(self, port, rate, timeout):
         # serialize access lock
         self.TransactionLock = Lock()
-        # 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()
-        # start with empty
+        if BMZ_DBG:
+            # Debugging serial stuff
+            self._serialPort = serial.Serial( port, rate, timeout = timeout, writeTimeout = timeout )
+            class myser:
+                def readline(self_):
+                    res = self._serialPort.readline() 
+                    print 'Recv :"', res, '"' 
+                    return res
+
+                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_, string):
+                    lstr=len(string)
+                    if lstr > 16:
+                        print "Send :", map(hex,map(ord,string[:16])), "[...]"
+                    else:
+                        print "Send :", map(hex,map(ord,string))
+                    return self._serialPort.write(string)
+                    # while len(string)>0:
+                    #     i = self._serialPort.write(string[:4096])
+                    #     print ".",
+                    #     string = string[i:]
+                    # print
+                    #return lstr
+                def flush(self_):
+                    return self._serialPort.flush()
+                def close(self_):
+                    self._serialPort.close()
+            self.serialPort = myser()
+        else:
+            # open serial port
+            self.serialPort = serial.Serial( port, rate, timeout = timeout )
+        # start with empty buffer
         self.serialPort.flush()
     
     def __del__(self):