Mercurial > ~darius > hgwebdir.cgi > pyinst
comparison 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 |
comparison
equal
deleted
inserted
replaced
4:6b360c30eed6 | 5:51d1fc44a753 |
---|---|
8 def main(): | 8 def main(): |
9 u = usb488.USB488Device() | 9 u = usb488.USB488Device() |
10 print "Found device" | 10 print "Found device" |
11 | 11 |
12 u.write("*IDN?") | 12 u.write("*IDN?") |
13 print "ID is..", | 13 print "IDN reports " + u.read() |
14 print u.read() | |
15 | 14 |
16 u.write("DATA:ENC RIB") # Big endian signed | 15 u.write("DATA:ENC RIB") # Big endian signed |
17 u.write("DATA:WIDTH 2") # 2 bytes wide | 16 u.write("DATA:WIDTH 2") # 2 bytes wide |
18 u.write("SELECT:CH1 ON") # Turn channel 1 on | 17 u.write("SELECT:CH1 ON") # Turn channel 1 on |
19 u.write("DATA:SOURCE CH1") # Set the curve source to channel 1 | 18 u.write("DATA:SOURCE CH1") # Set the curve source to channel 1 |
20 u.write("CURVE?") # Ask for the curve data | 19 u.write("CURVE?") # Ask for the curve data |
21 time.sleep(1) # Wait for the data.. | 20 then = time.time() |
22 # XXX: need some way of polling | 21 result = u.read(1.0) # Takes the CRO a while for this |
23 result = u.read() | 22 now = time.time() |
23 print "CURVE read took %f milliseconds" % ((now - then) * 1000.0) | |
24 data = result[13:] # Chop off the header | 24 data = result[13:] # Chop off the header |
25 dattype = numpy.dtype('>h') # Big endian 16 bit quantity | 25 dattype = numpy.dtype('>h') # Big endian 16 bit quantity |
26 ary = numpy.fromstring(data, dtype = dattype) | 26 ary = numpy.fromstring(data, dtype = dattype) |
27 pylab.plot(ary) | 27 pylab.plot(ary) |
28 pylab.show() | 28 pylab.show() |