forked from hardbyte/python-can
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvcan_filtered.py
More file actions
executable file
·32 lines (21 loc) · 903 Bytes
/
vcan_filtered.py
File metadata and controls
executable file
·32 lines (21 loc) · 903 Bytes
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
#!/usr/bin/env python
"""
This shows how message filtering works.
"""
import time
import can
def main():
"""Send some messages to itself and apply filtering."""
with can.Bus(bustype="virtual", receive_own_messages=True) as bus:
can_filters = [{"can_id": 1, "can_mask": 0xF, "extended": True}]
bus.set_filters(can_filters)
# print all incoming messages, wich includes the ones sent,
# since we set receive_own_messages to True
# assign to some variable so it does not garbage collected
notifier = can.Notifier(bus, [can.Printer()]) # pylint: disable=unused-variable
bus.send(can.Message(arbitration_id=1, is_extended_id=True))
bus.send(can.Message(arbitration_id=2, is_extended_id=True))
bus.send(can.Message(arbitration_id=1, is_extended_id=False))
time.sleep(1.0)
if __name__ == "__main__":
main()