diff scpi.py @ 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 20df02be818a
children e2833d081413
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)