diff --git a/enocean/communicators/serialcommunicator.py b/enocean/communicators/serialcommunicator.py index 6bc638d..4843547 100644 --- a/enocean/communicators/serialcommunicator.py +++ b/enocean/communicators/serialcommunicator.py @@ -39,7 +39,7 @@ def run(self): try: self.parse() except Exception as e: - self.logger.error('Exception occured while parsing: ' + str(e)) + self.logger.exception('Exception occured while parsing: ') time.sleep(0) self.__ser.close() diff --git a/enocean/protocol/packet.py b/enocean/protocol/packet.py index 14fdc34..cdf5f32 100644 --- a/enocean/protocol/packet.py +++ b/enocean/protocol/packet.py @@ -149,18 +149,21 @@ def parse_msg(buf): return PARSE_RESULT.CRC_MISMATCH, buf, None # If we got this far, everything went ok (?) - if packet_type == PACKET.RADIO_ERP1: - # Need to handle UTE Teach-in here, as it's a separate packet type... - if data[0] == RORG.UTE: - packet = UTETeachInPacket(packet_type, data, opt_data) + try: + if packet_type == PACKET.RADIO_ERP1: + # Need to handle UTE Teach-in here, as it's a separate packet type... + if data[0] == RORG.UTE: + packet = UTETeachInPacket(packet_type, data, opt_data) + else: + packet = RadioPacket(packet_type, data, opt_data) + elif packet_type == PACKET.RESPONSE: + packet = ResponsePacket(packet_type, data, opt_data) + elif packet_type == PACKET.EVENT: + packet = EventPacket(packet_type, data, opt_data) else: - packet = RadioPacket(packet_type, data, opt_data) - elif packet_type == PACKET.RESPONSE: - packet = ResponsePacket(packet_type, data, opt_data) - elif packet_type == PACKET.EVENT: - packet = EventPacket(packet_type, data, opt_data) - else: - packet = Packet(packet_type, data, opt_data) + packet = Packet(packet_type, data, opt_data) + except IndexError: + return PARSE_RESULT.INCOMPLETE, buf, None return PARSE_RESULT.OK, buf, packet