Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to partially grab memory #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions ds1054z/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=1, end=None):
"""
Returns the waveform voltage samples of the specified channel.

Expand All @@ -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]
Expand All @@ -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=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
Expand Down Expand Up @@ -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'):
"""
Expand Down Expand Up @@ -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 = 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.
Expand All @@ -310,15 +310,23 @@ 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']
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 = 1
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))
end_pos = min(pnts, pos+max_byte_len-1)
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
Expand Down