forked from DukeRobotics/Acoustics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
saleae_sampling.py
81 lines (66 loc) · 2.28 KB
/
saleae_sampling.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
import saleae
import subprocess
import time
import sys
import os.path
# 2 = 1250 kS/s, 3 = 625 kS/s, 4 = 125 kS/s
sampling_rate = 3
fs = 625000
pingc = pingc = fs*0.004
output_path = "/home/estellehe/Desktop/output/"
def moving_average_max(a, n = pingc) :
weights = np.repeat(1.0, n)/n
alist = np.convolve(a, weights, 'valid')
maxa = 0
maxi = 0
for k in range(len(alist)):
ave = alist[k]
if ave > maxa:
maxa = ave
maxi = k
return maxi
if __name__ == "__main__":
try:
s = saleae.Saleae()
except:
subprocess.Popen(["/home/estellehe/Desktop/Logic/Logic", "-socket"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
time.sleep(15)
s = saleae.Saleae()
print("saleae software down, open saleae software before next script run")
#print("software not opened or no device detected")
#exit()
#todo: add a while loop here to keep trying on get_active_device, timeout after 10s
try:
if s.get_active_device().active:
s.set_active_channels([], [0, 1, 2, 3])
s.set_capture_seconds(3)
s.set_sample_rate(s.get_all_sample_rates()[sampling_rate])
except:
exit()
# try:
# file = open(sys.argv[1], 'r')
# except IOError:
# file = open(sys.argv[1], 'w')
s.capture_start_and_wait_until_finished()
s.export_data2(output_path+"output1/"+sys.argv[1], analog_channels=[0, 1, 2, 3])
time.sleep(10)
s.capture_start_and_wait_until_finished()
s.export_data2(output_path+"output2/"+sys.argv[1], analog_channels=[0, 1, 2, 3])
time.sleep(10)
s.capture_start_and_wait_until_finished()
s.export_data2(output_path+"output3/"+sys.argv[1], analog_channels=[0, 1, 2, 3])
# s.capture_start_and_wait_until_finished()
# s.export_data2(sys.argv[1], analog_channels=[0, 1, 2, 3])
# count +=1
# print(count)
# time.sleep(5)
# s.set_capture_seconds(3)
# exit()
# change to a series of csv
# try:
# file = open(sys.argv[1], 'r')
# except IOError:
# file = open(sys.argv[1], 'w')
#todo: add a while loop to wait till process is finished and then export data
# if s.is_processing_complete():
# s.export_data2(sys.argv[1], analog_channels=[0, 1, 2, 3])