3535
3636from threading import Lock , Condition , Thread
3737from IO import IODone
38- from Serial import Serial
38+ from SerialH import Serial
3939
4040SYNC_BYTE = Serial .HDLC_FLAG_BYTE
4141ESCAPE_BYTE = Serial .HDLC_CTLESC_BYTE
@@ -88,15 +88,17 @@ def run(self):
8888 #OK, kind of ugly. finishing the SerialSource (ThreadTask)
8989 # leads (ultimately) to an IODone exception coming up
9090 # through here. At this point, the thread should complete.
91- except IODone :
91+ except Exception , e :
9292 with self .prot .ackCV :
9393 self .prot .lastAck = None
9494 self .prot .ackCV .notify ()
9595 with self .prot .dataCV :
96+ self .prot .read_exception = e # storing exception to inform the other thread
9697 self .prot .lastData = None
9798 self .prot .dataCV .notify ()
9899 break
99100
101+
100102class SerialProtocol :
101103 def __init__ (self , ins , outs ):
102104 self .ins = ins
@@ -115,6 +117,7 @@ def __init__(self, ins, outs):
115117 self .ackCV = Condition (rxLock )
116118 self .lastData = None
117119 self .lastAck = None
120+ self .read_exception = None
118121
119122 #also a little ugly: can't start this thread until the
120123 # serial.Serial object has been opened. This should all be
@@ -125,7 +128,10 @@ def open(self):
125128
126129 def readPacket (self ):
127130 with self .dataCV :
131+ self .read_exception = None
128132 self .dataCV .wait ()
133+ if self .read_exception != None :
134+ raise self .read_exception # an exception from the other thread
129135 return self .lastData
130136
131137 def readFramedPacket (self ):
0 commit comments