diff --git a/socs/agents/hwp_pcu/agent.py b/socs/agents/hwp_pcu/agent.py index 56157cd1d..aff2f6144 100644 --- a/socs/agents/hwp_pcu/agent.py +++ b/socs/agents/hwp_pcu/agent.py @@ -3,6 +3,7 @@ from dataclasses import dataclass from queue import Queue +import serial import txaio from twisted.internet import defer, reactor, threads @@ -116,20 +117,30 @@ def main(self, session, params): self.log.info('Connected to PCU') PCU.clear_buffer() self.log.info('Cleared buffer') - except ConnectionRefusedError: + except (ConnectionRefusedError, serial.serialutil.SerialException): self.log.error( "Could not connect to PCU. " "Retrying after 30 sec..." ) time.sleep(30) continue - now = time.time() - if now - last_daq > 5: - self._get_and_publish_data(PCU, session) - last_daq = now - - self._process_actions(PCU) - time.sleep(0.1) + try: + now = time.time() + if now - last_daq > 5: + self._get_and_publish_data(PCU, session) + last_daq = now + + self._process_actions(PCU) + session.degraded = False + time.sleep(0.1) + except serial.serialutil.SerialException: + self.log.error( + "Decive reports readiness to read but returned no data. " + "Reconnect to PCU." + ) + PCU.close() + PCU = None + session.degraded = True PCU.close()