diff --git a/can/interfaces/slcan.py b/can/interfaces/slcan.py index a952fb7c4..89ba00621 100644 --- a/can/interfaces/slcan.py +++ b/can/interfaces/slcan.py @@ -7,13 +7,14 @@ """ +import io from typing import Any, Optional, Tuple -from can import typechecking import time import logging from can import BusABC, Message +from can import typechecking logger = logging.getLogger(__name__) @@ -252,9 +253,12 @@ def shutdown(self) -> None: self.serialPortOrig.close() def fileno(self) -> int: - if hasattr(self.serialPortOrig, "fileno"): + try: return self.serialPortOrig.fileno() - # Return an invalid file descriptor on Windows + except (io.UnsupportedOperation): + # Return an invalid file descriptor on a platform which doesn't implement fileno such as Windows + pass + return -1 def get_version(