Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions can/interfaces/gs_usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import usb
import logging

from ..exceptions import CanInitializationError, CanOperationError


logger = logging.getLogger(__name__)

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

Expand All @@ -38,7 +40,7 @@ def send(self, msg: can.Message, timeout: Optional[float] = None):
:param timeout: timeout is not supported.
The function won't return until message is sent or exception is raised.

:raises can.CanError:
:raises CanOperationError:
if the message could not be sent
"""
can_id = msg.arbitration_id
Expand All @@ -64,7 +66,7 @@ def send(self, msg: can.Message, timeout: Optional[float] = None):
try:
self.gs_usb.send(frame)
except usb.core.USBError:
raise can.CanError("The message can not be sent")
raise CanOperationError("The message could not be sent")

def _recv_internal(
self, timeout: Optional[float]
Expand All @@ -76,6 +78,8 @@ def _recv_internal(
:meth:`~can.BusABC.set_filters` do not match and the call has
not yet timed out.

Never raises an error/exception.

:param float timeout: seconds to wait for a message,
see :meth:`~can.BusABC.send`
0 and None will be converted to minimum value 1ms.
Expand All @@ -85,9 +89,6 @@ def _recv_internal(
2. a bool that is True if message filtering has already
been done and else False. In this interface it is always False
since filtering is not available

:raises can.CanError:
if an error occurred while reading
"""
frame = GsUsbFrame()

Expand All @@ -111,8 +112,4 @@ def _recv_internal(
return msg, False

def shutdown(self):
"""
Called to carry out any interface specific cleanup required
in shutting down a bus.
"""
self.gs_usb.stop()