changeset 20:a124aa7067e7

Make ascdecode smarter so it can handle Anritsu ASCII.
author Daniel O'Connor <darius@dons.net.au>
date Thu, 11 Aug 2011 17:13:55 +0930
parents cba1c44060f5
children 6e7619f2dffd
files scpi.py
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/scpi.py	Thu Aug 11 17:11:58 2011 +0930
+++ b/scpi.py	Thu Aug 11 17:13:55 2011 +0930
@@ -58,9 +58,21 @@
         raise exceptions.ValueError('length mismatch, header says %d, actually got %d bytes' % (dlen + 2 + dlenlen, len(data)))
     return numpy.frombuffer(data[2 + dlenlen:], dtype = dtype)
 
-def ascdecode(data, dtype = numpy.float32):
+def ascdecode(data, dtype = numpy.float32, sep = None):
     '''Decode ASCII data, returns numpy array'''
 
     data = clean(data)
-    return numpy.fromstring(data, dtype = dtype, sep = ',')
+
+    # Strip length off if present as we don't need it
+    if data[0] == '#':
+        l = int(data[1])
+        data = data[l + 2:]
+
+    # Take a guess at the separator
+    if sep == None:
+        if data.find(',', 0, 20) != -1:
+            sep = ','
+        else:
+            sep = ' '
+    return numpy.fromstring(data, dtype = dtype, sep = sep)