From 284af8f9c150a34dfdbd6696741465bd9d0e7c38 Mon Sep 17 00:00:00 2001 From: ykyohei <38639108+ykyohei@users.noreply.github.com> Date: Fri, 22 Nov 2024 07:37:42 -0500 Subject: [PATCH 1/4] attempt to improve robustness --- socs/agents/hwp_pcu/agent.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/socs/agents/hwp_pcu/agent.py b/socs/agents/hwp_pcu/agent.py index 56157cd1d..a9c48d58a 100644 --- a/socs/agents/hwp_pcu/agent.py +++ b/socs/agents/hwp_pcu/agent.py @@ -2,6 +2,7 @@ import time from dataclasses import dataclass from queue import Queue +import serial import txaio from twisted.internet import defer, reactor, threads @@ -123,13 +124,24 @@ def main(self, session, params): ) 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 after 30 sec..." + ) + PCU.close() + session.degraded = True + time.sleep(30) + continue PCU.close() From 923a772bdc328608eb259092672e52b105b225bf Mon Sep 17 00:00:00 2001 From: ykyohei <38639108+ykyohei@users.noreply.github.com> Date: Fri, 22 Nov 2024 07:53:51 -0500 Subject: [PATCH 2/4] fix --- socs/agents/hwp_pcu/agent.py | 1 + 1 file changed, 1 insertion(+) diff --git a/socs/agents/hwp_pcu/agent.py b/socs/agents/hwp_pcu/agent.py index a9c48d58a..2c023ecf9 100644 --- a/socs/agents/hwp_pcu/agent.py +++ b/socs/agents/hwp_pcu/agent.py @@ -139,6 +139,7 @@ def main(self, session, params): "Reconnect after 30 sec..." ) PCU.close() + PCU = None session.degraded = True time.sleep(30) continue From 1e6d34a55e109fc0dcb0346001fcfe95f1e1aa32 Mon Sep 17 00:00:00 2001 From: ykyohei <38639108+ykyohei@users.noreply.github.com> Date: Fri, 22 Nov 2024 12:32:06 -0300 Subject: [PATCH 3/4] add exception --- socs/agents/hwp_pcu/agent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/socs/agents/hwp_pcu/agent.py b/socs/agents/hwp_pcu/agent.py index 2c023ecf9..52dd4d241 100644 --- a/socs/agents/hwp_pcu/agent.py +++ b/socs/agents/hwp_pcu/agent.py @@ -2,8 +2,8 @@ import time from dataclasses import dataclass from queue import Queue -import serial +import serial import txaio from twisted.internet import defer, reactor, threads @@ -117,7 +117,7 @@ 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..." From 69aab842b830a27a6fc9ea6c55341ac884a10041 Mon Sep 17 00:00:00 2001 From: ykyohei <38639108+ykyohei@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:42:22 -0500 Subject: [PATCH 4/4] fix --- socs/agents/hwp_pcu/agent.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/socs/agents/hwp_pcu/agent.py b/socs/agents/hwp_pcu/agent.py index 52dd4d241..aff2f6144 100644 --- a/socs/agents/hwp_pcu/agent.py +++ b/socs/agents/hwp_pcu/agent.py @@ -136,13 +136,11 @@ def main(self, session, params): except serial.serialutil.SerialException: self.log.error( "Decive reports readiness to read but returned no data. " - "Reconnect after 30 sec..." + "Reconnect to PCU." ) PCU.close() PCU = None session.degraded = True - time.sleep(30) - continue PCU.close()