diff --git a/can/interfaces/robotell.py b/can/interfaces/robotell.py index 88cee26d1..709fad78d 100644 --- a/can/interfaces/robotell.py +++ b/can/interfaces/robotell.py @@ -2,6 +2,7 @@ Interface for Chinese Robotell compatible interfaces (win32/linux). """ +import io import time import logging @@ -367,10 +368,14 @@ def shutdown(self): self.serialPortOrig.close() def fileno(self): - if hasattr(self.serialPortOrig, "fileno"): + try: return self.serialPortOrig.fileno() - # Return an invalid file descriptor on Windows - return -1 + except io.UnsupportedOperation: + raise NotImplementedError( + "fileno is not implemented using current CAN bus on this platform" + ) + except Exception as exception: + raise CanOperationError("Cannot fetch fileno") from exception def get_serial_number(self, timeout): """Get serial number of the slcan interface. diff --git a/test/test_robotell.py b/test/test_robotell.py index 86e053f2d..8250b7ada 100644 --- a/test/test_robotell.py +++ b/test/test_robotell.py @@ -940,6 +940,10 @@ def test_set_hw_filter(self): ), ) + def test_when_no_fileno(self): + with self.assertRaises(NotImplementedError): + self.bus.fileno() + if __name__ == "__main__": unittest.main()