From d87cad7328e43570ce17163244e5779458951c06 Mon Sep 17 00:00:00 2001 From: Benny Meisels Date: Tue, 28 Jan 2020 15:03:51 +0200 Subject: [PATCH] Fixed Slcan fileno raising an exception on windows --- can/interfaces/slcan.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/can/interfaces/slcan.py b/can/interfaces/slcan.py index 5d7450987..9ac38807b 100644 --- a/can/interfaces/slcan.py +++ b/can/interfaces/slcan.py @@ -7,6 +7,7 @@ """ +import io import time import logging @@ -244,9 +245,12 @@ 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 + 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(self, timeout):