File: vcan_filtered.py

package info (click to toggle)
python-can 3.0.0%2Bgithub-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,892 kB
  • sloc: python: 8,014; makefile: 29; sh: 12
file content (24 lines) | stat: -rwxr-xr-x 649 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python
# coding: utf-8

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

import time

import can

if __name__ == '__main__':
    bus = can.interface.Bus(bustype='socketcan',
                            channel='vcan0',
                            receive_own_messages=True)

    can_filters = [{"can_id": 1, "can_mask": 0xf, "extended": True}]
    bus.set_filters(can_filters)
    notifier = can.Notifier(bus, [can.Printer()])
    bus.send(can.Message(arbitration_id=1, extended_id=True))
    bus.send(can.Message(arbitration_id=2, extended_id=True))
    bus.send(can.Message(arbitration_id=1, extended_id=False))

    time.sleep(10)