From 843d942ee8aa84f38338a9058b45156ff3b17c54 Mon Sep 17 00:00:00 2001 From: Kyohei YAMADA <38639108+ykyohei@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:58:23 -0500 Subject: [PATCH] Improve robustness of hwp_pcu (#797) * attempt to improve robustness * fix * add exception * fix --- socs/agents/hwp_pcu/agent.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) 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()