# HG changeset patch # User Daniel O'Connor # Date 1313048635 -34200 # Node ID a124aa7067e7f168c238b4b5128055f82d42cf00 # Parent cba1c44060f56816c1162c924f8aeda6629ef852 Make ascdecode smarter so it can handle Anritsu ASCII. diff -r cba1c44060f5 -r a124aa7067e7 scpi.py --- 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)