From 67cc970f4c5d03dee8d82ba018ebab9a2dc02ce4 Mon Sep 17 00:00:00 2001 From: "Travis F. Collins" Date: Wed, 15 May 2024 11:51:20 -0600 Subject: [PATCH] Add timeouts to instrument Signed-off-by: Travis F. Collins --- bench/common.py | 7 +++++-- bench/keysight/e36233a.py | 8 ++++++-- doc/requirements.txt | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bench/common.py b/bench/common.py index 41e87e6..565feaa 100644 --- a/bench/common.py +++ b/bench/common.py @@ -9,9 +9,11 @@ class Common: def __del__(self): """Close the instrument on object deletion""" - self._instr.close() + if hasattr(self, "_instr"): + self._instr.close() self.address = None - self._rm.close() + if hasattr(self, "_rm"): + self._rm.close() def _find_dev_ind(self, rm): all_resources = rm.list_resources() @@ -23,6 +25,7 @@ def _find_dev_ind(self, rm): common_log.info(f"Found {self.id} at {res}") self.address = res self._instr = rm.open_resource(self.address) + self._instr.timeout = 15000 return True return False diff --git a/bench/keysight/e36233a.py b/bench/keysight/e36233a.py index ef99f86..d8e99c2 100644 --- a/bench/keysight/e36233a.py +++ b/bench/keysight/e36233a.py @@ -98,8 +98,12 @@ def __init__(self, address: str = None) -> None: else: self.address = address self._instr = pyvisa.ResourceManager().open_resource(self.address) - if self._instr.query("*IDN?") != self.id: - raise Exception(f"Device at {self.address} is not a {self.id}") + self._instr.timeout = 15000 + q_id = self._instr.query("*IDN?") + if self.id not in q_id: + raise Exception( + f"Device at {self.address} is not a {self.id}. Got {q_id}" + ) self.ch1 = channel(self, 1) self.ch2 = channel(self, 2) diff --git a/doc/requirements.txt b/doc/requirements.txt index 7ac8041..52f485e 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -3,4 +3,4 @@ myst-parser sphinxcontrib-mermaid pillow furo -sphinx-remove-toctrees \ No newline at end of file +sphinx-remove-toctrees