annotate example.py @ 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
children 51d1fc44a753
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 #!/usr/bin/env python
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3 import usb488
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4 import matplotlib.pylab as pylab
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5 import numpy
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 import time
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
8 def main():
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9 u = usb488.USB488Device()
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10 print "Found device"
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
12 u.write("*IDN?")
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13 print "ID is..",
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 print u.read()
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16 u.write("DATA:ENC RIB") # Big endian signed
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 u.write("DATA:WIDTH 2") # 2 bytes wide
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 u.write("SELECT:CH1 ON") # Turn channel 1 on
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19 u.write("DATA:SOURCE CH1") # Set the curve source to channel 1
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20 u.write("CURVE?") # Ask for the curve data
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21 time.sleep(1) # Wait for the data..
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22 # XXX: need some way of polling
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23 result = u.read()
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24 data = result[13:] # Chop off the header
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25 dattype = numpy.dtype('>h') # Big endian 16 bit quantity
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26 ary = numpy.fromstring(data, dtype = dattype)
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27 pylab.plot(ary)
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28 pylab.show()
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30 if __name__ == "__main__":
62ffab79227e Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31 main()