changeset 3:62ffab79227e

Add example.py with pylab plotting example. Tested with the Tek 2024B.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 13 May 2009 17:08:41 +0930
parents adaff1c4fd6b
children 6b360c30eed6
files example.py usb488.py
diffstat 2 files changed, 31 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example.py	Wed May 13 17:08:41 2009 +0930
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+
+import usb488
+import matplotlib.pylab as pylab
+import numpy
+import time
+
+def main():
+    u = usb488.USB488Device()
+    print "Found device"
+
+    u.write("*IDN?")
+    print "ID is..",
+    print 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()
+    data = result[13:]		# Chop off the header
+    dattype = numpy.dtype('>h')	# Big endian 16 bit quantity
+    ary = numpy.fromstring(data, dtype = dattype)
+    pylab.plot(ary)
+    pylab.show()
+    
+if __name__ == "__main__":
+    main()
--- a/usb488.py	Wed May 13 15:26:42 2009 +0930
+++ b/usb488.py	Wed May 13 17:08:41 2009 +0930
@@ -251,14 +251,4 @@
             result = result[0:-1]
 
         return result
-def main():
-    u = USB488Device()
-    print "Found device"
-
-    print "ID is.."
-    u.write("*IDN?")
-    print u.read()
     
-if __name__ == "__main__":
-    main()
-