Skip to content

Commit e767285

Browse files
authored
Merge pull request hardbyte#924 from bmeisels/fileno_slcan_fix
Slcan: fix fileno issue with windows
2 parents f7a843e + 1948d6c commit e767285

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

can/interfaces/slcan.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Any, Optional, Tuple
1111
from can import typechecking
1212

13+
import io
1314
import time
1415
import logging
1516

@@ -252,10 +253,12 @@ def shutdown(self) -> None:
252253
self.serialPortOrig.close()
253254

254255
def fileno(self) -> int:
255-
if hasattr(self.serialPortOrig, "fileno"):
256+
try:
256257
return self.serialPortOrig.fileno()
257-
# Return an invalid file descriptor on Windows
258-
return -1
258+
except io.UnsupportedOperation:
259+
raise NotImplementedError(
260+
"fileno is not implemented using current CAN bus on this platform"
261+
)
259262

260263
def get_version(
261264
self, timeout: Optional[float]

0 commit comments

Comments
 (0)