Skip to content

Commit 8ec50bc

Browse files
committed
Add filtered messages example
1 parent cc5950f commit 8ec50bc

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

examples/send_one.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
def main():
7-
bus = can.interface.Bus()
7+
bus = can.interface.Bus(bustype='socketcan', channel='vcan0')
88
msg = can.Message(arbitration_id=0xc0ffee,
99
data=[0, 25, 0, 1, 3, 1, 4, 1],
1010
extended_id=False)

examples/vcan_filtered.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import time
2+
import can
3+
4+
bus = can.interface.Bus(bustype='socketcan', channel='vcan0')
5+
6+
can_filters = [{"can_id": 1, "can_mask": 0xf}]
7+
bus.set_filters(can_filters)
8+
notifier = can.Notifier(bus, [can.Printer()])
9+
time.sleep(10)
10+

examples/virtual_can_demo.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@
77
import concurrent.futures
88

99
import can
10-
can.rc['interface'] = 'socketcan_native'
11-
from can.interfaces.interface import Bus
12-
can_interface = 'vcan0'
1310

1411

1512
def producer(id):
1613
""":param id: Spam the bus with messages including the data id."""
1714

18-
bus = Bus(can_interface)
15+
bus = can.interface.Bus(bustype='socketcan', channel='vcan0')
1916
for i in range(16):
20-
msg = can.Message(arbitration_id=0x0cf02200, data=[id, i, 0, 1, 3, 1, 4, 1])
17+
msg = can.Message(arbitration_id=0x0cf02200+id, data=[id, i, 0, 1, 3, 1, 4, 1])
2118
bus.send(msg)
2219
# TODO Issue #3: Need to keep running to ensure the writing threads stay alive. ?
2320
time.sleep(2)

0 commit comments

Comments
 (0)