-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial.py
More file actions
44 lines (31 loc) · 1.05 KB
/
tutorial.py
File metadata and controls
44 lines (31 loc) · 1.05 KB
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
from CanbusHandler import Handler, Channel
# i used 2-Channel Isolated CAN Expansion HAT for Raspberry Pi, Dual Chips Solution
# in this project https://www.waveshare.com/2-ch-can-hat.htm
# Initialize CAN bus on channel B
busB = Handler(Channel.CanB)
# Initialize CAN bus on channel A
busA = Handler(Channel.CanA)
# Add variables to monitor
devicePid = 0x0016
offset = 0
length = 8
alias = "Battery"
busB.AddCheckList(devicePid, offset, length, alias)
#or just
busB.AddCheckList(0x0000, 3, 1, "Terminal50")
busB.AddCheckList(0x0000, 5, 1, "Terminal15")
# Start the CAN bus communication
busB.Begin()
#read value from checklist, if value not exist returns 0
battery_voltage = busB.GetValue("Battery")
# Send value to can bus
devicePid = 0x1
msg = [0x3,0x4,0x5,0x3]
times = -1 #send every second and never stop
busB.SendMessage(devicePid, msg, times)
#you can cancel message if you want remove example neverstop message
busB.CancelMessage(0x1)
devicePid = 0x2
msg = [0x3,0x4,0x5,0x3]
times = 13 #send every second 13 times
busA.SendMessage(devicePid, msg, times)