Skip to content

Commit 44853c5

Browse files
committed
Update examples to use default configured Bus where it makes sense
1 parent 7713748 commit 44853c5

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

examples/cyclic.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ def main():
114114
arbitration_id=0x00, data=[0, 0, 0, 0, 0, 0], is_extended_id=False
115115
)
116116

117-
with can.Bus(interface="virtual") as bus:
117+
# this uses the default configuration (for example from environment variables, or a
118+
# config file) see https://python-can.readthedocs.io/en/stable/configuration.html
119+
with can.Bus() as bus:
118120
bus.send(reset_msg)
119121

120122
simple_periodic_send(bus)

examples/receive_all.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
def receive_all():
1212
"""Receives all messages and prints them to the console until Ctrl+C is pressed."""
1313

14-
with can.Bus(interface="pcan", channel="PCAN_USBBUS1", bitrate=250000) as bus:
15-
# bus = can.Bus(interface='ixxat', channel=0, bitrate=250000)
16-
# bus = can.Bus(interface='vector', app_name='CANalyzer', channel=0, bitrate=250000)
14+
# this uses the default configuration (for example from environment variables, or a
15+
# config file) see https://python-can.readthedocs.io/en/stable/configuration.html
16+
with can.Bus() as bus:
1717

1818
# set to read-only, only supported on some interfaces
19-
bus.state = BusState.PASSIVE
19+
try:
20+
bus.state = BusState.PASSIVE
21+
except NotImplementedError:
22+
pass
2023

2124
try:
2225
while True:

examples/virtual_can_demo.py renamed to examples/send_multiple.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ def producer(thread_id: int, message_count: int = 16) -> None:
1616
:param thread_id: the id of the thread/process
1717
:param message_count: the number of messages that shall be sent
1818
"""
19-
with can.Bus(interface="socketcan", channel="vcan0") as bus: # type: ignore
19+
20+
# this uses the default configuration (for example from environment variables, or a
21+
# config file) see https://python-can.readthedocs.io/en/stable/configuration.html
22+
with can.Bus() as bus: # type: ignore
2023
for i in range(message_count):
2124
msg = can.Message(
2225
arbitration_id=0x0CF02200 + thread_id,

0 commit comments

Comments
 (0)