forked from RedPitaya/RedPitaya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacq_bin_test.py
executable file
·109 lines (84 loc) · 2.31 KB
/
acq_bin_test.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python
__author__ = 'infused'
import sys
import redpitaya_scpi as scpi
import array
import matplotlib.pyplot as plt
rp_s = scpi.scpi(sys.argv[1])
wave_form = 'sine'
freq = 10000
ampl = 0.9
# TODO: for some reason '*RST' is returning an error
#rp_s.tx_txt('*RST')
rp_s.tx_txt('RP:DIGLOOP')
rp_s.tx_txt('SOUR1:FUNC ' + str(wave_form).upper())
rp_s.tx_txt('SOUR1:FREQ:FIX ' + str(freq))
rp_s.tx_txt('SOUR1:VOLT ' + str(ampl))
#Enable output
rp_s.tx_txt('OUTPUT1:STATE ON')
rp_s.tx_txt('ACQ:START')
rp_s.tx_txt('ACQ:TRIG NOW')
while 1:
rp_s.tx_txt('ACQ:TRIG:STAT?')
tmp = rp_s.rx_txt()
print tmp
if tmp == 'TD':
break
################################################################################
# float ascii
rp_s.tx_txt('ACQ:DATA:UNITS VOLTS')
rp_s.tx_txt('ACQ:DATA:FORMAT ASCII')
rp_s.tx_txt('ACQ:SOUR1:DATA?')
buff_string = rp_s.rx_txt()
buff_string = buff_string.strip('{}\n\r').replace(" ", "").split(',')
buff = map(float, buff_string)
print "FLOAT ASCII"
print buff_string[:100]
print(buff[:10])
plt.plot(buff)
plt.ylabel('Voltage')
plt.show()
################################################################################
# int16_t ascii
rp_s.tx_txt('ACQ:DATA:UNITS RAW')
rp_s.tx_txt('ACQ:DATA:FORMAT ASCII')
rp_s.tx_txt('ACQ:SOUR1:DATA?')
buff_string = rp_s.rx_txt()
buff_string = buff_string.strip('{}\n\r').replace(" ", "").split(',')
buff = map(int, buff_string)
print "INT16 ASCII"
print buff_string[:100]
print(buff[:10])
plt.plot(buff)
plt.ylabel('Voltage')
plt.show()
################################################################################
# float bin
rp_s.tx_txt('ACQ:DATA:UNITS VOLTS')
rp_s.tx_txt('ACQ:DATA:FORMAT BIN')
rp_s.tx_txt('ACQ:SOUR1:DATA?')
str = rp_s.rx_arb()
print [hex(ord(str[i])) for i in range(10)]
buff = array.array('f', str)
buff.byteswap()
print "FLOAT BIN"
print(len(str))
print(buff[:10])
plt.plot(buff[:])
plt.ylabel('Voltage')
plt.show()
################################################################################
# int16_t bin
rp_s.tx_txt('ACQ:DATA:UNITS RAW')
rp_s.tx_txt('ACQ:DATA:FORMAT BIN')
rp_s.tx_txt('ACQ:SOUR1:DATA?')
str = rp_s.rx_arb()
print [hex(ord(str[i])) for i in range(10)]
buff = array.array('h', str)
buff.byteswap()
print "INT16 BIN"
print(len(str))
print(buff[:10])
plt.plot(buff[:])
plt.ylabel('Voltage')
plt.show()