From 893f423aa9534e63dc7a310bfd3789180e01412c Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Tue, 30 Nov 2021 20:21:30 -0500 Subject: better trace handling --- scope.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/scope.py b/scope.py index 50d09b7..9bd2fe1 100644 --- a/scope.py +++ b/scope.py @@ -17,13 +17,27 @@ class Scope(scpi.SCPIinstr): def __init__(self, resource): super().__init__(resource) + # Minimal set of methods to be implemented by a scope. + # Should work with minimal arguments list + # but might be faster if parameters provided: less IO requests + + def getTrace(self, chNum, availableNpnts=None, maxRequiredPoints=None): + warnings.warn( 'this function is not implemented' ) + class Trace: - x = None - xlabel = 'time' - xunit = 'S' - y = None - ylabel = 'Voltage' - yunit = 'V' + def __init__(self, descrStr): + self.descr = descrStr + self.x = None + self.xlabel = None + self.xunit = None + self.y = None + self.ylabel = None + self.yunit = None + + def plot(self): + import matplotlib.pyplot as plt + plt.plot(self.x, self.y, label=self.descr) + plt.legend() class SDS1104x(Scope): """ Siglent SDS1104x scope """ @@ -171,10 +185,13 @@ class SDS1104x(Scope): def getTrace(self, chNum, availableNpnts=None, maxRequiredPoints=None): wfVoltage, availableNpnts = self.getWaveform( chNum, availableNpnts=availableNpnts, maxRequiredPoints=maxRequiredPoints) t = self.getTimeTrace(availableNpnts=availableNpnts, maxRequiredPoints=maxRequiredPoints) - tr = Trace() + tr = Trace( f'Ch{chNum}' ) + tr.xlabel = 'Time' + tr.xunit = 'S' + tr.ylabel = 'Voltage' + tr.yunit = 'V' tr.x = t tr.y = wfVoltage - tr.ylabel = f'Ch{chNum} Voltage' return( tr ) -- cgit v1.2.3