From 8a8752f6b2dfcd813c86f45493f9044e81ee92d1 Mon Sep 17 00:00:00 2001 From: J-A-M Date: Mon, 18 Sep 2017 12:35:36 +0100 Subject: [PATCH] Updated serialcommunicator.py Fix to the issue where a serial port error will not be detected by the parent task Add code to prevent lockup in multi-threaded app, by yielding if there is no IO --- enocean/communicators/serialcommunicator.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/enocean/communicators/serialcommunicator.py b/enocean/communicators/serialcommunicator.py index 4475630..ffe4201 100644 --- a/enocean/communicators/serialcommunicator.py +++ b/enocean/communicators/serialcommunicator.py @@ -2,6 +2,7 @@ from __future__ import print_function, unicode_literals, division, absolute_import import logging import serial +import time from enocean.communicators.communicator import Communicator @@ -24,15 +25,19 @@ def run(self): packet = self._get_from_send_queue() if not packet: break - self.__ser.write(bytearray(packet.build())) + try: + self.__ser.write(bytearray(packet.build())) + except serial.SerialException: + self.stop() # Read chars from serial port as hex numbers try: self._buffer.extend(bytearray(self.__ser.read(16))) except serial.SerialException: self.logger.error('Serial port exception! (device disconnected or multiple access on port?)') - break + self.stop() self.parse() + time.sleep(0) self.__ser.close() self.logger.info('SerialCommunicator stopped')