From a18acacc9c0e175186ee0aea8a90d47f07db04e9 Mon Sep 17 00:00:00 2001 From: meifonglow Date: Mon, 13 May 2024 17:20:23 +1000 Subject: [PATCH 1/3] Add support for loading DCF configuration to remote node --- canopen/node/remote.py | 10 +++++++++- canopen/pdo/base.py | 13 +++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/canopen/node/remote.py b/canopen/node/remote.py index 07462422..0db46623 100644 --- a/canopen/node/remote.py +++ b/canopen/node/remote.py @@ -147,8 +147,16 @@ def __load_configuration_helper(self, index, subindex, name, value): def load_configuration(self): ''' Load the configuration of the node from the object dictionary.''' + # First apply PDO configuration from object dictionary + self.pdo.read(from_od=True) + self.pdo.save() + + # Now apply all other records in object dictionary for obj in self.object_dictionary.values(): - if isinstance(obj, ODRecord) or isinstance(obj, ODArray): + if 0x1400 <= obj.index < 0x1c00: + # Ignore PDO related objects + pass + elif isinstance(obj, ODRecord) or isinstance(obj, ODArray): for subobj in obj.values(): if isinstance(subobj, ODVariable) and subobj.writable and (subobj.value is not None): self.__load_configuration_helper(subobj.index, subobj.subindex, subobj.name, subobj.value) diff --git a/canopen/pdo/base.py b/canopen/pdo/base.py index 52a0aa04..0f5ca06f 100644 --- a/canopen/pdo/base.py +++ b/canopen/pdo/base.py @@ -314,11 +314,20 @@ def add_callback(self, callback: Callable[["Map"], None]) -> None: self.callbacks.append(callback) def read(self, from_od=False) -> None: - """Read PDO configuration for this map using SDO.""" + """Read PDO configuration for this map. + + :param from_od: + Read using SDO if False, read from object dictionary if True. + When reading from object dictionary, if DCF populated a value, the + DCF value will be used, otherwise the EDS default will be used instead. + """ def _raw_from(param): if from_od: - return param.od.default + if param.od.value is not None: + return param.od.value + else: + return param.od.default return param.raw cob_id = _raw_from(self.com_record[1]) From 1c06cbb63759941b4ffccfa9d0181ae54bb9a60e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Colomb?= Date: Thu, 4 Jul 2024 22:11:09 +0200 Subject: [PATCH 2/3] Update canopen/node/remote.py --- 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 0db46623..4230525e 100644 --- a/canopen/node/remote.py +++ b/canopen/node/remote.py @@ -155,8 +155,8 @@ def load_configuration(self): for obj in self.object_dictionary.values(): if 0x1400 <= obj.index < 0x1c00: # Ignore PDO related objects - pass - elif isinstance(obj, ODRecord) or isinstance(obj, ODArray): + continue + if isinstance(obj, ODRecord) or isinstance(obj, ODArray): for subobj in obj.values(): if isinstance(subobj, ODVariable) and subobj.writable and (subobj.value is not None): self.__load_configuration_helper(subobj.index, subobj.subindex, subobj.name, subobj.value) From 8cd3914483213dee39fc7c58d445b347c5b518cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Colomb?= Date: Thu, 4 Jul 2024 22:34:13 +0200 Subject: [PATCH 3/3] Remove unnecessary reading back of PDO settings. --- canopen/node/remote.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/canopen/node/remote.py b/canopen/node/remote.py index f95f6f51..4f3281db 100644 --- a/canopen/node/remote.py +++ b/canopen/node/remote.py @@ -146,10 +146,10 @@ def load_configuration(self) -> None: Iterate through all objects in the Object Dictionary and download the values to the remote node via SDO. - Then, to avoid PDO mapping conflicts, read back (upload) the PDO - configuration via SDO. + To avoid PDO mapping conflicts, PDO-related objects are handled through + the methods :meth:`canopen.pdo.PdoBase.read` and + :meth:`canopen.pdo.PdoBase.save`. - :see-also: :meth:`canopen.pdo.PdoBase.read` """ # First apply PDO configuration from object dictionary self.pdo.read(from_od=True) @@ -166,4 +166,3 @@ def load_configuration(self) -> None: 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