Skip to content

Commit ba4fa0c

Browse files
authored
Support of custom can.Bus implementations to the Network class (#404)
1 parent 6f9f06e commit ba4fa0c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

canopen/network.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Listener:
3333
class Network(MutableMapping):
3434
"""Representation of one CAN bus containing one or more nodes."""
3535

36-
def __init__(self, bus=None):
36+
def __init__(self, bus: can.BusABC | None = None):
3737
"""
3838
:param can.BusABC bus:
3939
A python-can bus instance to re-use.
@@ -110,7 +110,8 @@ def connect(self, *args, **kwargs) -> "Network":
110110
if node.object_dictionary.bitrate:
111111
kwargs["bitrate"] = node.object_dictionary.bitrate
112112
break
113-
self.bus = can.interface.Bus(*args, **kwargs)
113+
if self.bus is None:
114+
self.bus = can.Bus(*args, **kwargs)
114115
logger.info("Connected to '%s'", self.bus.channel_info)
115116
self.notifier = can.Notifier(self.bus, self.listeners, 1)
116117
return self

0 commit comments

Comments
 (0)