From 19bd46a17be51c2009084e1500c8c971eb6fe9a5 Mon Sep 17 00:00:00 2001 From: Yves Chevallier Date: Tue, 5 Aug 2025 17:28:52 +0200 Subject: [PATCH] Fix encode_phys for int64 --- canopen/objectdictionary/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/canopen/objectdictionary/__init__.py b/canopen/objectdictionary/__init__.py index f394da23..ea7c3bdf 100644 --- a/canopen/objectdictionary/__init__.py +++ b/canopen/objectdictionary/__init__.py @@ -484,8 +484,12 @@ def decode_phys(self, value: int) -> Union[int, bool, float, str, bytes]: def encode_phys(self, value: Union[int, bool, float, str, bytes]) -> int: if self.data_type in INTEGER_TYPES: - value /= self.factor - value = int(round(value)) + if self.factor == 1: + pass + elif isinstance(value, int) and isinstance(self.factor, int): + value = value // self.factor + else: + value = int(round(value / self.factor)) return value def decode_desc(self, value: int) -> str: