From 18d131c45cfcd648a62b5133db4cd77e9b496fc1 Mon Sep 17 00:00:00 2001 From: Pavel Gostev <73311144+vongostev@users.noreply.github.com> Date: Tue, 14 Nov 2023 18:15:33 +0300 Subject: [PATCH 1/2] Support of custom can.Bus implementations to the Network class The fixed bug relates to the inability to use a custom can.BusABC implementation in the Network connection process due to hard-coded instantiation of the can.Bus object in the `connect` method. --- 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 From 38483133d8e9ceed69d35891f595787419745cd6 Mon Sep 17 00:00:00 2001 From: Pavel Gostev <73311144+vongostev@users.noreply.github.com> Date: Thu, 16 Nov 2023 15:23:46 +0300 Subject: [PATCH 2/2] Add `from_od` flag to the `RemoteNode.load_configuration` In the library we have some methods to load settings from OD, for example `node.rpdo.read(from_od=True)`, but we can not do this for entire configuration. This PR fixes it. --- canopen/node/remote.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/canopen/node/remote.py b/canopen/node/remote.py index 07462422..7718721e 100644 --- a/canopen/node/remote.py +++ b/canopen/node/remote.py @@ -145,7 +145,7 @@ def __load_configuration_helper(self, index, subindex, name, value): logger.warning('[ERROR SETTING object {0:#06x}:{1:#06x}] {2}'.format(index, subindex, str(e))) raise - def load_configuration(self): + def load_configuration(self, from_od: bool = False): ''' Load the configuration of the node from the object dictionary.''' for obj in self.object_dictionary.values(): if isinstance(obj, ODRecord) or isinstance(obj, ODArray): @@ -154,4 +154,4 @@ def load_configuration(self): self.__load_configuration_helper(subobj.index, subobj.subindex, subobj.name, subobj.value) elif isinstance(obj, ODVariable) and obj.writable and (obj.value is not None): self.__load_configuration_helper(obj.index, None, obj.name, obj.value) - self.pdo.read() # reads the new configuration from the driver + self.pdo.read(from_od=from_od) # reads the new configuration from the driver