File: vcan_filtered.py

package info (click to toggle)
python-can 4.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,428 kB
  • sloc: python: 27,154; makefile: 31; sh: 16
file content (29 lines) | stat: -rwxr-xr-x 915 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python3

"""
This shows how message filtering works.
"""

import time

import can


def main():
    """Send some messages to itself and apply filtering."""
    with can.Bus(interface="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, which includes the ones sent,
        # since we set receive_own_messages to True
        # assign to some variable so it does not garbage collected
        with 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()