From 2697cfd38729be6bdf8d8b611b38c42dad4a2a25 Mon Sep 17 00:00:00 2001 From: Tristan Pinsonneault-Marotte Date: Fri, 17 May 2024 10:25:13 -0700 Subject: [PATCH] fix(client.command.cryo_card): Catch EPICS timeout on read and retry. Also adds a timeout between retries and logging capability. --- python/pysmurf/client/base/base_class.py | 3 ++- python/pysmurf/client/command/cryo_card.py | 24 +++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/python/pysmurf/client/base/base_class.py b/python/pysmurf/client/base/base_class.py index e702ef43a..69a9f08e0 100644 --- a/python/pysmurf/client/base/base_class.py +++ b/python/pysmurf/client/base/base_class.py @@ -181,7 +181,8 @@ def __init__(self, log=None, epics_root=None, offline=False, self.timing_status = self.amctiming + 'TimingFrameRx:' self.C = CryoCard(self.rtm_spi_cryo_root + 'read', - self.rtm_spi_cryo_root + 'write') + self.rtm_spi_cryo_root + 'write', + log=self.log) self.freq_resp = {} # RTM slow DAC parameters (used, e.g., for TES biasing). The diff --git a/python/pysmurf/client/command/cryo_card.py b/python/pysmurf/client/command/cryo_card.py index 7ef9d9b4a..bef8dfdf9 100644 --- a/python/pysmurf/client/command/cryo_card.py +++ b/python/pysmurf/client/command/cryo_card.py @@ -17,6 +17,8 @@ import time import os +from ..base.logger import SmurfLogger + try: import epics except ModuleNotFoundError: @@ -30,7 +32,7 @@ def write_csv(filename, header, line): f.write(line+'\n') class CryoCard(): - def __init__(self, readpv_in, writepv_in): + def __init__(self, readpv_in, writepv_in, log=None): """ Interact with the cryocard via the PIC. To interact via the RTM, use SmurfCommandMixin. Needs to be compatible with the C02 and C04 cryocards. @@ -54,12 +56,16 @@ def __init__(self, readpv_in, writepv_in): self.temperature_offset =.25 self.bias_scale = 1.0 self.max_retries = 5 #number of re-tries waiting for response + self.timeout = 5 # timeout in between retries self.retry = 0 # counts nubmer of retries self.busy_retry = 0 # counts number of retries due to relay busy status self.list_of_c02_amps = ['50k', 'hemt'] self.list_of_c04_amps = ['50k1', '50k2', 'hemt1', 'hemt2'] self.list_of_c02_and_c04_amps = self.list_of_c02_amps + self.list_of_c04_amps + # basic logging capacity + self.log = SmurfLogger() if log is None else log + def do_read(self, address, use_monitor=False): r"""Writes query to cryostat card PIC and reads reply. @@ -83,14 +89,18 @@ def do_read(self, address, use_monitor=False): self.writepv.put(cmd_make(1, address, 0)) for self.retry in range(0, self.max_retries): self.writepv.put(cmd_make(1, address, 0)) - data = self.readpv.get(use_monitor=use_monitor) - addrrb = cmd_address(data) - if (addrrb == address): - return (data) + data = self.readpv.get(use_monitor=use_monitor, timeout=self.timeout) + if data is None: + self.log(f"CryoCard.do_read: EPICS PV timed out after {self.timeout}s.") + else: + addrrb = cmd_address(data) + if (addrrb == address): + return (data) + self.log( + f"CryoCard.do_read failed, retry {self.retry + 1} / {self.max_retries}." + ) return (0) - return (self.readpv.get(use_monitor=use_monitor)) - def do_write(self, address, value): """Write the given value directly to the address on the PIC. Make sure you know if the value should be base-16, base-10, or base-2. There are