From d7df64bb89541b31ccbd9c8e9e62c146d8f7e5e4 Mon Sep 17 00:00:00 2001 From: a Date: Sun, 21 Oct 2018 20:51:50 +1100 Subject: [PATCH 1/3] allow partial grab of internal buffer --- ds1054z/__init__.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ds1054z/__init__.py b/ds1054z/__init__.py index 18ddd50..d6ae0f0 100644 --- a/ds1054z/__init__.py +++ b/ds1054z/__init__.py @@ -178,7 +178,7 @@ def waveform_preamble_dict(self): keys = 'fmt, typ, pnts, cnt, xinc, xorig, xref, yinc, yorig, yref'.split(', ') return dict(zip(keys, self.waveform_preamble)) - def get_waveform_samples(self, channel, mode='NORMal'): + def get_waveform_samples(self, channel, mode='NORMal', start=0, end=250000): """ Returns the waveform voltage samples of the specified channel. @@ -204,7 +204,7 @@ def get_waveform_samples(self, channel, mode='NORMal'): :rtype: list of float values """ - buff = self.get_waveform_bytes(channel, mode=mode) + buff = self.get_waveform_bytes(channel, mode=mode, start=start, end=end) fmt, typ, pnts, cnt, xinc, xorig, xref, yinc, yorig, yref = self.waveform_preamble samples = list(struct.unpack(str(len(buff))+'B', buff)) samples = [(val - yorig - yref)*yinc for val in samples] @@ -217,7 +217,7 @@ def get_waveform_samples(self, channel, mode='NORMal'): samples = samples[:-num] + [float('nan')] * num return samples - def get_waveform_bytes(self, channel, mode='NORMal'): + def get_waveform_bytes(self, channel, mode='NORMal', start=0, end=250000): """ Get the waveform data for a specific channel as :py:obj:`bytes`. (In most cases you would want to use the higher level @@ -247,7 +247,7 @@ def get_waveform_bytes(self, channel, mode='NORMal'): if mode.upper().startswith('NORM') or (self.running and mode.upper().startswith('MAX')): return self._get_waveform_bytes_screen(channel, mode=mode) else: - return self._get_waveform_bytes_internal(channel, mode=mode) + return self._get_waveform_bytes_internal(channel, mode=mode, start=start, end=end) def _get_waveform_bytes_screen(self, channel, mode='NORMal'): """ @@ -297,7 +297,7 @@ def _get_waveform_bytes_screen(self, channel, mode='NORMal'): self.mask_begin_num = None return buff - def _get_waveform_bytes_internal(self, channel, mode='RAW'): + def _get_waveform_bytes_internal(self, channel, mode='RAW', start = 0, end = 250000): """ This function returns the waveform bytes from the scope if you desire to read the bytes corresponding to the internal (deep) memory. @@ -310,15 +310,16 @@ def _get_waveform_bytes_internal(self, channel, mode='RAW'): self.write(":WAVeform:FORMat BYTE") self.write(":WAVeform:MODE " + mode) wp = self.waveform_preamble_dict - pnts = wp['pnts'] + pnts = min(wp['pnts'],end - start) buff = b"" max_byte_len = 250000 - pos = 1 + pos = start while len(buff) < pnts: self.write(":WAVeform:STARt {0}".format(pos)) - end_pos = min(pnts, pos+max_byte_len-1) + end_pos = min(pos + pnts, pos+max_byte_len-1) self.write(":WAVeform:STOP {0}".format(end_pos)) tmp_buff = self.query_raw(":WAVeform:DATA?") + print len(tmp_buff) buff += DS1054Z.decode_ieee_block(tmp_buff) pos += max_byte_len return buff From e27c36afffdb1ef1a8bc52a542a64595f9316c08 Mon Sep 17 00:00:00 2001 From: a Date: Sun, 21 Oct 2018 20:52:48 +1100 Subject: [PATCH 2/3] clean up debug print --- ds1054z/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ds1054z/__init__.py b/ds1054z/__init__.py index d6ae0f0..2a16d8d 100644 --- a/ds1054z/__init__.py +++ b/ds1054z/__init__.py @@ -319,7 +319,6 @@ def _get_waveform_bytes_internal(self, channel, mode='RAW', start = 0, end = 250 end_pos = min(pos + pnts, pos+max_byte_len-1) self.write(":WAVeform:STOP {0}".format(end_pos)) tmp_buff = self.query_raw(":WAVeform:DATA?") - print len(tmp_buff) buff += DS1054Z.decode_ieee_block(tmp_buff) pos += max_byte_len return buff From 1e0411e55efa5702794506cd39e13ae4a685523a Mon Sep 17 00:00:00 2001 From: a Date: Sun, 21 Oct 2018 21:15:31 +1100 Subject: [PATCH 3/3] off-by-one fix --- ds1054z/__init__.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ds1054z/__init__.py b/ds1054z/__init__.py index 2a16d8d..5d0c705 100644 --- a/ds1054z/__init__.py +++ b/ds1054z/__init__.py @@ -178,7 +178,7 @@ def waveform_preamble_dict(self): keys = 'fmt, typ, pnts, cnt, xinc, xorig, xref, yinc, yorig, yref'.split(', ') return dict(zip(keys, self.waveform_preamble)) - def get_waveform_samples(self, channel, mode='NORMal', start=0, end=250000): + def get_waveform_samples(self, channel, mode='NORMal', start=1, end=None): """ Returns the waveform voltage samples of the specified channel. @@ -217,7 +217,7 @@ def get_waveform_samples(self, channel, mode='NORMal', start=0, end=250000): samples = samples[:-num] + [float('nan')] * num return samples - def get_waveform_bytes(self, channel, mode='NORMal', start=0, end=250000): + def get_waveform_bytes(self, channel, mode='NORMal', start=1, end=None): """ Get the waveform data for a specific channel as :py:obj:`bytes`. (In most cases you would want to use the higher level @@ -297,7 +297,7 @@ def _get_waveform_bytes_screen(self, channel, mode='NORMal'): self.mask_begin_num = None return buff - def _get_waveform_bytes_internal(self, channel, mode='RAW', start = 0, end = 250000): + def _get_waveform_bytes_internal(self, channel, mode='RAW', start = 1, end = None): """ This function returns the waveform bytes from the scope if you desire to read the bytes corresponding to the internal (deep) memory. @@ -310,15 +310,23 @@ def _get_waveform_bytes_internal(self, channel, mode='RAW', start = 0, end = 250 self.write(":WAVeform:FORMat BYTE") self.write(":WAVeform:MODE " + mode) wp = self.waveform_preamble_dict - pnts = min(wp['pnts'],end - start) + if end is None: + pnts = wp['pnts'] - start - 1# to account for len(buff) < pnts later + else: + pnts = min(wp['pnts'],end - start) buff = b"" max_byte_len = 250000 pos = start + # print "POINTS IS %d" % pnts while len(buff) < pnts: + # print "LEN(BUFF) is %d" % len(buff) self.write(":WAVeform:STARt {0}".format(pos)) + print ":WAVeform:STARt {0}".format(pos) end_pos = min(pos + pnts, pos+max_byte_len-1) self.write(":WAVeform:STOP {0}".format(end_pos)) + print ":WAVeform:STOP {0}".format(end_pos) tmp_buff = self.query_raw(":WAVeform:DATA?") + # print len(tmp_buff) buff += DS1054Z.decode_ieee_block(tmp_buff) pos += max_byte_len return buff