Skip to content

Commit 4cb2f2f

Browse files
authored
Fix fileno error on Windows (robotell bus) (#1313)
* Fix fileno error on Windows (robotell bus) * Fix format * Add test * format
1 parent 796b525 commit 4cb2f2f

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

can/interfaces/robotell.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Interface for Chinese Robotell compatible interfaces (win32/linux).
33
"""
44

5+
import io
56
import time
67
import logging
78

@@ -367,10 +368,14 @@ def shutdown(self):
367368
self.serialPortOrig.close()
368369

369370
def fileno(self):
370-
if hasattr(self.serialPortOrig, "fileno"):
371+
try:
371372
return self.serialPortOrig.fileno()
372-
# Return an invalid file descriptor on Windows
373-
return -1
373+
except io.UnsupportedOperation:
374+
raise NotImplementedError(
375+
"fileno is not implemented using current CAN bus on this platform"
376+
)
377+
except Exception as exception:
378+
raise CanOperationError("Cannot fetch fileno") from exception
374379

375380
def get_serial_number(self, timeout):
376381
"""Get serial number of the slcan interface.

test/test_robotell.py

+4
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,10 @@ def test_set_hw_filter(self):
940940
),
941941
)
942942

943+
def test_when_no_fileno(self):
944+
with self.assertRaises(NotImplementedError):
945+
self.bus.fileno()
946+
943947

944948
if __name__ == "__main__":
945949
unittest.main()

0 commit comments

Comments
 (0)