diff options
author | Anthony LaTorre <devnull@localhost> | 2013-03-01 18:44:52 -0600 |
---|---|---|
committer | Anthony LaTorre <devnull@localhost> | 2013-03-01 18:44:52 -0600 |
commit | 1a460d45831755e734907b2cf8bdf6e042aebf07 (patch) | |
tree | a911b46f38a3dc546c87af4c103c423f40d70b51 /tektronix.py | |
parent | 51c9b29cac40f016ee1face47687978c9ea33993 (diff) | |
download | lecrunch-1a460d45831755e734907b2cf8bdf6e042aebf07.tar.gz lecrunch-1a460d45831755e734907b2cf8bdf6e042aebf07.tar.bz2 lecrunch-1a460d45831755e734907b2cf8bdf6e042aebf07.zip |
add ability to fetch waveforms in chunks when fastframe is turned on.
Diffstat (limited to 'tektronix.py')
-rw-r--r-- | tektronix.py | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/tektronix.py b/tektronix.py index d8129d6..3af4e5c 100644 --- a/tektronix.py +++ b/tektronix.py @@ -51,6 +51,9 @@ class TekScope(object): self.sock.connect((host,port)) def send(self, msg): + if not msg.endswith('\n'): + msg += '\n' + self.sock.sendall(msg) def recv(self): @@ -71,7 +74,7 @@ class TekScope(object): self.send(msg) - return self.recv() + return self.recv().strip() def set_sequence_mode(self): """Sets the oscilloscope in single acquisition mode.""" @@ -171,10 +174,22 @@ class TekScope(object): y = int(self.sock.recv(int(x[1]))) - waveform = np.fromstring(self.sock.recv(y),dtype) + buffer = '' + + while len(buffer) < y: + buffer += self.sock.recv(y-len(buffer)) + + waveform = np.fromstring(buffer,dtype) # messages end with a newline - assert self.sock.recv(1024) == '\n' + eom = self.sock.recv(1024) + + if eom != '\n': + print 'x = ', x + print 'y = ', y + print eom + + assert eom == '\n' self.send(header) @@ -243,16 +258,38 @@ if __name__ == '__main__': # enable single acquisition mode scope.set_sequence_mode() - for i in range(options.nevents): - print '\rsaving event: %i' % i, + scope.send('header 0\n') + + fastframe_state = int(scope.query('horizontal:fastframe:state?')) + fastframe_count = int(scope.query('horizontal:fastframe:count?')) + + #print 'fastframe_state = ', fastframe_state + + i = 0 + while i < options.nevents: + print '\rsaving event: %i' % (i+1), sys.stdout.flush() scope.acquire() + if fastframe_state: + n = min(fastframe_count,options.nevents-i) + else: + n = 1 + for channel in active_channels: dataset = f['channel%i' % channel] - dataset[i] = scope.get_waveform(channel, dataset.dtype) + data = scope.get_waveform(channel, dataset.dtype) + + if fastframe_state: + data = data.reshape((fastframe_count,-1)) + dataset[i:i+n] = data[:n] + else: + dataset[i] = data + + i += n + print elapsed = time.time() - t0 |