-
Notifications
You must be signed in to change notification settings - Fork 0
/
can-plotter.py
57 lines (48 loc) · 1.38 KB
/
can-plotter.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
import can
import asyncio
import matplotlib.pyplot as plt
from dynplot import dynplot
from matplotlib.animation import FuncAnimation
arbid_x=int(input('Arbitration id? '),16)
mult=float(input('Multiplier? '))
bus = can.Bus(interface='socketcan',
channel='vcan0',
receive_own_messages=True)
time_1=[0]
data_1=[0]
arbid_1=[0]
dplt=dynplot()
for message in bus:
if message.arbitration_id == arbid_x:
#print(message.timestamp, message.data[0], message.arbitration_id)
time_1.append(message.timestamp)
data_1.append(mult*message.data[0])
arbid_1.append(message.arbitration_id)
plt.cla()
plt.plot(time_1,data_1)
plt.style.use('fivethirtyeight')
plt.show(block=False)
plt.pause(0.00001)
while time_1[0]<(time_1[-1]-30):
del time_1[0]
del data_1[0]
del arbid_1[0]
##def animate(i):
## while time_1[0]<(time_1[-1]-30):
## del time_1[0]
## del data_1[0]
## del arbid_1[0]
##
## plt.cla() #clear old lines
## plt.plot(time_1, data_1, label='Data 1')
##
## #plt.plot(x, y2, label='Data 2')
##
## plt.legend(loc='upper left') #static location of legend
## plt.tight_layout() #keeps things on screen
##
##
##ani = FuncAnimation(plt.gcf(), animate, interval=100)
##
##plt.style.use('fivethirtyeight')
##plt.show()