Mercurial > ~darius > hgwebdir.cgi > pyinst
comparison tek2024b_example.py @ 56:91b476ebc0f2
Run through 2to3
author | Daniel O'Connor <doconnor@gsoft.com.au> |
---|---|
date | Tue, 08 Dec 2020 14:00:45 +1030 |
parents | 9bb8a9f3df6b |
children |
comparison
equal
deleted
inserted
replaced
55:ad5942d22f78 | 56:91b476ebc0f2 |
---|---|
31 import time | 31 import time |
32 import usb488 | 32 import usb488 |
33 | 33 |
34 def test(u): | 34 def test(u): |
35 u.write("*IDN?") | 35 u.write("*IDN?") |
36 print "IDN reports " + u.read() | 36 print("IDN reports " + u.read()) |
37 | 37 |
38 # Set data format to 16 bit big endian signed | 38 # Set data format to 16 bit big endian signed |
39 u.write("DATA:ENC RIB") | 39 u.write("DATA:ENC RIB") |
40 u.write("DATA:WIDTH 2") | 40 u.write("DATA:WIDTH 2") |
41 | 41 |
46 u.write("DATA:SOURCE CH1") | 46 u.write("DATA:SOURCE CH1") |
47 | 47 |
48 # Fetch channel scale | 48 # Fetch channel scale |
49 u.write("CH1:SCALE?") | 49 u.write("CH1:SCALE?") |
50 vscale = float(u.read(1).split()[1]) | 50 vscale = float(u.read(1).split()[1]) |
51 print "Channel 1 scale is %.2f volts/div" % (vscale) | 51 print("Channel 1 scale is %.2f volts/div" % (vscale)) |
52 | 52 |
53 # Fetch horizontal scale | 53 # Fetch horizontal scale |
54 u.write("HOR:MAIN:SCALE?") | 54 u.write("HOR:MAIN:SCALE?") |
55 hscale = scpi.getdata(u.read()) | 55 hscale = scpi.getdata(u.read()) |
56 print "Horizontal scale is %f nsec/div" % (hscale * 1e9) | 56 print("Horizontal scale is %f nsec/div" % (hscale * 1e9)) |
57 | 57 |
58 # Make sure the previous commands have been executed | 58 # Make sure the previous commands have been executed |
59 u.write("*WAI") | 59 u.write("*WAI") |
60 | 60 |
61 # Fetch curve data (wait up to 1 second) since the read takes a little while | 61 # Fetch curve data (wait up to 1 second) since the read takes a little while |
62 u.write("CURVE?") | 62 u.write("CURVE?") |
63 then = time.time() | 63 then = time.time() |
64 result = u.read(1.0) | 64 result = u.read(1.0) |
65 now = time.time() | 65 now = time.time() |
66 print "CURVE read took %f milliseconds" % ((now - then) * 1000.0) | 66 print("CURVE read took %f milliseconds" % ((now - then) * 1000.0)) |
67 | 67 |
68 # Parse data | 68 # Parse data |
69 ary = scpi.bindecode(result, dtype = numpy.dtype('>h')) | 69 ary = scpi.bindecode(result, dtype = numpy.dtype('>h')) |
70 | 70 |
71 # Convert to volts | 71 # Convert to volts |
75 pylab.plot(ary) | 75 pylab.plot(ary) |
76 pylab.show() | 76 pylab.show() |
77 | 77 |
78 if __name__ == "__main__": | 78 if __name__ == "__main__": |
79 u = usb488.USB488Device() | 79 u = usb488.USB488Device() |
80 print "Found device" | 80 print("Found device") |
81 | 81 |
82 test(u) | 82 test(u) |