Skip to content

Commit

Permalink
Support of custom can.Bus implementations to the Network class (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
vongostev authored Nov 14, 2023
1 parent 6f9f06e commit ba4fa0c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions canopen/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Listener:
class Network(MutableMapping):
"""Representation of one CAN bus containing one or more nodes."""

def __init__(self, bus=None):
def __init__(self, bus: can.BusABC | None = None):
"""
:param can.BusABC bus:
A python-can bus instance to re-use.
Expand Down Expand Up @@ -110,7 +110,8 @@ def connect(self, *args, **kwargs) -> "Network":
if node.object_dictionary.bitrate:
kwargs["bitrate"] = node.object_dictionary.bitrate
break
self.bus = can.interface.Bus(*args, **kwargs)
if self.bus is None:
self.bus = can.Bus(*args, **kwargs)
logger.info("Connected to '%s'", self.bus.channel_info)
self.notifier = can.Notifier(self.bus, self.listeners, 1)
return self
Expand Down

0 comments on commit ba4fa0c

Please sign in to comment.