diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-11-30 09:28:28 -0500 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-11-30 09:28:28 -0500 |
commit | 1940f9f4f0cd55267a5d208de65f8282996315f8 (patch) | |
tree | 3885c038e0e6fe39883316142fd87f91b2c3e252 | |
parent | 8ce6318636c98a2c051a9221d6509ca3f56bb224 (diff) | |
download | qolab-1940f9f4f0cd55267a5d208de65f8282996315f8.tar.gz qolab-1940f9f4f0cd55267a5d208de65f8282996315f8.zip |
simplification of the Scope reply parsing
-rw-r--r-- | scope.py | 58 |
1 files changed, 37 insertions, 21 deletions
@@ -18,22 +18,33 @@ class Scope(scpi.SCPIinstr): super().__init__(resource) class SDS1104x(Scope): + """ Siglent SDS1104x scope """ def __init__(self, resource): super().__init__(resource) self.resource.read_termination='\n' self.maxRequiredPoints = 1000; # desired number of points per channel, can return twice more + def response2numStr(self, strIn, firstSeparator=None, unit=None): + # A typical reply of Siglent is in the form 'TDIV 2.00E-08S' + # i.e. "<prefix><firstSeparator><numberString><unit> + # prefix='TDIV', firstSeparator=' ', numberString='2.00E-08', unit='S' + # this function parses the reply + spltStr = re.split(firstSeparator, strIn) + prefix = spltStr[0] + rstr = spltStr[1] + spltStr = re.split(unit, rstr) + numberString = spltStr[0] + unit = spltStr[1] + return (prefix, numberString, unit) + def mean(self, chNum): # get mean on a specific channel calculated by scope # PAVA stands for PArameter VAlue qstr = f'C{chNum}:PAVA? MEAN' rstr = self.query(qstr); # reply is in the form 'C1:PAVA MEAN,3.00E-02V' - spltStr = re.split(',', rstr) - rstr = spltStr[1] - spltStr = re.split('V', rstr) - rstr = spltStr[0] - return( float(rstr) ) + prefix, numberString, unit = self.response2numStr(rstr, firstSeparator=',', unit='V') + return(float(numberString)) def getAvailableNumberOfPoints(self, chNum): if chNum != 1 and chNum != 3: @@ -42,18 +53,14 @@ class SDS1104x(Scope): qstr = f'SAMPLE_NUM? C{chNum}' rstr = self.query(qstr) # reply is in the form 'SANU 7.00E+01pts' - spltStr = re.split(' ', rstr) - spltStr = re.split('pts', spltStr[1]) - rstr = spltStr[0] - return( int(float(rstr)) ) + prefix, numberString, unit = self.response2numStr(rstr, firstSeparator=' ', unit='pts') + return(int(float(numberString))) def getSampleRate(self): rstr = self.query('SAMPLE_RATE?'); # expected reply is like 'SARA 1.00E+09Sa/s' - spltStr = re.split(' ', rstr) - spltStr = re.split('Sa/s', spltStr[1]) - rstr = spltStr[0] - return( int(float(rstr)) ) + prefix, numberString, unit = self.response2numStr(rstr, firstSeparator=' ', unit='Sa/s') + return(int(float(numberString))) def getRawWaveform(self, chNum, availableNpnts=None, sampleRate=None, maxRequiredPoints=None): if availableNpnts == None: @@ -99,19 +106,23 @@ class SDS1104x(Scope): qstr = f'C{chNum}:VDIV?' rstr = self.query(qstr) # expected reply to query: 'C1:VDIV 1.04E+00V' - res = re.split(' ', rstr) - res = re.split('V', res[1]) - VoltsPerDiv = float(res[0]) - return(VoltsPerDiv) + prefix, numberString, unit = self.response2numStr(rstr, firstSeparator=' ', unit='V') + return(float(numberString)) def getChanOffset(self, chNum): qstr = f'C{chNum}:OFST?' rstr = self.query(qstr) # expected reply to query: 'C1:OFST -1.27E+00V' - res = re.split(' ', rstr) - res = re.split('V', res[1]) - VoltageOffset = float(res[0]) - return(VoltageOffset) + prefix, numberString, unit = self.response2numStr(rstr, firstSeparator=' ', unit='V') + return(float(numberString)) + + def getTimePerDiv(self): + qstr = f'TDIV?' + rstr = self.query(qstr) + # expected reply to query: 'TDIV 2.00E-08S' + prefix, numberString, unit = self.response2numStr(rstr, firstSeparator=' ', unit='S') + return(float(numberString)) + def getWaveform(self, chNum, availableNpnts=None, sampleRate=None, maxRequiredPoints=None): wfRaw = self.getRawWaveform(chNum, availableNpnts=availableNpnts, sampleRate=sampleRate, maxRequiredPoints=maxRequiredPoints) @@ -120,6 +131,10 @@ class SDS1104x(Scope): VoltsPerDiv = self.getChanVoltsPerDiv(chNum) return( wfRaw * VoltsPerDiv * vertDivOnScreen/250 -VoltageOffset ) + def getTimeTrace(self): + sampleRate = self.getSampleRate() + timePerDiv = self.getTimePerDiv() + if __name__ == '__main__': print("testing") @@ -131,6 +146,7 @@ if __name__ == '__main__': print(scope.mean(1)) print(scope.getAvailableNumberOfPoints(1)) print(scope.getSampleRate()) + print(scope.getTimePerDiv()) print(scope.getChanVoltsPerDiv(1)) print(scope.getChanOffset(1)) wf = scope.getWaveform(1) |