Mercurial > ~darius > hgwebdir.cgi > pyinst
annotate example.py @ 10:154dab1e474f
Use short form of handle which looks nicer..
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Sat, 16 May 2009 23:33:20 +0930 |
parents | 813e183cfd49 |
children |
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 |
7 | 3 # Copyright (c) 2009 |
4 # Daniel O'Connor <darius@dons.net.au>. All rights reserved. | |
5 # | |
6 # Redistribution and use in source and binary forms, with or without | |
7 # modification, are permitted provided that the following conditions | |
8 # are met: | |
9 # 1. Redistributions of source code must retain the above copyright | |
10 # notice, this list of conditions and the following disclaimer. | |
11 # 2. Redistributions in binary form must reproduce the above copyright | |
12 # notice, this list of conditions and the following disclaimer in the | |
13 # documentation and/or other materials provided with the distribution. | |
14 # | |
15 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
18 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE | |
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
25 # SUCH DAMAGE. | |
26 # | |
27 | |
3
62ffab79227e
Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
28 import usb488 |
62ffab79227e
Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
29 import matplotlib.pylab as pylab |
62ffab79227e
Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
30 import numpy |
62ffab79227e
Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
31 import time |
62ffab79227e
Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
32 |
62ffab79227e
Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
33 def main(): |
62ffab79227e
Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
34 u = usb488.USB488Device() |
62ffab79227e
Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
35 print "Found device" |
62ffab79227e
Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
36 |
62ffab79227e
Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
37 u.write("*IDN?") |
5
51d1fc44a753
Add variable timeout for reads.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
38 print "IDN reports " + u.read() |
3
62ffab79227e
Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
39 |
62ffab79227e
Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
40 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
|
41 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
|
42 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
|
43 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
|
44 u.write("CURVE?") # Ask for the curve data |
5
51d1fc44a753
Add variable timeout for reads.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
45 then = time.time() |
51d1fc44a753
Add variable timeout for reads.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
46 result = u.read(1.0) # Takes the CRO a while for this |
51d1fc44a753
Add variable timeout for reads.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
47 now = time.time() |
51d1fc44a753
Add variable timeout for reads.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
48 print "CURVE read took %f milliseconds" % ((now - then) * 1000.0) |
3
62ffab79227e
Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
49 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
|
50 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
|
51 ary = numpy.fromstring(data, dtype = dattype) |
62ffab79227e
Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
52 pylab.plot(ary) |
62ffab79227e
Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
53 pylab.show() |
62ffab79227e
Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
54 |
62ffab79227e
Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
55 if __name__ == "__main__": |
62ffab79227e
Add example.py with pylab plotting example.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
56 main() |