From 61cda18308f600ad747db57ff8f8e15bbb11ca34 Mon Sep 17 00:00:00 2001 From: cgriffin Date: Wed, 9 Apr 2025 09:35:50 -0400 Subject: [PATCH 1/2] Add setup utility functions Add load_setup_file, and save_setup_file to load and save scope setups from a file Add store_setup, and recall_setup to store and save scope setups to on board memory --- .../oscilloscope/_tektronix_dpo4xxx.py | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/pythonequipmentdrivers/oscilloscope/_tektronix_dpo4xxx.py b/src/pythonequipmentdrivers/oscilloscope/_tektronix_dpo4xxx.py index 6d2d02a..628c817 100644 --- a/src/pythonequipmentdrivers/oscilloscope/_tektronix_dpo4xxx.py +++ b/src/pythonequipmentdrivers/oscilloscope/_tektronix_dpo4xxx.py @@ -815,3 +815,62 @@ def clear_annotation(self): Clear the current annotation """ self.write_resource("MESSAGE:CLEAR; STATE 0") + + def load_setup_file( + self, setup_path: Union[str, Path], timeout_seconds: float = 5 + ) -> None: + """ + Load a scope setup from a file and wait for the scope to complete the + reconfiguration + + Args: + setup_path (Union[str, Path]): path the the text file containing the setup + timeout_seconds (float, optional): Maximum time to wait for setup to + complete. Defaults to 5s. + """ + prev_timeout = self.timeout + self.timeout = timeout_seconds * 1000 + with open(Path(setup_path), "r") as f: + self.write_resource(f.read()) + self.query_resource("*OPC?") + self.timeout = prev_timeout + + def save_setup_file(self, setup_path: Union[str, Path]): + """ + Save a scope setup to a file + + Args: + setup_path (Union[str, Path]): path to the setup file + """ + with open(Path(setup_path), "w") as f: + setup_string = self.query_resource("SET?") + f.write(setup_string) + + def store_setup(self, setup_index: int): + """ + Store the current setup to one of the setup memory locations + + Args: + setup_index (int): setup memory location (1 to 10) + """ + if setup_index not in range(1, 10 + 1): + ValueError(f"{setup_index=} is not valid") + self.write_resource(f"*SAV {setup_index}") + + def recall_setup(self, setup_index: int, timeout_seconds: float = 5) -> None: + """ + Load a scope setup from a file and wait for the scope to complete the + reconfiguration + + Args: + setup_index (int): setup memory location (1 to 10) + timeout_seconds (float, optional): Maximum time to wait for setup to + complete. Defaults to 5s. + """ + if setup_index not in range(1, 10 + 1): + ValueError(f"{setup_index=} is not valid") + prev_timeout = self.timeout + self.timeout = timeout_seconds * 1000 + self.write_resource(f"*RCL {setup_index}") + self.query_resource("*OPC?") + self.timeout = prev_timeout From 877afb0e7b913388890b7f1244c33eef619fac7d Mon Sep 17 00:00:00 2001 From: cgriffin Date: Wed, 9 Apr 2025 09:36:46 -0400 Subject: [PATCH 2/2] Add missing type hints --- src/pythonequipmentdrivers/oscilloscope/_tektronix_dpo4xxx.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pythonequipmentdrivers/oscilloscope/_tektronix_dpo4xxx.py b/src/pythonequipmentdrivers/oscilloscope/_tektronix_dpo4xxx.py index 628c817..d0a0ff4 100644 --- a/src/pythonequipmentdrivers/oscilloscope/_tektronix_dpo4xxx.py +++ b/src/pythonequipmentdrivers/oscilloscope/_tektronix_dpo4xxx.py @@ -835,7 +835,7 @@ def load_setup_file( self.query_resource("*OPC?") self.timeout = prev_timeout - def save_setup_file(self, setup_path: Union[str, Path]): + def save_setup_file(self, setup_path: Union[str, Path]) -> None: """ Save a scope setup to a file @@ -846,7 +846,7 @@ def save_setup_file(self, setup_path: Union[str, Path]): setup_string = self.query_resource("SET?") f.write(setup_string) - def store_setup(self, setup_index: int): + def store_setup(self, setup_index: int) -> None: """ Store the current setup to one of the setup memory locations