-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathread_csv.py
50 lines (43 loc) · 1.23 KB
/
read_csv.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
import matplotlib.pyplot as plt
import numpy as np
# Channel 0 = TX
# Channel 1 = RX
MASK = 0x3
TIMEOUT = 0.2
def read_file(file='logic.csv'):
deltas = []
try:
with open(file, 'r') as f:
f.readline()
t0 = 0
t1 = 0
state = 0
while data := f.readline():
raw_time, raw_value = data.split(',')
t1 = float(raw_time)
value = (~int(raw_value, 16)) & MASK
if state == 0:
if value == 1:
state = 1
else:
d = t1-t0
if value == 2:
state = 0
deltas.append(d)
if d > TIMEOUT:
deltas.append(d)
state = 0
t0 = t1
except FileNotFoundError:
print(f'File >{file}< does not exist.')
print(f'Run fast_uart.py and save data to -> {file} <- in this dir.')
exit(1)
return np.array(deltas)
data = read_file()
print(f'Largest value: {np.argmax(data)}')
plt.plot(data)
plt.xlabel('Combination')
plt.ylabel('Required time [s]')
plt.savefig('read_csv.png')
plt.show()
exit(0)