forked from hardbyte/python-can
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreceive_all.py
More file actions
34 lines (24 loc) · 865 Bytes
/
receive_all.py
File metadata and controls
34 lines (24 loc) · 865 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
33
34
#!/usr/bin/env python
"""
Shows how the receive messages via polling.
"""
import can
from can.bus import BusState
def receive_all():
"""Receives all messages and prints them to the console until Ctrl+C is pressed."""
with can.interface.Bus(
bustype="pcan", channel="PCAN_USBBUS1", bitrate=250000
) as bus:
# bus = can.interface.Bus(bustype='ixxat', channel=0, bitrate=250000)
# bus = can.interface.Bus(bustype='vector', app_name='CANalyzer', channel=0, bitrate=250000)
# set to read-only, only supported on some interfaces
bus.state = BusState.PASSIVE
try:
while True:
msg = bus.recv(1)
if msg is not None:
print(msg)
except KeyboardInterrupt:
pass # exit normally
if __name__ == "__main__":
receive_all()