Skip to content

Commit 02febb6

Browse files
committed
fix #23: fix a problem when closing the device connection in the reader
The serial port is only closed in the XBee reader if the process has not been stopped and the serial port is still open. Signed-off-by: Ruben Moral <ruben.moral@digi.com>
1 parent c4a4c65 commit 02febb6

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

digi/xbee/devices.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,8 +1278,6 @@ def close(self):
12781278

12791279
if self._packet_listener is not None:
12801280
self._packet_listener.stop()
1281-
# Wait 100 ms before closing the port.
1282-
time.sleep(0.1)
12831281

12841282
if self._serial_port is not None and self._serial_port.isOpen():
12851283
self._serial_port.close()

digi/xbee/reader.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,13 @@ def run(self):
324324
# Execute all user callbacks.
325325
self.__execute_user_callbacks(read_packet, remote)
326326
except Exception as e:
327-
self.__xbee_device.serial_port.close()
328-
self._log.exception(e)
327+
if not self.__stop:
328+
self._log.exception(e)
329329
finally:
330-
self.__stop = True
330+
if not self.__stop:
331+
self.__stop = True
332+
if self.__serial_port.isOpen():
333+
self.__serial_port.close()
331334

332335
def stop(self):
333336
"""

0 commit comments

Comments
 (0)