-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscope.py
55 lines (42 loc) · 1.13 KB
/
scope.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pyvisa
from matplotlib import pyplot as plt
def main():
rm = pyvisa.ResourceManager('@py')
scope = rm.open_resource('TCPIP::192.168.88.2::INSTR')
scope.timeout = 5000
print(scope.query('*IDN?')[:-1])
print('Collecting data...')
scope.write('SCDP')
res = scope.read_bytes(1)
with open('test.bmp', 'wb') as f:
f.write(res)
f.close()
vdiv = scope.query('C1:VDIV?')
vdiv = float(vdiv[8:-2])
ofst = scope.query('C1:OFST?')
ofst = float(ofst[8:-2])
tdiv = scope.query('TDIV?')
tdiv = float(tdiv[5:-2])
sr = scope.query('SARA?')
sr = 1 / float(sr[5:-5])
scope.write('C1:WF? DAT2')
res = scope.read_bytes(1)
data = list(res)[22:-2]
voltages = []
times = []
print('Processing data...')
count = 0
for b in data:
if b > 127:
b -= 255
v = b * (vdiv / 25) - ofst
voltages.append(v)
t = -(tdiv * 14 / 2) + count*sr
times.append(t)
count += 1
print('Rendering...')
plt.plot(times, voltages)
plt.ylabel('scope')
plt.show()
if __name__ == '__main__':
main()