HP3562A/trace_decoder.py

changeset 16
de9122b5680a
parent 14
07e2cbf140df
--- a/HP3562A/trace_decoder.py	Tue Dec 18 00:38:33 2007 +0100
+++ b/HP3562A/trace_decoder.py	Wed Dec 19 00:19:25 2007 +0100
@@ -10,7 +10,7 @@
 """
 import struct
 import numpy
-from HP3562A import format_header, decode_float, decode_string, decode_header
+from HP3562A import format_header, decode_float, decode_string, decode_header, read_trace
 from HP3562A.enum_types import *
 
 
@@ -61,7 +61,7 @@
            ('Start data value', decode_float, None, 8),
            ]
 
-def decode_trace(data):
+def decode_trace(data, idx=0):
     """
     Decode the data (as generated by the HP3562A DSA in response to a
     "DDBN" command), and returns a couple (header, values).
@@ -70,14 +70,8 @@
     value is a numpy array holding the trace (vector of float or
     complex values).
     """
-    header, idx = decode_header(data, HEADER)
-    resu = []
-    for i in range(header["Number of elements"]):
-        resu.append(decode_float(data[idx: idx+4]))
-        idx += 4
-    return header, numpy.array(resu, dtype=float)
-
-
+    header, idx = decode_header(data, HEADER, idx)
+    return header, read_trace(data, idx, header["Number of elements"])
 
 def main():
     import sys

mercurial