diff example.py @ 5:51d1fc44a753

Add variable timeout for reads. Modify the example to use it & print how long curve takes.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 13 May 2009 17:17:01 +0930
parents 62ffab79227e
children 813e183cfd49
line wrap: on
line diff
--- a/example.py	Wed May 13 17:09:14 2009 +0930
+++ b/example.py	Wed May 13 17:17:01 2009 +0930
@@ -10,17 +10,17 @@
     print "Found device"
 
     u.write("*IDN?")
-    print "ID is..",
-    print u.read()
+    print "IDN reports " + u.read()
     
     u.write("DATA:ENC RIB")	# Big endian signed
     u.write("DATA:WIDTH 2")	# 2 bytes wide
     u.write("SELECT:CH1 ON")	# Turn channel 1 on
     u.write("DATA:SOURCE CH1")	# Set the curve source to channel 1
     u.write("CURVE?")		# Ask for the curve data
-    time.sleep(1)		# Wait for the data..
-    				# XXX: need some way of polling
-    result = u.read()
+    then = time.time()                            
+    result = u.read(1.0)	# Takes the CRO a while for this
+    now = time.time()
+    print "CURVE read took %f milliseconds" % ((now - then) * 1000.0)
     data = result[13:]		# Chop off the header
     dattype = numpy.dtype('>h')	# Big endian 16 bit quantity
     ary = numpy.fromstring(data, dtype = dattype)