From e0fb8e1ab81a7ab22d9f18dcda0590ee96102287 Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Fri, 26 Jul 2024 11:16:06 -0400 Subject: refactor basic scope and Rigol so the getTrace is now in the basic class --- qolab/hardware/scope/_basic.py | 51 +++++++++++++++++++++++++++++------- qolab/hardware/scope/rigolds1054z.py | 25 +----------------- 2 files changed, 43 insertions(+), 33 deletions(-) (limited to 'qolab/hardware') diff --git a/qolab/hardware/scope/_basic.py b/qolab/hardware/scope/_basic.py index d9905ce..eaab281 100644 --- a/qolab/hardware/scope/_basic.py +++ b/qolab/hardware/scope/_basic.py @@ -7,7 +7,7 @@ Created by Eugeniy E. Mikhailov 2021/11/29 import numpy as np from qolab.hardware.scpi import SCPIinstr from qolab.hardware.basic import BasicInstrument -from qolab.data.trace import TraceSetSameX +from qolab.data.trace import TraceSetSameX, TraceXY import time import logging @@ -83,17 +83,50 @@ class Scope(BasicInstrument): "VoltageOffset", } + def getWaveform( + self, chNum, availableNpnts=None, maxRequiredPoints=None, decimate=True + ): + """ + Get scope channel waveform where X axis is index and not time. + + Waveform MUST HAVE config dictionary with + ``trRaw.config["tags"]["rawChanConfig"]`` assigned + with items helping to calculate time trace + usually ``SampleRate``, ``Npnts``, ``sparsing``. + + For decimate use see ``getRawWaveform``. + + In short decimate=True is slower but more precise. + + """ + raise NotImplementedError("getWaveform function is not implemented") + + def getTimeTrace(self, rawChanCfg): + """Constructs time trace from properties provided in ``rawChanCfg`` dictionary.""" + raise NotImplementedError("getTimeTrace function is not implemented") + def getTrace( self, chNum, availableNpnts=None, maxRequiredPoints=None, decimate=True ): - # Should work with minimal arguments list - # but might be faster if parameters provided: less IO requests - # old_trg_mode = self.getTriggerMode() - # self.setTriggerMode('STOP'); # to get synchronous channels - raise NotImplementedError("getTrace function is not implemented") - # if old_trg_mode != "STOP": - # short speed up here with this check - # self.setTriggerMode(old_trg_mode) + old_run_status = self.getRun() + if old_run_status: # avoid unnecessary status change + self.setRun(False) # stop if currently running + self._waitUntillStop() + # to get synchronous channels + wfVoltage, rawChanCfg = self.getWaveform( + chNum, + availableNpnts=availableNpnts, + maxRequiredPoints=maxRequiredPoints, + decimate=decimate, + ) + t = self.getTimeTrace(rawChanCfg) + tr = TraceXY(f"Ch{chNum}") + tr.x = t + tr.y = wfVoltage + # restore scope to the before acquisition mode + if old_run_status: # avoid unnecessary status change + self.setRun(old_run_status) # start running if it was old run state + return tr def getTriggerMode(self): # we expect NORM, AUTO, SINGLE diff --git a/qolab/hardware/scope/rigolds1054z.py b/qolab/hardware/scope/rigolds1054z.py index 94eed25..598ad4a 100644 --- a/qolab/hardware/scope/rigolds1054z.py +++ b/qolab/hardware/scope/rigolds1054z.py @@ -5,7 +5,7 @@ Created by Eugeniy E. Mikhailov 2024/07/18 from qolab.hardware.basic import BasicInstrument from qolab.hardware.scpi import SCPI_PROPERTY from ._basic import ScopeSCPI, calcSparsingAndNumPoints -from qolab.data.trace import Trace, TraceXY +from qolab.data.trace import Trace import numpy as np import scipy.signal from pyvisa.errors import VisaIOError @@ -456,29 +456,6 @@ class RigolDS1054z(ScopeSCPI): tr.config["tags"]["VoltsPerDiv"] = VoltsPerDiv return (tr, rawChanCfg) - def getTrace( - self, chNum, availableNpnts=None, maxRequiredPoints=None, decimate=True - ): - old_run_status = self.getRun() - if old_run_status: # avoid unnecessary status change - self.setRun(False) # stop if currently running - self._waitUntillStop() - # to get synchronous channels - wfVoltage, rawChanCfg = self.getWaveform( - chNum, - availableNpnts=availableNpnts, - maxRequiredPoints=maxRequiredPoints, - decimate=decimate, - ) - t = self.getTimeTrace(rawChanCfg) - tr = TraceXY(f"Ch{chNum}") - tr.x = t - tr.y = wfVoltage - # restore scope to the before acquisition mode - if old_run_status: # avoid unnecessary status change - self.setRun(old_run_status) # start running if it was old run state - return tr - if __name__ == "__main__": import pyvisa -- cgit v1.2.3