Skip to content

Commit 3ae8b00

Browse files
felixdivoGiuseppe Corbelli
authored and
Giuseppe Corbelli
committed
Use new exceptions
1 parent 97d7864 commit 3ae8b00

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

can/interfaces/gs_usb.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import usb
88
import logging
99

10+
from ..exceptions import CanInitializationError, CanOperationError
11+
1012

1113
logger = logging.getLogger(__name__)
1214

@@ -22,7 +24,7 @@ def __init__(self, channel, bus, address, bitrate, can_filters=None, **kwargs):
2224
"""
2325
gs_usb = GsUsb.find(bus=bus, address=address)
2426
if not gs_usb:
25-
raise can.CanError("Can not find device {}".format(channel))
27+
raise CanInitializationError(f"Cannot find device {channel}")
2628
self.gs_usb = gs_usb
2729
self.channel_info = channel
2830

@@ -38,7 +40,7 @@ def send(self, msg: can.Message, timeout: Optional[float] = None):
3840
:param timeout: timeout is not supported.
3941
The function won't return until message is sent or exception is raised.
4042
41-
:raises can.CanError:
43+
:raises CanOperationError:
4244
if the message could not be sent
4345
"""
4446
can_id = msg.arbitration_id
@@ -64,7 +66,7 @@ def send(self, msg: can.Message, timeout: Optional[float] = None):
6466
try:
6567
self.gs_usb.send(frame)
6668
except usb.core.USBError:
67-
raise can.CanError("The message can not be sent")
69+
raise CanOperationError("The message could not be sent")
6870

6971
def _recv_internal(
7072
self, timeout: Optional[float]
@@ -76,6 +78,8 @@ def _recv_internal(
7678
:meth:`~can.BusABC.set_filters` do not match and the call has
7779
not yet timed out.
7880
81+
Never raises an error/exception.
82+
7983
:param float timeout: seconds to wait for a message,
8084
see :meth:`~can.BusABC.send`
8185
0 and None will be converted to minimum value 1ms.
@@ -85,9 +89,6 @@ def _recv_internal(
8589
2. a bool that is True if message filtering has already
8690
been done and else False. In this interface it is always False
8791
since filtering is not available
88-
89-
:raises can.CanError:
90-
if an error occurred while reading
9192
"""
9293
frame = GsUsbFrame()
9394

@@ -111,8 +112,4 @@ def _recv_internal(
111112
return msg, False
112113

113114
def shutdown(self):
114-
"""
115-
Called to carry out any interface specific cleanup required
116-
in shutting down a bus.
117-
"""
118115
self.gs_usb.stop()

0 commit comments

Comments
 (0)