1313"""
1414from xbee .frame import APIFrame
1515from xbee .backend .base import XBeeBase as _XBeeBase
16+ from xbee .backend .base import TimeoutException as _TimeoutException
1617import threading
1718import time
1819
@@ -93,7 +94,7 @@ def run(self):
9394 if self ._error_callback :
9495 self ._error_callback (e )
9596
96- def wait_read_frame (self ):
97+ def wait_read_frame (self , timeout = None ):
9798 """
9899 wait_read_frame: None -> frame info dictionary
99100
@@ -102,10 +103,10 @@ def wait_read_frame(self):
102103 wait_read_frame attempts to parse the data contained within it
103104 and returns the resulting dictionary
104105 """
105- frame = self ._wait_for_frame ()
106+ frame = self ._wait_for_frame (timeout )
106107 return self ._split_response (frame .data )
107108
108- def _wait_for_frame (self ):
109+ def _wait_for_frame (self , timeout = None ):
109110 """
110111 _wait_for_frame: None -> binary data
111112
@@ -119,11 +120,17 @@ def _wait_for_frame(self):
119120 """
120121 frame = APIFrame (escaped = self ._escaped )
121122
123+ deadline = 0
124+ if timeout is not None and timeout > 0 :
125+ deadline = time .time () + timeout
126+
122127 while True :
123128 if self ._callback and not self ._thread_continue :
124129 raise ThreadQuitException
125130
126131 if self .serial .inWaiting () == 0 :
132+ if deadline and time .time () > deadline :
133+ raise _TimeoutException
127134 time .sleep (.01 )
128135 continue
129136
0 commit comments