From f86527b5fd8ecd8c054d4510918dcc1be21481e0 Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Tue, 1 Sep 2026 08:36:26 +0200 Subject: [PATCH] feat: Return -1 to indicate an error in `get_switching_cycles` method The old behavior was the return of the maximum value. However, this can also be a valid value. Now all positive values are valid and a negative value of -1 describes an error in the query. close #37 Signed-off-by: Sven Sager --- src/revpimodio2/io.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/revpimodio2/io.py b/src/revpimodio2/io.py index 2a05b16..e153233 100644 --- a/src/revpimodio2/io.py +++ b/src/revpimodio2/io.py @@ -1285,7 +1285,8 @@ class RelaisOutput(IOBase): This function is only available locally on a Revolution Pi. This function cannot be used via RevPiNetIO. - :return: Integer of switching cycles as single value or tuple of all + :return: Integer of switching cycles as single value or tuple of all. The + value -1 indicates an error. """ # Using ioctl request K+29 = 19229 if self._parentdevice._modio._run_on_pi: @@ -1298,10 +1299,14 @@ class RelaisOutput(IOBase): self.__ioctl_arg, ) except Exception as e: - # If not implemented, we return the max value and set an error - ioctl_return_value = b"\xff" * struct.calcsize(self.__ioctl_arg_format) self._parentdevice._modio._gotioerror("rocounter", e) + # To report an error, return -1 values + if self._bitaddress == -1: + return -1, -1, -1, -1 + else: + return -1 + elif hasattr(self._parentdevice._modio._myfh, "ioctl"): # IOCTL over network """