From ba4fa0c337e1d8df1800788f4a778be162302663 Mon Sep 17 00:00:00 2001 From: Pavel Gostev <73311144+vongostev@users.noreply.github.com> Date: Tue, 14 Nov 2023 23:29:49 +0300 Subject: [PATCH] Support of custom can.Bus implementations to the Network class (#404) --- canopen/network.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/canopen/network.py b/canopen/network.py index 7768795d..0f9c9327 100644 --- a/canopen/network.py +++ b/canopen/network.py @@ -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. @@ -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